# How to change the amount of Fast Linear Gaussian blur in GLSL?

I implemented the GLSL from http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/, but is unclear to me how to reduce or increase the amount of blur. Has it something to do with the iterations? I don't understand how.

There are a few ways to control the amount of blur:

1. Change your kernel size.

This is the width of the window you sample from your source texture. The guide you're using samples a 9-pixel window (4 pixels to either side of the center), using 5 texture samples.

By adding more texture samples you can make that window wider, for more blur. Or by sampling a smaller neighborhood around your center you can get less blur.

To maintain the Gaussian property when using a different kernel size, you'll need to adjust the weight you apply to each pixel (called the kernel weights), which your guide already shows you how to calculate.

2. Iterate your blur.

If you want to blur a lot more, then just making your kernel wider and wider might start to get prohibitively expensive because you have to do so much texture fetching for every fragment.

Instead you can just blur once with your current kernel size, then blur again with the same (or different) kernel size. That is:

• Original Image --[horizontal blur]--> intermediate
• intermediate --[vertical blur]--> 1x blurred
• 1x blurred --[horizontal blur]--> intermediate
• intermediate --[vertical blur]--> 2x blurred

This gives you the effect of a single Gaussian blur whose radius is the square root of the sum of the squares of the radii of the blurs used as stepping stones.

So repeating your 9-pixel blur (horizontal & vertical) twice would do the same as scaling up your kernel 1.4x (to about 13 pixels) — so it's not as efficient as just widening your kernel as long as you can do so. It's just a way to keep blurring more even if you hit an absolute cap on texture samples (eg. on older/weaker hardware)

3. Down-sample first.

If you need a particularly extreme blur, you can go via a smaller texture as an intermediate.

Your first pass might average blocks of 4 pixels to produce a texture half the width and height of your original. Then repeat with this texture to make one a quarter the width & height of your original.

Now when you run your 9-pixel Gaussian blur using this quarter-sized texture as input, it's like running a 36-pixel blur on your original source texture, at vastly reduced cost.

The downsampling will erase high-frequency information from your texture, but so does a big blur kernel, so in practice the scaling artifacts are not very noticeable in the blurred output.

• so there is no golden key to cheap Blur. You iterate in Shader more to get more blur or iterate the Shader calls more? – Janis Taranda Dec 10 '19 at 14:46
• I mean, using a separable blur like you're doing, plus the linear sampling trick, already cuts an 81 sample blur down to 10 samples. That's pretty cheap for what you're getting! Other tricks you can use include downsampling your intermediates to a smaller resolution, so you cover more of the texture with a fixed-size kernel. – DMGregory Dec 10 '19 at 14:50
• I read the article twice and I dont understand why it 9 tap/pixel solution.And how I can calc the weights using the table.And how are offset calculated. I also have no idea what you mean with downsampling :/ – Janis Taranda Dec 10 '19 at 17:13
• Each of those could be its own question post. I'll edit my answer to detail downsampling, and you can ask the rest separately. – DMGregory Dec 10 '19 at 17:15
• I think one important thing I left out is, that I need to change the Blur intensity at run-time. So adding kernels and weights doesn't sound like a solution. – Janis Taranda Dec 10 '19 at 17:29