Texture resolution issue?

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.

For me pictures look correct, second one is ‘blockier’ becouse second texture has small resolution.
What do You expect to get?

Thank you for the reply :slight_smile:
Well, it is not very obvious on this picture, but if I take a 32x32 Texture, it is much worse, a sort of displacement appears, as if I were using a blur shader with a TexelSize of 1/32 with a 1024x1024 texture.
However, I am correctly calling the glTexImage2D with the correct Resolution I want.

OK, I just found what was the problem : indeed, the supposed to be 1024x1024 Texture and the 32x32 Texture had in fact the same resolution, because glCopyTexImage2D do not take into account the resolution of the target texture, it simply takes the screen resolution.
Anyone has an idea how do I copy the screen into a texture with a different resolution ?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.