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 z component is the depth value that would be used for the fragment's depth if no shader contained any writes to gl_FragDepth().

  • gl_FragCoord may be redeclared with the additional layout qualifier identifiers origin_upper_left or pixel_center_integer.

By default, gl_FragCoord assumes a

  • lower-left origin for window coordinates and assumes
  • pixel centers are located at half-pixel centers.

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.

posted @ 2022-03-22 14:51  fndefbwefsowpvqfx  阅读(71)  评论(0编辑  收藏  举报