Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the range of gl_FragCoord

What is the range of gl_FragCoord.xy ? I know gl_FragCoords 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.

like image 802
tayrak Avatar asked May 29 '13 23:05

tayrak


2 Answers

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].

like image 87
0xAA55 Avatar answered Nov 04 '22 13:11

0xAA55


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]

like image 36
datenwolf Avatar answered Nov 04 '22 14:11

datenwolf