What it does

A Fragment Shader calculates color and other outputs for fragments produced when geometry is rasterized. It samples textures and evaluates lighting or transparency. A fragment is a candidate surface contribution to the rendered image.

Figure: Conceptual relationship: Rasterized fragments → Compute fragment values → Output color/depth
Figure: Conceptual relationship: Rasterized fragments → Compute fragment values → Output color/depth

How to use it

The fragment stage uses interpolated UVs, normals and other inputs to compute color and opacity. Overlapping shapes can cause more evaluations than the final screen-pixel count.

A concrete example

Several noise samples on large translucent smoke cards add sampling and blending work even when geometry is simple. Mostly transparent padding can also be processed.

How to check it

  1. Compare constant color, one texture and the complete shader.
    Inspect per-pixel values, thresholds and coverage
    Inspect per-pixel values, thresholds and coverage
  2. Inspect GPU changes with resolution and coverage to separate pixel work from vertex cost.
    Inspect per-pixel values, thresholds and coverage
    Inspect per-pixel values, thresholds and coverage

Limitations

Fragment count can exceed final pixels due to overdraw.

References