PDA

View Full Version : Texture coordinates rules



kaikai
12-20-2010, 10:46 AM
Hello,
I'm getting some result with texture coordinates that I don't understand.
I'm rendering a quad with texture coordinates (0,0)(1,0)(1,1)(0,1) and a 2x2 texture.
If I discard all fragments with texcoord.x>=0.5, I expect to see only the left part of my texture. Instead I'm seeing a small part of the right side.
http://tinypic.com/r/fpbllw/7
My shader looks like this:


uniform sampler2D tex;
void main()
{
if ( gl_TexCoord[0].x >= 0.5)
discard;
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
}

I only get this result on ATI, not NVIDIA.
The "error" is very high because sampling texture like this:
gl_FragColor = texture2D(tex, vec2(0.4999, 0.));
already fetchs texel at image pos (1,0).

What is the expected result? Do you see how to fix this?
Thank you.
Edit: Texture is in nearest mode.

Alfonse Reinheart
12-20-2010, 10:55 AM
http://tinypic.com/r/fpbllw/7

There doesn't appear to be a picture there.

kaikai
12-20-2010, 03:38 PM
There doesn't appear to be a picture there.
You can try here : http://bayimg.com/hABapAaDj

ZbuffeR
12-21-2010, 04:26 AM
Sorry but I am not even sure of what has to be seen in this picture ? red blue, yellow, green, black ?

kaikai
12-21-2010, 08:43 AM
Sorry, the picture is indeed not clear.
What you are seeing is a quad on which a 2x2 texture is applied (with filtering set to nearest).
Texel (0,0) is red, Texel (1,0) is green
Texel (0,1) is blue, Texel (1,1) is yellow
I'm discarding all fragment whose texture coords are >= 0.5. Thus I'm expecting to see only red and blue. Instead, I see a small border with green and yellow.

My question can be reduced to:
Why on a 2x2 texture in nearest mode, texture2D(tex, vec2(0.4999, 0.)) fetchs texel(1,0)?
On ATI(HD5870) at least. Thank you.