Thanks!
The shader does appear to only take input parameters for blur amount between 0 and 1 divided by the target texture width and height. I wanted a greater amount of blurring than the shader could supply by default, so I had to expand it a bit. Here’s a brief description of how to do it in case anyone’s interested:
The shader works by setting the value of each pixel to sum of a bunch of surrounding pixels, such that the amount that each neighboring pixel contributes to the final fragment color is the product of the value of its original color and number sampled from a normal (gaussian) distribution.
In order to get a greater amount of blurring, you can increase the number of neighboring pixels used in the computation of the final fragment color, and expand the standard deviation of the normal distribution that you are sampling. I didn’t feel like doing the math for that, so I used MATLAB to sample a normal probability density function with a wider spread than the values in the original shader.
Matlab Command Window
>> x = [-12:1:12];
>> norm = normpdf(x,0,2.0);
>> norm
norm =
Columns 1 through 10
0.0000 0.0002 0.0005 0.0015 0.0038 0.0087 0.0180 0.0332 0.0547 0.0807
Columns 11 through 20
0.1065 0.1258 0.1330 0.1258 0.1065 0.0807 0.0547 0.0332 0.0180 0.0087
Columns 21 through 25
0.0038 0.0015 0.0005 0.0002 0.0000
You can then adjust the shader like so:
uniform sampler2D texture;
uniform vec2 blur_radius;
void main() {
vec2 textureCoordinates = gl_TexCoord[0].xy;
vec4 color = vec4(0.0);
color += texture2D(texture, textureCoordinates - 10.0 * blur_radius) * 0.0012;
color += texture2D(texture, textureCoordinates - 9.0 * blur_radius) * 0.0015;
color += texture2D(texture, textureCoordinates - 8.0 * blur_radius) * 0.0038;
color += texture2D(texture, textureCoordinates - 7.0 * blur_radius) * 0.0087;
color += texture2D(texture, textureCoordinates - 6.0 * blur_radius) * 0.0180;
color += texture2D(texture, textureCoordinates - 5.0 * blur_radius) * 0.0332;
color += texture2D(texture, textureCoordinates - 4.0 * blur_radius) * 0.0547;
color += texture2D(texture, textureCoordinates - 3.0 * blur_radius) * 0.0807;
color += texture2D(texture, textureCoordinates - 2.0 * blur_radius) * 0.1065;
color += texture2D(texture, textureCoordinates - blur_radius) * 0.1258;
color += texture2D(texture, textureCoordinates) * 0.1330;
color += texture2D(texture, textureCoordinates + blur_radius) * 0.1258;
color += texture2D(texture, textureCoordinates + 2.0 * blur_radius) * 0.1065;
color += texture2D(texture, textureCoordinates + 3.0 * blur_radius) * 0.0807;
color += texture2D(texture, textureCoordinates + 4.0 * blur_radius) * 0.0547;
color += texture2D(texture, textureCoordinates + 5.0 * blur_radius) * 0.0332;
color += texture2D(texture, textureCoordinates + 6.0 * blur_radius) * 0.0180;
color += texture2D(texture, textureCoordinates - 7.0 * blur_radius) * 0.0087;
color += texture2D(texture, textureCoordinates - 8.0 * blur_radius) * 0.0038;
color += texture2D(texture, textureCoordinates - 9.0 * blur_radius) * 0.0015;
color += texture2D(texture, textureCoordinates - 10.0 * blur_radius) * 0.0012;
gl_FragColor = color;
}
Remember that all the samples from the gaussian distribution need to add up to one or it’ll darken the final image! Also, obviously if you do it this way a greater amount of blurring is more computationally intensive.
EDIT:
You might be able to get a greater blur with fewer samples by using a flatter distribution.
EDIT2:
Never mind, flattening a distribution also widens it
. If anyone knows how to speed this up let me know! The only way I know of evenly flattening a normal distribution would be convolving it with another normal distribution, which obviously makes it wider, but maybe there's something that I'm not thinking of...