Rasterization (source code)

= Rasterization

<Rasterization> converts geometric primitives into candidate contributions at discrete <pixel> sample positions. For a projected <triangle>, an implementation tests which samples lie inside its three oriented edges and interpolates attributes from the vertices. With <barycentric coordinates> $\lambda_i$, a screen-space linear attribute is $\sum_i\lambda_i a_i$. Attributes defined before <perspective projection> generally need perspective-correct interpolation:
$$
a=\frac{\sum_i\lambda_i a_i/w_i}{\sum_i\lambda_i/w_i}.
$$
Here $w_i$ are the clip-coordinate denominators. Ordinary interpolation would distort a texture seen at an angle.

A generated fragment is not necessarily a final visible <pixel>: a <fragment shader> determines its values, a <depth buffer> can reject hidden contributions, and blending combines surviving contributions. Multiple samples per <pixel> improve coverage estimates near boundaries but do not recreate arbitrarily fine detail. OpenGL specifies these stages separately, so geometric coverage and final image storage must not be conflated.<The OpenGL Graphics System Version 4.6 Core Profile by Khronos Group>[Chapter14, rasterization and early tests; Chapter15, fragment shading]{ref}