Shadow Rendering Techniques
Overview
- Lightmaps
- Stencil buffer shadows
- Shadow mapping
- Real-time ray-tracing
- Or at least, variants that get "close enough"
The right choice of implementation really depends on the game, its assets and environments, and current hardware capabilities
Lightmaps
- Raytracing, but rendered offline and baked into texture data
- Generated as part of level data -- e.g. you hit 'save' in a level editor, lightmaps are a section of saved data
- At runtime, just use multitexturing and multiply diffuse texture sample with lightmap texture sample
- Best for static geometry and non-moving light sources
Full scene without lightmaps (before)
Full scene with lightmaps (after)
Stencil Buffer Shadows
- Most notably used in Doom 3
- Very precise shadows, very few artifacts/glitches from long distances
- Best used in outdoor, open scenes
Stencil Buffer Shadows
- Given a light source, render outwards
- Occluding geometry creates a shadow volume
Shadow Mapping
- Most common implementation of real-time shadows for the last few years
- More flexible in terms of scene variety (indoor, outdoor, whatever)
- Bad precision, prone to low resolution and artifacting issues ("shadow acne") without precautions
Shadow mapping basic algorithm:
- For each light source, render scene into a depth map using the light as a camera
- Doesn't need to be full resolution, e.g. 256x256
Original scene rendered from "light camera" and not "real camera"
Shadow Mapping algorithm
- Project/transform each shadow map created this way onto the scene rendered by the real camera
- Test shadow map depth against real camera depth:
- If shadow map depth < real camera depth, darken pixel
Shadow Mapping issues
- Shadow Acne
- Problem: Low resolution and floating-point precision causes discontinuities, jagged "false" shadows
- Fix: Add some padding to depth test, e.g. shadow map depth has to be less than real depth plus some margin
Real-time Raytracing
- Most accurate - not approximations like other shading/lighting techniques, but literal emulation of light physics
-
Absurdly costly without shortcuts
- Rendering a few seconds of final animation footage can take days of processing
- Getting it to work at 30-60 frames per second is the holy grail
- Solves other issues, too, like transparency or refraction or reflection
Hybrid Ray-tracing
- Mix of traditional rasterization game engines (e.g. deferred rendering) and ray tracing
- Render frame, ray trace only what's accumulated in the G-buffer and not entire scene
Hybrid ray-tracing
Path tracing
Ray-tracing, but with fewer bounces -- approximates with a "russian roulette" early termination
Image credits (and more reading material):
Lightmaps: http://www.flipcode.com/archives/Light_Mapping_Theory_and_Implementation.shtml
Stencil Buffering: http://joshbeam.com/articles/stenciled_shadow_volumes_in_opengl/
Shadow Mapping: https://en.wikipedia.org/wiki/Shadow_mapping and https://www.digitalrune.com/Blog/Post/1765/Shadow-Acne and http://learnopengl.com/img/advanced-lighting/shadow_mapping_acne_diagram.png
Raytracing:
Hybrid: http://www.gamasutra.com/blogs/AlexandruVoica/20140318/213148/Practical_techniques_for_ray_tracing_in_games.php
Path-tracing: https://home.otoy.com/render/brigade/
Shadow Rendering Techniques
By tdhoward
Shadow Rendering Techniques
- 811