Hi,
I would like to apply a blur on my scene, so I use glTexImage2D to get the corresponding texture, to which I apply a blur shader.
However, my problem is the shader does not seem to take into account the texture resolution I am passing him.
Here is my shader :
Vertex shader :
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
Pixel shader :
uniform sampler2D Texture;
uniform float BlurSize;
uniform float InternalResolution;
void main()
{
vec4 ColorsSum = vec4(0.0);
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t - 4.0*BlurSize/InternalResolution)) * 1.0/25.0;
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t - 3.0*BlurSize/InternalResolution)) * 2.0/25.0;
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t - 2.0*BlurSize/InternalResolution)) * 3.0/25.0;
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t - 1.0*BlurSize/InternalResolution)) * 4.0/25.0;
ColorsSum += texture2D(Texture, gl_TexCoord[0].st) * 5.0/25.0;
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t + 1.0*BlurSize/InternalResolution)) * 4.0/25.0;
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t + 2.0*BlurSize/InternalResolution)) * 3.0/25.0;
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t + 3.0*BlurSize/InternalResolution)) * 2.0/25.0;
ColorsSum += texture2D(Texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t + 4.0*BlurSize/InternalResolution)) * 1.0/25.0;
gl_FragColor = ColorsSum;
}
This is how the scene looks like :
http://img818.imageshack.us/i/originalx.jpg/
If I pass a 1024*1024 Texture to this shader, with the corresponding uniform “InternalResolution” to 1024, and “BlurSize” to 1.0, I get this :
http://img813.imageshack.us/i/result1.jpg/
Now if I use a 128x128 Texture, with the “InternalResolution” set to 128 :
http://img820.imageshack.us/i/result2y.jpg/
I expected to get the same result, since BlurSize/InternalResolution with BlurSize to 1.0 should give the texel size, independent of the sampler resolution.
If anyone as an idea on it, thank you in advance.