Shading
The rendering pipeline from vertices to pixels, with the maths written out
Computer Science | Undergraduate (Level 5) | December 2026
WHAT IS INSIDE
1. Core Concepts and Theoretical Frameworks
2. Transforms and the viewing pipeline
3. Rasterisation and visibility
4. Lighting and shading models
5. Texture, sampling and anti-aliasing
6. Step-by-Step Worked Examples
7. Comparative Summary Table
8. Common Exam Pitfalls and Answer Technique
9. Practice Exam Questions with Model Answers
10. Glossary of Exam-Ready Definitions
1. Core Concepts and Theoretical Frameworks
Graphics questions are usually answered by tracing a quantity through the pipeline. The table gives the stages, and
every exam calculation can be located at one of them.
Stage Input Operation Output
Modelling transform Object coordinates Model matrix places the object in the World coordinates
world
Viewing transform World coordinates Camera matrix expresses the scene Eye coordinates
relative to the eye
Projection Eye coordinates Perspective or orthographic projection Clip coordinates
Perspective divide Clip coordinates Divide x, y, z by w Normalised device coordinates
Viewport transform NDC Map to screen coordinates Window coordinates
Rasterisation Screen-space Determine which pixels each primitive Fragments
triangles covers
Visibility Fragments Depth test with a z-buffer Visible fragments
Shading Visible fragments Evaluate the illumination model Pixel colours
Two conventions cause most errors. First, matrices are applied to column vectors in the order projection times
view times model, which reads right to left in the code. Second, normal vectors transform with the inverse
transpose of the model matrix, not with the model matrix itself, because non-uniform scaling would otherwise
distort them.
2. Transforms and the viewing pipeline
Two-dimensional and three-dimensional transforms are written as matrices so that they compose by
multiplication. Translation is not linear in two dimensions and is therefore expressed in homogeneous coordinates
by a three-by-three matrix, and in three dimensions by a four-by-four matrix. Rotation about an axis uses sine and
cosine terms, and scaling is diagonal. Composition order matters: rotating then translating differs from translating
then rotating.
The viewing transform is constructed from the camera position, a look-at point and an up vector. The three basis
vectors are computed as forward, right and up, normalised and orthogonalised, and the matrix that maps the world
Computer Graphics: Rasterisation, Transforms and Shading Page 1 of 5
,Computer Graphics: Rasterisation, Transforms and Shading
into camera coordinates is the inverse of the camera-to-world transform. A sign error here produces a scene that
renders mirrored, which is the most common symptom in coursework.
Projection converts the view volume into the canonical view volume. Orthographic projection maps a box to the
cube without foreshortening, and perspective projection divides by a function of depth so that distant objects
appear smaller. The perspective matrix places negative z in the w component, which is why the perspective divide
produces the depth-dependent scaling. Clipping must occur before the divide, because vertices behind the eye
would otherwise map to mirrored positions.
Transform Matrix form Effect Common error
Translation Identity with translation in the last Moves the point Applying before rotation when
column the intent was after
Rotation Sine and cosine about an axis Rotates about the origin Rotating about the object
centre without translating first
Scale Diagonal entries Changes size, possibly Transforming normals with the
non-uniformly model matrix
View Inverse of camera to world Expresses world in eye Wrong handedness or up vector
space
Perspective Frustum to cube, w equals minus z Produces foreshortening Dividing before clipping
3. Rasterisation and visibility
Rasterisation determines which pixels a primitive covers. For a triangle, the standard approach computes edge
functions for each of the three edges and accepts a pixel when all three are consistent in sign, which is efficient
and gives a natural barycentric coordinate for interpolation. Line drawing uses an incremental algorithm such as
Bresenham's, which chooses the next pixel from an integer error term and therefore avoids floating point.
Interpolation across the triangle must be perspective-correct. Screen-space linear interpolation of attributes
produces texture swimming, because the mapping from screen space to the surface is not affine under perspective
projection. The correction divides the attribute and the reciprocal of w by the interpolated reciprocal of w, which
restores the correct proportions.
Visibility is resolved with a depth buffer in the standard pipeline: each fragment stores depth and replaces the
stored value if it is nearer. The z-buffer has constant cost per pixel and handles arbitrary geometry, but it is
memory-hungry and suffers from precision artefacts when the near and far planes are far apart. Alternative
approaches include the painter's algorithm, which sorts primitives and fails on intersecting geometry, and BSP
trees, which order geometry once and are suited to static scenes.
• Edge functions give both coverage and barycentric weights at no extra cost.
• Perspective-correct interpolation is required for texture coordinates and normals.
• Precision artefacts are reduced by increasing the near plane distance, not the far plane.
• Back-face culling halves the fragment load for closed surfaces.
• Early depth testing saves shading work but must be disabled for transparency.
4. Lighting and shading models
The illumination model approximates the interaction of light with surfaces. Ambient, diffuse and specular terms
sum to the reflected intensity. Lambertian diffuse reflection is proportional to the cosine of the angle between the
surface normal and the light direction, which is computed as the dot product of unit vectors and clamped at zero.
Specular reflection is modelled by a power of the cosine between the reflected light direction and the view
direction, with the exponent controlling the size of the highlight.
Blinn-Phong replaces the reflected vector with the halfway vector between light and view, which is cheaper and
produces a broader highlight that many consider more realistic at grazing angles. Physically based models use the
microfacet formulation, with a normal distribution function, a geometry term and a Fresnel term, and conserve
Computer Graphics: Rasterisation, Transforms and Shading Page 2 of 5