23.3. Clipping Shader Outputs

Next, vertex output attributes are clipped. The output values associated with a vertex that lies within the clip volume are unaffected by clipping. If a primitive is clipped, however, the output values assigned to vertices produced by clipping are clipped.

Let the output values assigned to the two vertices ${\textbf P}_1$ and ${\textbf P}_2$ of an unclipped edge be ${\textbf c}_1$ and ${\textbf c}_2$ . The value of $t$ (see Primitive Clipping) for a clipped point ${\textbf P}$ is used to obtain the output value associated with ${\textbf P}$ as

${\textbf c} = t {\textbf c}_1 + (1-t){\textbf c}_2. $

(Multiplying an output value by a scalar means multiplying each of x, y, z, and w by the scalar.)

Since this computation is performed in clip space before division by $w_c$ , clipped output values are perspective-correct.

Polygon clipping creates a clipped vertex along an edge of the clip volume’s boundary. This situation is handled by noting that polygon clipping proceeds by clipping against one half-space at a time. Output value clipping is done in the same way, so that clipped points always occur at the intersection of polygon edges (possibly already clipped) with the clip volume’s boundary.

For vertex output attributes whose matching fragment input attributes are decorated with NoPerspective, the value of $t$ used to obtain the output value associated with ${\textbf P}$ will be adjusted to produce results that vary linearly in framebuffer space.

Output attributes of integer or unsigned integer type must always be flatshaded. Flatshaded attributes are constant over the primitive being rasterized (see Basic Line Segment Rasterization and Basic Polygon Rasterization), and no interpolation is performed. The output value ${\textbf c}$ is taken from either ${\textbf c}_1$ or ${\textbf c}_2$ , since flatshading has already occurred and the two values are identical.