Fragment

From OpenGL.org
Jump to: navigation, search

A Fragment is a collection of values produced by the Rasterizer. Each fragment represents a sample-sized segment of a rasterized Primitive. The size covered by a fragment is related to the pixel area, but rasterization can produce multiple fragments from the same triangle per-pixel, depending on various multisampling parameters and OpenGL state. There will be at least one fragment produced for every pixel area covered by the primitive being rasterized.

Fragments are processed in a manor similar to vertices in a Vertex Shader. For them, an input vertex, build from Vertex Attributes defined during Vertex Specification, enters the Vertex Shader. After arbitrary processing, the vertex shader writes a number of values. These values represent the output vertex, and this output vertex is passed along to the next stages of the pipeline.

Fragments work the same way. An input fragment, built by the rasterizer, enters the Fragment Shader. After arbitrary processing, the fragment shader writes a number of values. These values represent the output fragment, and this output fragment is passed along to the next stage of the pipeline.

Fragment shader inputs

Initially, the data for a fragment consists of the following:

Fragment shader outputs

After processing, the output fragment from a fragment shader consists of the following:

  • a depth value, either written by the fragment shader or passed through from the screen-space fragment's Z value.
  • a stencil value.
  • An array of zero or more color values, as written by the fragment shader.

The color value array elements are routed to different buffers based on the framebuffer's draw buffer state.

Fragment discard

Fragments generated by the rasterizer may be discarded. This can happen due to the failure of various per-fragment tests or by command from the Fragment Shader.

When a fragment is discarded, any updates caused by this fragment will fail. This includes the fragment shader's color outputs, depth outputs, Image Load Store operations, Shader Storage Buffer Objects and anything else. The only operation caused by a discarded fragment are potentially Stencil Test updates, and those will only happen if the fragment was discarded due to the failure of either the depth or stencil tests.

See also