Unit 4: 3D graphics and rendering
Computer Graphics notes · PTU syllabus (PGCA1919)
On this page
- Unit summary
- 3D transformations
- Viewing pipeline and coordinates
- Parallel and perspective projections
- Perspective projection mathematics
- Visible-surface determination
- Illumination models: ambient, diffuse and specular reflection
- Shading models: flat, Gouraud and Phong
- Ray tracing
- Key terms
- Quick revision
- Important questions
Unit summary
Realistic 3D images need transformations, projections, hidden-surface removal and lighting. This unit covers 3D transformations, the viewing pipeline and coordinates, parallel and perspective projections, visible-surface determination — back-face removal, z-buffer, scan-line, painter's and area subdivision methods — illumination and shading models, ray tracing, ambient, diffuse and specular reflection, Phong's model and Gouraud shading.
After this unit you can
- Apply 3D transformations and projections
- Explain the 3D viewing pipeline
- Compare visible-surface determination methods
- Explain illumination models and shading methods
PTU syllabus topics
- 3D transformations
- viewing pipeline and coordinates
- parallel and perspective projections
- visible-surface determination (back-face removal, z-buffer, scan-line, painter's algorithm, area subdivision)
- illumination and shading models
- ray tracing
- ambient/specular/diffuse reflection
- Phong's model
- Gouraud shading
Topic 1
3D transformations
Translation
x′ = x + tx, y′ = y + ty, z′ = z + tz
Scaling
x′ = sx·x, y′ = sy·y, z′ = sz·z
Rotation about the z-axis
x′ = x cos θ − y sin θ; y′ = x sin θ + y cos θ; z′ = z
Rotation about the x-axis
y′ = y cos θ − z sin θ; z′ = y sin θ + z cos θ; x′ = x
Rotation about the y-axis
z′ = z cos θ − x sin θ; x′ = z sin θ + x cos θ; y′ = y
- 1
Translate the axis to pass through the origin
- 2
Rotate about x so the axis lies in the xz-plane
- 3
Rotate about y so the axis coincides with z
- 4
Rotate by θ about z
- 5
Apply the inverse rotations
- 6
Apply the inverse translation
- Reflection in 3D is about a plane (e.g., xy-plane: z′ = −z); shear shifts coordinates in proportion to another coordinate.
Example
3D translation: the point (2, 3, 4) translated by (5, −1, 2) becomes (7, 2, 6). Scaling by 2 in all directions about the origin gives (4, 6, 8).
Exam tip
3D transformations use 4 × 4 homogeneous matrices.
Topic 2
Viewing pipeline and coordinates
- 1Modelling transformation
Object to world coordinates
- 2Viewing transformation
World to camera (viewing) coordinates using view reference point, view-plane normal and view-up vector
- 3Projection transformation
Parallel or perspective to projection coordinates
- 4Normalisation and clipping
To a canonical view volume
- 5Viewport transformation
To device coordinates for display
Example
From model to screen: a car model is placed in a scene (world coordinates), viewed from a camera position (viewing coordinates), projected onto a plane (projection coordinates), normalised, and mapped to the screen's pixels (device coordinates).
Exam tip
Learn the order of coordinate systems in the 3D viewing pipeline.
Topic 3
Parallel and perspective projections
- Projection maps 3D points onto a 2D projection plane along projectors from a centre of projection.
Parallel
Projectors parallel; centre at infinity
Orthographic
Projectors perpendicular to the plane — front, top, side views; axonometric (isometric)
Oblique
Projectors at an angle — cavalier, cabinet
Perspective
Projectors meet at a centre; one-, two- and three-point perspective
Example
Choosing a projection: an engineering drawing uses parallel (orthographic) projection so lengths can be measured; a game uses perspective projection so distant objects look smaller and the scene looks realistic.
Exam tip
Parallel: projectors parallel, sizes preserved. Perspective: projectors meet at a centre, distant objects shrink.
Topic 4
Perspective projection mathematics
- With the centre of projection at the origin and the projection plane at z = d:
Projected x
xp = x·d ÷ z
Projected y
yp = y·d ÷ z
Homogeneous form
(x, y, z, z ÷ d) then divide by the fourth coordinate
Example
d = 2: point (4, 6, 8) projects to (4 × 2 ÷ 8, 6 × 2 ÷ 8) = (1, 1.5); the farther point (4, 6, 16) projects to (0.5, 0.75) — distant objects look smaller.
- Properties: foreshortening (size decreases with distance), vanishing points where parallel lines appear to meet; realistic but does not preserve true measurements.
Centre of projection
At infinity
At a finite point
Size with distance
Unchanged
Decreases
Parallel lines
Remain parallel
Converge at vanishing points
Use
Engineering drawings, CAD
Games, architecture renderings, films
Topic 5
Visible-surface determination
- Hidden surfaces must be removed so that only surfaces facing and nearest to the viewer are drawn. Methods work in object space (compare objects) or image space (decide per pixel).
Back-face removal
Discard polygons whose normal points away from the viewer (N · V > 0 in a right-handed view looking along −z)
Object space; removes about half of polygons; enough only for single convex objects
Z-buffer (depth buffer)
For each pixel keep the nearest depth; draw a polygon's pixel only if it is nearer than the stored depth
Image space; simple and hardware-supported; needs a depth buffer
Scan-line method
Process one scan line at a time with active edge and polygon lists; determine the nearest surface along spans
Image space; uses coherence
Painter's (depth-sort) algorithm
Sort polygons by depth and paint from farthest to nearest
Object and image space; cyclic overlaps need splitting
Area subdivision (Warnock)
Subdivide the screen until each area is simple — empty, one polygon, or one polygon in front
Image space; recursive
- 1Initialise depth buffer to the farthest value and frame buffer to the background
- 2For each polygon and each pixel it covers, compute depth z
- 3If z is nearer than depth[x][y], store z and the polygon's colour
- 4After all polygons, the frame buffer holds the visible image
Example
Z-buffer method: for each pixel, the depth of the nearest surface found so far is stored. When a new surface covers the pixel, its depth is compared; if it is closer, the pixel colour and depth are updated — so the nearest surface always wins.
Exam tip
Methods: back-face detection, z-buffer (depth buffer), A-buffer, scan-line, depth sorting (painter's algorithm).
Topic 6
Illumination models: ambient, diffuse and specular reflection
Ambient
Ia = ka × Iamb — uniform background light
Diffuse (Lambertian)
Id = kd × Il × (N · L) — depends on the angle between surface normal and light
Specular
Is = ks × Il × (R · V)ⁿ — shiny highlights; larger n gives smaller, sharper highlights
Total intensity
I = Ia + Id + Is (summed over lights), optionally attenuated with distance
- ka, kd, ks are the material's ambient, diffuse and specular coefficients (0–1); N is the unit normal, L the direction to the light, R the reflection direction and V the direction to the viewer. This combined formula is Phong's illumination (reflection) model.
Example
Diffuse reflection: with light intensity 1, diffuse coefficient kd = 0.8 and the angle between the light and the surface normal 60°, Idiff = 0.8 × 1 × cos 60° = 0.4. A surface facing the light directly (0°) gets 0.8.
Exam tip
Lambert's law: diffuse intensity ∝ cos θ between the light direction and the surface normal.
Topic 7
Shading models: flat, Gouraud and Phong
Flat (constant) shading
One intensity per polygon
Fast; faceted look
Gouraud shading
Compute intensity at vertices (using averaged normals) and interpolate intensities across the polygon
Smooth; may miss or smear specular highlights; Mach bands
Phong shading
Interpolate normals across the polygon and apply the illumination model at each pixel
Realistic highlights; more computation
Example
Comparing shading: a sphere drawn with flat shading looks faceted; Gouraud shading interpolates vertex intensities, giving smooth shading but possibly missing highlights; Phong shading interpolates normals, showing realistic specular highlights at higher cost.
Exam tip
Flat → Gouraud → Phong: increasing realism and computation.
Topic 8
Ray tracing
- 1For each pixel, cast a ray from the eye through the pixel
- 2Find the nearest object the ray hits
- 3Compute local illumination; send shadow rays to lights
- 4Spawn reflected and refracted rays recursively
- 5Combine contributions for the pixel colour
- Produces shadows, reflections and transparency naturally; computationally expensive, but real-time ray tracing is now supported by modern GPUs.
Example
Ray tracing a mirror: a ray from the eye hits a mirror; the method traces a reflected ray, which hits a red ball, so the mirror pixel shows the ball's reflection. Shadow rays towards the light check whether the point is in shadow.
Exam tip
Ray tracing handles reflections, refraction and shadows naturally but is computationally expensive.
Key terms
- Z-buffer
- Per-pixel depth memory for hidden-surface removal
- Back-face
- Polygon facing away from the viewer
- Diffuse reflection
- Light scattered equally in all directions
- Specular reflection
- Mirror-like highlight depending on viewing angle
- Gouraud shading
- Interpolating vertex intensities across a polygon
Quick revision
- 3D translation, scaling, rotation; viewing pipeline; parallel and perspective projections.
- Object-space vs image-space methods.
- Back-face, z-buffer, scan-line, painter's, area subdivision.
- Ambient, diffuse, specular; Phong illumination model.
- Flat, Gouraud, Phong shading; ray tracing.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.What is back-face removal?
- Q2.How does the z-buffer algorithm decide visibility?
- Q3.What is the painter's algorithm?
- Q4.Write the diffuse reflection equation.
- Q5.Distinguish Gouraud and Phong shading.
- Q6.What does ray tracing compute well?
Long-answer questions
- Q1.Explain 3D transformations and the viewing pipeline.
- Q2.Explain parallel and perspective projections.
- Q3.Compare visible-surface determination methods.
- Q4.Explain illumination models and shading methods.
Stuck on this unit?
Message SBS on WhatsApp for help with Computer Graphics, or to ask about studying M.Sc IT at Synetic.
