gl_FragCoord
Available only in the fragment language,
gl_FragCoord is an input variable that contains
the window relative coordinate (x, y, z, 1/w) values for the fragment.
- If multi-sampling, this value can be for any location within the pixel, or one of the fragment samples.
This value is the result of fixed functionality that interpolates primitives after vertex processing to generate fragments.
-
The
zcomponent is the depth value that would be used for thefragment's depthif no shader contained any writes togl_FragDepth(). -
gl_FragCoordmay be redeclared with the additional layout qualifier identifiersorigin_upper_leftorpixel_center_integer.
By default, gl_FragCoord assumes a
lower-leftorigin for window coordinates and assumes- pixel
centersare located athalf-pixelcenters.
For example, the (x, y) location (0.5, 0.5) is returned for the lower-left-most pixel in a window.
The origin of gl_FragCoord may be changed by redeclaring gl_FragCoord with the origin_upper_left identifier.
The values returned can also be shifted by half a pixel in both x and y by pixel_center_integer so it appears the pixels are centered at whole number pixel offsets.
This moves the (x, y) value returned by gl_FragCoord of (0.5, 0.5) by default to (0.0, 0.0) with pixel_center_integer.
Redeclare
If gl_FragCoord is redeclared in any fragment shader in a program,
it must be redeclared in all fragment shaders in that program that have static use of gl_FragCoord.
Effect
Redeclaring gl_FragCoord with any accepted qualifier affects only gl_FragCoord.x and gl_FragCoord.y.
It has no affect on rasterization, transformation or any other part of the OpenGL pipline or language features.
RHI implement
layout(pixel_center_integer) in vec4 gl_FragCoord;
But that requires desktop GLSL 1.50 or better; even OpenGL ES 3.2 doesn't have this capability.

浙公网安备 33010602011771号