How dynamic are the variable radius ? Is it on a per pixel level or per game session (depending only on the visual settings ? ).

Here are some tips:

1. If you really have a dynamic setup, try to save different gaussian distributions in a texture and sample the texture.

2. If the setup change not very often, try to generate the shader coder just before uploading it. This way you avoid recalculation of the gaussian distribution and you have a fix range, which avoids dynamic for-loops (better performance on older hardware).

Edit:

3. You can use pre-processor directive to choose between a fix set of precoded configurations.

I did a DOF blur effect with a variable width Gaussian blur per pixel for this scene, by first implementing a regular two-pass Gaussian blur shader, and then simply scaling my texture coordinate offsets per pixel. I think that shader is using 5 samples per pixel in each direction.

Using traditional techniques, you would either want to recompile hundreds of different blur shaders for those different radii, as they'll all need different numbers of samples and different weights, or you'd have to use a loop in the shader to dynamically choose the number of weights.

We're trying to implement 2-pass Gaussian blur on HSL2.0. Here is a code of shader for horizontal blur. Pixelwidth is a radius. This shader doesn't work, the result looks as without the shader, please can you help?