What is the range of gl_FragCoord.xy
? I know gl_FragCoord
s are screen coordinates but what is the actual range? ( 0, width - 1 )
or ( 1, width )
? And what kind of error (if any) would glsl compiler generate say I did something like gl_FragCoord.x - 5
when i do some fragcoord based calculation?
ps: I don't need normalization.
I did a test to the actual range of gl_FragCoord.xy
, by using the following shader code and glReadPixels(0, 0, 1024, 1024, GL_RED, GL_FLOAT, xxx)
to get the output of the shader from my framebuffer object, and the FBO had attached a texture which's internal format is GL_R32F
.
out highp vec4 Output;
void main()
{
Output = vec4(gl_FragCoord.xy, 0.0, 1.0);
}
The actual result is: gl_FragCoord.xy
is in the range [0.5, 1023.5], not [0.0, 1023.0].
gl_FragCoord coordinates are indexed starting from 0.
The expression gl_FragCoord.x - 5
would result in a value in the range [-5, (width - 5) - 1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With