Glsl pixel rounding error?

Hi,

For testing purposes, I’ve written a glsl shader that does the following:

vec2 texCoord = gl_TexCoord[0].st;
gl_FragColor = vec4( texture2D(myTexture, vec2(texCoord.x-(1.0/width),texCoord.y)) );

where width is a uniform float giving the number of pixels in that dimension.
In other words, the curr pixel copies from the one to its left. This is being done on an FBO so if I initialize a single pixel wide line along the vertical axis, that line should travel across the screen. Instead, its propagation is uneven.
Please see image at: http://yfrog.com/71screenshot20101113at544p

When I change these parameters for my bound texture, the unevenness of the propagation changes.
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
But I can’t seem to get it right.

Anyone know what the problem might be?
Thanks

Let me put it another way.

I’m ping-ponging two FBOs that have four target textures each.
I’ve written a simple test program where on each iteration, each pixel copies its neighbor to the left. Here’s the trick though:
If the FBO has textures A,B,C and D, pixels in the first vertical column of texture B should copy from the last column of texture A.

I think I’ve worked out the neighbor rules within the textures properly and it seems like the problem has something to do the texture wrapping and interpolation parameters.

Any thoughts on how to do this?
Thanks

Are you really positive you have a 1-to-1 mapping between texels and pixels ? input texture texcoords and output FBO position ?

I guess I’m not sure. In fact, this morning it is looking more like that is the problem.

Here’s how I’m thinking about this, am I way off, I think I might be:


uniform sampler2D mytex0;
uniform sampler2D mytex1;

uniform float mytexWidth;
uniform float mytexHeight;

void main(void) {
	vec2 texCoord  = gl_TexCoord[0].xy;

        float wUnit = 1.0/mytexWidth;
        float hUnit = 1.0/mytexHeight;

        vec3 leftPix0;
        vec3 leftPix1;

        if(texCoord.x == 0.0) {  
             leftPix0 = texture2D(mytex1, texCoord + vec2(1.0,texCoord.y) ).rgb;
             leftPix1 = texture2D(mytex0, texCoord + vec2(1.0,texCoord.y) ).rgb;
        }      
        else if(texCoord.x == 1.0) {  
             leftPix0 = texture2D(mytex1, texCoord + vec2(0.0,texCoord.y) ).rgb;
             leftPix1 = texture2D(mytex0, texCoord + vec2(0.0,texCoord.y) ).rgb;
        }   
        else {
             leftPix0 = texture2D(mytex0, texCoord + vec2(-wUnit,texCoord.y) ).rgb;
             leftPix1 = texture2D(mytex1, texCoord + vec2(-wUnit,texCoord.y) ).rgb;
        }

        gl_FragData[0] = vec4(leftPix0,1.0);
        gl_FragData[1] = vec4(leftPix1,1.0);
}

Thanks!

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