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.
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.
you know that gl_FragCoord.xy is the pixel coordinate right? Also, what fractional value it gives depends on GL state (see: gl_FragCoord - OpenGL 4 Reference Pages ). 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:
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.