Visible Surface Detection, Illumination and Shading
Once a 3D scene has been defined and transformed, the renderer must determine which surfaces are visible from the camera and how they should appear under the scene's lighting. These closely related problems—visible surface determination and illumination and shading—produce the final pixel colours that the user sees.
Back-Face Culling
The simplest and fastest visibility test is back-face culling. For an opaque closed object, polygons whose outward-facing normals point away from the viewer are invisible and can be discarded. The test reduces to computing the sign of the dot product between the viewing direction and the polygon normal. Back-face culling typically removes about half the polygons in a scene at negligible cost.
Z-Buffer Algorithm
The Z-buffer (depth buffer) algorithm is the dominant visibility method in modern graphics hardware. A depth buffer the same size as the frame buffer stores the minimum depth drawn at each pixel. When rasterizing each fragment, the algorithm compares its depth to the stored value; if the fragment is closer, its colour and depth replace the existing values. The algorithm is simple, parallel, and requires memory proportional to the image rather than the scene complexity.
Scanline and Painter's Algorithms
The scanline algorithm processes one horizontal scanline at a time, maintaining an active edge list and resolving visibility by comparing depths along each scanline. The painter's algorithm sorts polygons by depth and draws them from back to front so that nearer polygons overwrite farther ones. Both methods are useful pedagogically but have weaknesses: scanline is complex to implement for concave polygons, and the painter's algorithm fails when polygons intersect or form cyclic overlaps.
BSP Trees and Ray Casting
Binary Space Partitioning (BSP) trees recursively subdivide the scene by planes, producing a data structure that allows visibility to be resolved in any viewing direction. Ray casting traces a ray from the camera through each pixel, finds the nearest intersected surface, and shades that point. Ray casting is the basis for ray tracing, which additionally traces secondary rays for reflections, refractions, and shadows.
Illumination Models
An illumination model computes the intensity of light leaving a point in a given direction. The classic Phong illumination model decomposes light into ambient, diffuse, and specular components. Ambient light simulates uniform indirect illumination; diffuse reflection, governed by Lambert's cosine law, depends on the angle between the light direction and the surface normal; specular reflection produces shiny highlights along the direction close to the mirror reflection. Modern rendering uses more physically accurate models such as Cook–Torrance and the microfacet BRDF family.
Shading Models
Three common shading models trade quality for speed. Flat shading computes one colour per polygon using the polygon normal; it is fast but reveals the faceted structure of meshes. Gouraud shading interpolates colours computed at vertices across the polygon, giving smoother appearance but missing specular highlights that fall inside polygons. Phong shading interpolates the normal vector itself and evaluates the illumination model per pixel; it produces the highest quality at higher cost.
Texture Mapping
Texture mapping applies an image to the surface of a 3D object, providing visual detail without increasing geometric complexity. Each vertex stores texture coordinates (u, v); these are interpolated across the polygon and used to index into the texture. Filtering techniques—nearest-neighbour, bilinear, trilinear, and anisotropic—control the quality of minification and magnification. Bump mapping, normal mapping, and displacement mapping simulate surface detail by perturbing the surface normal or position.
Shadows and Global Illumination
Accurate shadows add dramatically to realism. Shadow maps render the scene from the light's point of view and compare pixel depths to test whether a fragment is in shadow. Shadow volumes use extruded silhouettes to mark shadowed regions in the stencil buffer. Global illumination techniques—ray tracing, radiosity, path tracing—simulate inter-reflection of light between surfaces and produce the soft lighting and colour bleeding seen in real environments.
Summary
Visible-surface determination and shading translate a geometric scene into a lit image. The Z-buffer and ray tracing are the workhorses of visibility, while Phong shading and modern physically-based models produce the appearance of lit materials. Together with texture mapping and global illumination, these techniques deliver the realism of modern 3D graphics.