gl_FragCoord.y always 0

Hello,

I wrote a shader that needs to obtain texture coordinates from screen coordinates, but gl_FragCoord’s y coordinate is always 0.
x, z, and w are fine. As a result, I get lines going up and down the screen.

What could be the cause of this?

Thank for any help you can offer.

Restarted my computer and now it works. What is going on here?

EDIT: Never mind, it came back on the second run of the program.

How do you check the value of y, what gpu and drivers are you using, can you reproduce it on another platform?
(it looks like a driver bug)

I checked the value by discarding fragments with a y of 0. The problem went away when I did that. I found that it was not actually always 0, but 0 for fragments where it shouldn’t be. It is almost as if it were drawing multiple passes, one normal, one stretched (with all y frag coords 0). However, it is just one quad, and even if I were rendering multiple passes, the frag coords shouldn’t change. So discarding the fragments with a y of 0 got rid of the 1 pixel tall stretched image covering up the regular image.

This does not work:

    
vec4 diffuseFinal = vec4(texture2D(effectCopy, gl_FragCoord.xy) / vec2(800, 600)).rgb, 1.0) * diffuseColor;

But this does:


if(gl_FragCoord.y == 0)
        discard;


vec4 diffuseFinal = vec4(texture2D(effectCopy, gl_FragCoord.xy) / vec2(800, 600)).rgb, 1.0) * diffuseColor;

you know that gl_FragCoord.xy is the pixel coordinate right? Also, what fractional value it gives depends on GL state (see: http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_FragCoord.xml ). I think you do know that frag is a window coordinate, as you have a /vec2(800, 600) in the code, but the location is borked, I think the code should read:



vec4 diffuseFinal = vec4( texture2D(effectCopy, gl_FragCoord.xy/vec2(800, 600)).rgb, 1.0) * diffuse

as a side note you’d really be better off doing the following for readability:


vec2 tex_coord;
vec3 color;


tex_coord=gl_FragCoord.xy/vec2(800.0, 600.0);
color = texture2D( effectCopy, tex_coord).rgb;

diffuseFinal = vec4(color.rgb, 1.0); 

Opps, copied it incorrectly. The way you show it is how I also did it in the shader. There was an offset applied to the texture coordinates originally (but I did test it without the offset as well, so that is not the problem), which I removed for clarity.

The fractional value is OK, when it gives it to me at all.