Re: Gaussian Blur on texture
As you can see in that algorithm.. do the same.. but you cant write (setpixel) into the same texture. So.. do the ping-pong... create another texture (same size as original) and do horizontal blur. Then use that new texture as source for vertical blur.
Code :
fbo1 is original fbo
fbo2 is temporary fbo
fbo2 = horizontal_blur(fbo1) // step 1.. read from fbo1, write to fbo2
fbo1 = vertical_blur(fbo2) // step 2.. read from fbo2, write to fbo1
now, fbo1 contains blurred image.
Even more, you can repeat step1 and step2 several times to blur more.
Re: Gaussian Blur on texture
Re: Gaussian Blur on texture
Thanks guy,
I now have the doubt that using this extension "EXT_convolution" I can do it via hardware. Do you know if it is true?
Thanks.
Alberto
Re: Gaussian Blur on texture
In my experience some/most of the imaging extensions (including convolution) are not HW accelerated.
Re: Gaussian Blur on texture
No I am certain, the best way to do what we need are Shaders. Does anybody know a good 'basic' tutorial on the Shaders based convulution filter?
Thanks.
Alberto
Re: Gaussian Blur on texture
Code :
/////////////////////////////////////////////////
// 7x1 gaussian blur fragment shader
/////////////////////////////////////////////////
varying vec2 v_Coordinates;
uniform vec2 u_Scale;
uniform sampler2D u_Texture0;
const vec2 gaussFilter[7] =
{
-3.0, 0.015625,
-2.0, 0.09375,
-1.0, 0.234375,
0.0, 0.3125,
1.0, 0.234375,
2.0, 0.09375,
3.0, 0.015625
};
void main()
{
vec4 color = 0.0;
for( int i = 0; i < 7; i++ )
{
color += texture2D( u_Texture0, vec2( v_Coordinates.x+gaussFilter[i].x*u_Scale.x, v_Coordinates.y+gaussFilter[i].x*u_Scale.y ) )*gaussFilter[i].y;
}
gl_FragColor = color;
}
u_Scale is vec2(0, 1.0/height ) for vertical blur and vec2(1.0/width, 0 ) for horizontal blur.
Re: Gaussian Blur on texture
Thanks a lot vexator,
You all Shaders expert use shader program only code samples but for us old OpenGL programmers the rest is still not so easy to add.
Can you please add also the gl calls to make this shader to run?
Thanks so much,
Alberto
Re: Gaussian Blur on texture
Re: Gaussian Blur on texture
Hi Vexator,
Please help me to make this shader to work.
What are variables we need to initialize?
How can we perform the blur in both directions?
Thanks,
Alberto