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:
  1. Importance of shadows
  2. Definition
  3. Shadow volumes
  4. Shadow map
  5. Perspective Shadow Map
  6. Cascaded Shadow map
  7. Fixed soft shadows and filtering
  8. Extended Soft Shadows
  9. Sources

Importance of shadows

Shadows can surprisingly affect perceived object positions



Images from [Mamassian et al. 1998]. Watch the demo here.


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} \)


Shadow volumes



Algorithm

  1. Render the scene with depth ambient lighting attributes
  2. From a light source, calculate silhouettes of all occluders
  3. Extrude silhouettes away from the light
  4. Render the shadow volume: from the camera, test front and back shadow volume faces and update the stencil buffer
  5. Do a light pass using the stencil buffer
  6. Repeat steps 2-5 for all lights



Dealing with soft shadows

  1. Compute shadow volumes for a few light positions
  2. Compare shadow faces for the different positions




Shadow volumes in Doom 3



Shadow map

Algorithm

  1. From the light point of view
    1. render the scene
    2. store depth in a buffer (the shadow map) using render to texture (FBO)
      1. via an orthographic projection with a directional light
      2. via a perspective projection with a spot light
      3. via a perspective projection in a cube map for a point light
  2. From the camera point of view
    1. render the scene
    2. compute lighting
    3. project/convert vertex position in the light coordinate system
    4. compare vertex depth with the one stored in the shadow map
    5. 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






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)



Images taken here







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)





Better but still a lot of aliasing


Variance / Convolution / Exponential Shadow Maps




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

  1. Blocker search
    1. sample the depth buffer
    2. average depths that are closer to the light
  2. Estimate penumbra
    1. estimate penumbra width based on light size and blocker/receiver distances from the light
  3. Filter
    1. using PCF...
    2. ... 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


PREVIOUS: EXERCICE07
NEXT: EXERCICE08