

gl_PointCoord The location within a point primitive that defines the position of the fragment relative to the side of the point. gl_FrontFacing This is false if the fragment was generated by the back-face of the primitive it is true in all other cases (including Primitives that have no back face). Unless you need your shaders to have this compatibility, you are advised not to use these features. Both of these exist to be compatible with D3D's window space. Using pixel_center_integer adjust gl_FragCoord such that whole integer values represent pixel centers. So the center of the lower-left pixel is (0.5, 0.5). Layout(pixel_center_integer) in vec4 gl_FragCoord OpenGL window space is defined such that pixel centers are on half-integer boundaries. Specifically, between this stage and the last Vertex Processing shader stage in the program or pipeline object. The fragment shader's input variables must be declared in accord with the interface matching rules between shader stages. The user-defined inputs received by this fragment shader will be interpolated according to the interpolation qualifiers declared on the input variables declared by this fragment shader.

The inputs to the fragment shader are either generated by the system or passed from prior fixed-function operations and potentially interpolated across the surface of the primitive. Similarly, if you discard a fragment, the Stencil Test will still result in updating the stencil buffer if the appropriate operations are set. The value written to the depth buffer will always be the value tested against the depth buffer. If you attempt to write to gl_FragDepth when you force early-fragment tests, then the value written will be ignored. You cannot, for example, perform the depth test with one value and then write a different value to the depth buffer than the one you tested. Warning: This does not mean that you can subvert the meaning of the Depth Test. To do this, the following syntax is used in the shader: However, with OpenGL 4.2 or ARB_shader_image_load_store, the shader can enforce Early Fragment Testing, which ensures that the conditional per-sample tests that discard fragments happen before the fragment shader executes. Normally, most of the Per-Sample Processing steps happen after the fragment shader. Such systems are required to prevent image store, Atomic Counter, and Shader Storage Buffer Object writes issued after the discard from working (such operations performed before the discard work as expected).

Though execution of the fragment shader is technically stopped by discard, on actual systems, it may continue. Thus, the fragment does not proceed on to the next pipeline stages, and any fragment shader outputs are lost. When executed, this command causes the fragment's output values to be discarded. You still need to watch out for non-uniform flow control.įragment shaders also have access to the discard command. As such, they can use the majority of the texturing functions. Unlike every other shader stage, fragment shaders have implicit derivatives generated. Such depth-only rendering is used for shadow mapping operations as well as depth pre-pass optimizations. This is useful for doing rendering where the only useful output is the fragment's depth, and you want to use the depth computed by the system, rather than some other depth. However, the depth and stencil values for the output fragment have the same values as the inputs. If no fragment shader is used, then the color values of the output Fragment have undefined values. The output of a fragment shader is a depth value, a possible stencil value (unmodified by the fragment shader), and zero or more color values to be potentially written to the buffers in the current framebuffers.įragment shaders take a single fragment as input and produce a single fragment as output.įragment shaders are technically an optional shader stage. Each fragment has a Window Space position, a few other values, and it contains all of the interpolated per-vertex output values from the last Vertex Processing stage. For each sample of the pixels covered by a primitive, a "fragment" is generated. The fragment shader is the OpenGL pipeline stage after a primitive is rasterized. A Fragment Shader is the Shader stage that will process a Fragment generated by the Rasterization into a set of colors and a single depth value.
