PDA

View Full Version : Gaussian blur with varaible radius



dirhem
09-08-2011, 04:24 PM
I am trying to write a shader which will apply gaussian blur to a texture. I can do it with a fixed radius size. What i am trying to do is get the blur radius from user and apply the gaussian filter with that radius.

For now i am using something like this with fixed radius 7.(of course there is vertical shader too)


void main(void)
{
vec4 sum = vec4(0.0);
sum += texture2D(RTScene, vec2(vTexCoord.x - 4.0*blurSize, vTexCoord.y)) * 0.05;
sum += texture2D(RTScene, vec2(vTexCoord.x - 3.0*blurSize, vTexCoord.y)) * 0.09;
sum += texture2D(RTScene, vec2(vTexCoord.x - 2.0*blurSize, vTexCoord.y)) * 0.12;
sum += texture2D(RTScene, vec2(vTexCoord.x - blurSize, vTexCoord.y)) * 0.15;
sum += texture2D(RTScene, vec2(vTexCoord.x, vTexCoord.y)) * 0.16;
sum += texture2D(RTScene, vec2(vTexCoord.x + blurSize, vTexCoord.y)) * 0.15;
sum += texture2D(RTScene, vec2(vTexCoord.x + 2.0*blurSize, vTexCoord.y)) * 0.12;
sum += texture2D(RTScene, vec2(vTexCoord.x + 3.0*blurSize, vTexCoord.y)) * 0.09;
sum += texture2D(RTScene, vec2(vTexCoord.x + 4.0*blurSize, vTexCoord.y)) * 0.05;

gl_FragColor = sum;
}

ZbuffeR
09-08-2011, 11:22 PM
Well just change the blurSize for a variable radius.
Or maybe I do not understand your (implicit) question ?

dirhem
09-09-2011, 04:49 AM
Well, i got this code from somewhere else so i am not sure but "blurSize" just looks like the step size not radius. For some reason i think radius is directly related with kernel size which is 7 in this example.

ZbuffeR
09-09-2011, 05:16 AM
And if you increase the step size, you should get a wider blur. Did you try ?

The number of samples taken has a effect on quality, not on blur size.

dirhem
09-09-2011, 05:39 AM
I have tried and yes it gives a result with higher radius with less quality. Thanks for your answer, it is clear now.