What is Shadow Mapping?
Shadow mapping is a shadow rendering technique that uses depth textures to determine which areas are in shadow.
How It Works
The algorithm consists of four key steps:
- Depth texture generation: Render the scene from the light source perspective, storing only depth values
- Distance calculation: Calculate the distance from each pixel to the light source
- Depth comparison: Compare the pixel distance with the corresponding depth texture value
- Shadow determination: If the depth value is smaller than the pixel distance, the pixel is in shadow; otherwise, it's lit
Advantages
- Easy GPU pipeline integration
- Supports dynamic shadows
- Extensible to soft shadows
- Hardware-accelerated depth testing
Disadvantages
- Aliasing: Pixelated shadow edges
- Peter panning: Objects appear to float
- Shadow acne: Self-shadowing artifacts
- Memory usage: Requires depth textures for each light
- Resolution limits: Quality bound by texture size
Typical Parameters
- Shadow map resolution
- Depth bias (prevents shadow acne)
- Near/far clip planes
- Light frustum bounds
- Edge filtering: Nearest, Bilinear, Dithering, Percentage Closer Filtering, Poisson sampling (stratified/rotated), Exponential, Contact hardening shadows
Performance Considerations
- Shadow map resolution (quadratic impact)
- Number of shadow-casting objects
- Lowering the FPS for the shadow map
- Reduce Near/far clip
- LOD systems for shadow casters