Shadow mapping

What Is Shadow Mapping?

Shadow mapping is a real-time rendering technique used in three-dimensional computer graphics to compute which parts of a scene lie in shadow relative to a light source. By comparing depth values stored in a precomputed texture against the depth of each rendered pixel, the algorithm determines whether a given point is visible from the light or occluded by intervening geometry. The technique produces plausible shadowing under dynamic lighting conditions with computational cost low enough for interactive applications such as video games and simulation software.

Shadow mapping was introduced by Lance Williams in 1978, making it one of the oldest shadow algorithms still in widespread use. Its enduring adoption stems from its compatibility with the rasterization pipeline common to graphics hardware: it requires no specialized geometry processing and operates on depth data that the GPU already computes during normal rendering. An accessible technical treatment of the algorithm and its extensions appears in NVIDIA's GPU Gems on omnidirectional shadow mapping.

Depth Map Generation

The algorithm begins with a rendering pass from the light source's point of view. The scene is drawn using the light as the camera, and only depth values are recorded, producing a shadow map texture whose each texel stores the distance from the light to the nearest visible surface at that projection angle. For directional lights such as sunlight, an orthographic projection is used; for point lights, a cube map covering all six directions captures the full hemisphere of influence. This depth-only pass is computationally inexpensive because it skips color calculations, and the resulting shadow map can be reused across multiple lighting evaluations in the same frame.

Shadow Testing and Rendering

During the main rendering pass, each fragment is transformed into the light's coordinate system and its depth is compared against the corresponding value stored in the shadow map. If the fragment's depth exceeds the stored value by more than a small bias threshold, it lies behind a surface that blocked the light's path and is shaded as shadowed. The bias term prevents self-shadowing artifacts caused by numerical precision limits, though tuning it requires care: too large a bias causes shadows to detach from their casters, a visible error called Peter Panning. Resolution limits in the shadow map produce aliasing at shadow edges, a problem addressed through filtering strategies including percentage-closer filtering (PCF), which samples multiple neighboring shadow map texels and averages the results.

Soft Shadows and Cascaded Shadow Maps

Hard shadows, the result of a single comparison per fragment, are unrealistic for extended light sources. Percentage-Closer Soft Shadows (PCSS) approximates softness by modulating the PCF filter radius based on the blocker distance, producing contact-hardened shadows that become softer farther from occluding geometry. Large outdoor scenes present a different challenge: a single shadow map cannot simultaneously cover a wide view frustum at high resolution. Cascaded Shadow Maps (CSM) partition the view frustum into depth slices and assign a separate shadow map to each, concentrating resolution near the camera where shadow detail is perceptually most important. These extensions are detailed in the DigiPen master's thesis on shadow rendering techniques for real-time applications, which surveys the algorithm family from basic depth mapping through advanced soft shadow methods. Shadow volumes provide an alternative with different tradeoffs, though for complex scenes LearnOpenGL's tutorial on shadow mapping shows that depth map approaches remain dominant in practice.

Applications

Shadow mapping has applications in a wide range of disciplines, including:

  • Real-time video game rendering on consumer GPU hardware
  • Film and television visual effects production
  • Architectural visualization and virtual walkthroughs
  • Flight simulators and military training environments
  • Augmented reality and mixed reality display systems
Loading…