Chapter 16: Advanced Topics in Rendering
To move beyond basic geometric shapes and achieve high levels of realism, we must incorporate advanced techniques for lighting, texturing, and artifact reduction.
Lighting and Shading Models
Lighting models simulate how light interacts with surfaces. The most common models are Phong and Gouraud.
1. The Phong Reflection Model
The Phong model calculates the final color of a pixel as a sum of three components:
- Ambient: Constant background light that hits every surface equally.
- Diffuse: Light that scatters in all directions when it hits a rough surface. Calculated using the dot product of the surface normal () and the light direction (): .
- Specular: The bright, shiny "highlight" on a surface. Depends on the viewing angle.
2. Gouraud vs. Phong Shading
- Gouraud Shading: Calculates the light at each vertex and interpolates the resulting colors across the triangle's surface. Faster but can look faceted.
- Phong Shading: Interpolates the normals across the surface and calculates the light for every fragment. Much smoother and handles specular highlights correctly.
Texture Mapping
Texture mapping is the process of applying a 2D image (a "texture") onto the surface of a 3D model.
- UV Mapping: Each vertex is assigned coordinates, which map to specific locations on the 2D texture.
- Sampling: During fragment processing, the GPU "samples" the texture at the interpolated UV coordinates.
- Filtering: Techniques like Bilinear or Trilinear filtering help prevent pixelation when the texture is viewed up close.
- Mipmapping: Storing pre-scaled versions of the texture to improve performance and reduce artifacts when the object is far away.
Anti-Aliasing (AA)
Aliasing occurs when we represent high-frequency data (like smooth lines or curves) on a discrete grid (pixels). This results in "jaggies."
- SSAA (Super-Sample Anti-Aliasing): Renders the scene at a much higher resolution and then scales it down. Highest quality but very expensive.
- MSAA (Multi-Sample Anti-Aliasing): An optimized version of SSAA that only performs expensive sampling on the edges of triangles.
- FXAA / TAA (Post-Processing AA): Algorithms that smooth the final 2D image after it has been rendered.
Shadows
Shadows are essential for defining spatial relationships between objects.
- Shadow Mapping: The scene is first rendered from the point of view of the light source. This "depth map" is then used during the main rendering pass to check if a pixel is "visible" to the light.
- Shadow Volumes: A geometric technique where a "volume" of shadow is projected behind every object. Any pixel inside this volume is in shadow.
Summary
Advanced rendering techniques like Phong shading, texture mapping, and shadow mapping are what turn simple geometric primitives into believable digital worlds. While these techniques add significant computational complexity, modern GPUs are specifically optimized to handle them efficiently through programmable shaders and dedicated hardware units.