Author: Romain Vergne (
website)
Please cite my name and add a link to my web page if you use this course
Image synthesis and OpenGL: shadows
Quick links to:
- Importance of shadows
- Definition
- Shadow volumes
- Shadow map
- Perspective Shadow Map
- Cascaded Shadow map
- Fixed soft shadows and
filtering
- Extended Soft Shadows
- Sources
Importance of shadows
Shadows
can surprisingly affect perceived object positions
Definition
\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
\rho_a L_a +
\sum_{k}
\rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}_k) \
(\mathbf{n}\cdot\pmb{\ell}_k) \
V(\mathbf{p},\pmb{\ell}) \ L(\mathbf{p} \leftarrow
\pmb{\ell}_k)
\]
Visibility term \( V \) at a point \( \mathbf{p} \)
- 0 if the light source is hidden at point \( \mathbf{p} \)
- 1 if the light source is visible at point \( \mathbf{p} \)
- Shadows ~= surfaces for which light sources are not visible
Shadow volumes
- A punctual source divides space in two: shadowed and lighted regions
- shadow volume = boundary between these regions
Algorithm
- Render the scene with depth ambient lighting attributes
- From a light source, calculate silhouettes of all occluders
- Extrude silhouettes away from the light
- Render the shadow volume: from the camera, test front and back shadow
volume faces and update the stencil buffer
- Do a light pass using the stencil buffer
- Repeat steps 2-5 for all lights
Dealing with soft shadows
- Compute shadow volumes for a few light positions
- Compare shadow faces for the different positions
Shadow volumes in Doom 3
- + precise
- + directional / punctual light sources
- - highly dependent on the scene geometry
- necessitates manifold meshes
- lots of triangles : lots of silhouette extrusions
Shadow map
Algorithm
- From the light point of view
- render the scene
- store depth in a buffer (the shadow map) using render to texture
(FBO)
- via an orthographic projection with a directional light
- via a perspective projection with a spot light
- via a perspective projection in a cube map for a point light
- From the camera point of view
- render the scene
- compute lighting
- project/convert vertex position in the light coordinate system
- compare vertex depth with the one stored in the shadow map
- if the vertex is farther, then it is in the shadow
left: final rendering from the camera.
Middle: rendering from the light source. Right: depth map obtained from
the light source (shadow map)
Shadow map (depth from light)
|
Basic shadow mapping
|
Issues
- Shadow acne effect
- Solution 1: use a bias when comparing depths (but may produce other
artifacts)
- Solution 2: do not use thin geometry. Draw back faces first
(generate shadow maps), and front faces next to render and compare
Perspective Shadow Map
A solution consists in increasing the resolution of the shadow map near
the camera (where the problem is the most important and visible)
Cascaded Shadow map
Use several shadow maps at different
resolutions depending on camera frustum
A simple example
here
Fixed soft shadows and
filtering
Percentage Closer Filtering (PCF)
- Bilinear interpolation on the result of the comparison test
- Warning: different from comparing the result of the bilinear
interpolation on the depth map
Better but still a lot of aliasing
- Does not generate soft shadows
- May introduces artifacts
Variance / Convolution / Exponential Shadow Maps
- Solution: approximate shadow test by a linear function that can be
prefiltered
- Goal: blur the shadow map to generate realistic soft shadows
|
|
|
VSM: based on mean and variance
depth values
- May produce light bleeding effects
- But better solutions proposed [Lauritzen 07/08]
|
CSM: based on 1D fourier expansion
- May produce bleeding and ringing
- Quite slow
|
ESM: based on an exponential
approximation
- May produce small artifacts
- But resolved by [Salvi08]
- Fast
|
Extended Soft Shadows
Percentage Closer Soft Shadows
Observation: increasing the PCF kernel size produces soft shadows
Solution: Percentage Closer Soft Shadows
- Blocker search
- sample the depth buffer
- average depths that are closer to the light
- Estimate penumbra
- estimate penumbra width based on light size and blocker/receiver
distances from the light
- Filter
- using PCF...
- ... or VSM, CSM, ESM
Example using a simple
gaussian filtering
Examples
using PCF and bilateral filters
Original PCSS
(PCF filter)
|
Screen Space PCSS
(bilateral filter)
|
Brute force sampling (not real-time but correct)
|
|
|
|
|
1 source
|
2 sources
|
4 sources
|
16 sources
|
256 sources
|
Sources