1 of 62

Nima Kalantari

CSCE 441 - Computer Graphics

Shadows

Some slides from Scott Schaefer

2 of 62

Shadows

  • Shadows provide clues about depth
  • Make scenes appear more realistic

3 of 62

Shadows

  • Shadows provide clues about depth
  • Make scenes appear more realistic

4 of 62

Outline

  • Simple/Planar Shadows
  • Shadow Maps
  • Shadow Volumes
  • Soft shadows

5 of 62

Simple/Planar Shadows

  • Projection of an object onto a planar surface (floor/wall)
  • Project the object from light to surface
  • Draw the projected object with ambient color

Image taken NVIDIA

6 of 62

Simple/Planar Shadows

  • Stage 1: Render the scene as usual (there won’t be any shadows)
  • Stage 2: project the vertices of objects to the planar surface and draw them only with the ambient color

7 of 62

How to project an object to a planar surface?

Image taken NVIDIA

8 of 62

Ray Equation

unit direction

origin

“time”

point along ray

Ray equation:

Example:

Ray is defined by its origin and a direction vector

9 of 62

Plane Equation

Plane is defined by normal vector and a point on plane

Example:

Plane Equation:

normal vector

any point

all points on plane

10 of 62

Ray Intersection With Plane

Ray equation:

Plane equation:

Solve for intersection

Check:

11 of 62

How to project an object to a planar surface?

Image taken NVIDIA

12 of 62

Problem

13 of 62

How to project an object to a planar surface?

Image taken NVIDIA

14 of 62

Fixed

15 of 62

Simple/Planar Shadows

Fast and simple

Only for planar surfaces (nothing else has shadows cast on it)

Does not account for self-shadowing

Image taken NVIDIA

16 of 62

Outline

  • Simple/Planar Shadows
  • Shadow Maps
  • Shadow Volumes
  • Soft shadows

17 of 62

Shadow Maps

18 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer

19 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer

Shadow Map

20 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer
  • Render scene from viewer’s

perspective

21 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer
  • Render scene from viewer’s

perspective

  • For every pixel
    • Compare depth to the depth value

in shadow map

22 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer
  • Render scene from viewer’s

perspective

  • For every pixel
    • Compare depth to the depth value

in shadow map

23 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer
  • Render scene from viewer’s

perspective

  • For every pixel
    • Compare depth to the depth value

in shadow map

In shadow!

24 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer
  • Render scene from viewer’s

perspective

  • For every pixel
    • Compare depth to the depth value

in shadow map

In shadow!

25 of 62

Shadow Maps

  • Render scene from light’s perspective and save the depth buffer
  • Render scene from viewer’s

perspective

  • For every pixel
    • Compare depth to the depth value

in shadow map

Not in shadow!

26 of 62

Shadow Maps

Image taken from http://www.cse.ohio-state.edu/~haleyb/Hardware/ggDepthBuffer.jpg

27 of 62

Shadow map

  • Stage 1
    • Set up a camera at light
    • Render the scene
    • Store the depth
      • [-1, 1] in NDC
      • stored as a texture [0, 1]

28 of 62

Shadow map

  • Stage 1
    • Set up a camera at light
    • Render the scene
    • Store the depth
      • [-1, 1] in NDC
      • stored as a texture [0, 1]

Shadow map

depth

29 of 62

Shadow map

  • Stage 2
    • Render with viewer camera

Shadow map

depth

30 of 62

Shadow map

  • Stage 2
    • Render with viewer camera
    • Project vertices to light camera NDC

Shadow map

depth

xyz in Light NDC

31 of 62

Shadow map

  • Stage 2
    • Render with viewer camera
    • Project vertices to light camera NDC
    • Convert the projected vertex from [-1, 1] to [0, 1]

Shadow map

depth

xyz between [0, 1]

32 of 62

Shadow map

  • Stage 2
    • Render with viewer camera
    • Project vertices to light camera NDC
    • Convert the projected vertex from [-1, 1] to [0, 1]
    • Use the xy coordinate to look up the depth in shadow map (z’)
    • If z > z’
      • In shadow (only ambient)
    • Else
      • Visible (all shading terms)

Shadow map

depth

xyz between [0, 1]

33 of 62

Problem

34 of 62

Shadow map

  • Stage 2
    • Render with viewer camera
    • Project vertices to light camera NDC
    • Convert the projected vertex from [-1, 1] to [0, 1]
    • Use the xy coordinate to look up the depth in shadow map (z’)
    • If z - e > z’
      • In shadow (only ambient)
    • Else
      • Visible (all shading terms)

e is a small number e.g., 0.001

Shadow map

depth

xyz between [0, 1]

35 of 62

Fixed

36 of 62

Problem

37 of 62

Problem

Outside the light

camera view!

38 of 62

Problem

Outside the light

camera view!

z’ = 0

Blue point in shadow!

39 of 62

Hacky solution

  • Do not check for shadows if a vertex is outside the view volume of the light camera

40 of 62

Correct solution

  • Set up 6 cameras at light

41 of 62

Shadow Maps

  • Advantages
    • Simple to implement
    • Does not depend on scene complexity
      • except to render shadow map
    • Proper self-shadowing
  • Disadvantages
    • Omni-directional light sources require 6 shadow maps to cover every direction
    • Fixed resolution image leads to artifacts

42 of 62

Shadow Map Resolution

Rendered Image

Shadow Map

43 of 62

Outline

  • Simple/Planar Shadows
  • Shadow Maps
  • Shadow Volumes
  • Soft shadows

44 of 62

Anatomy of a Shadow

Shadowing�object

Partially

shadowed

object

Light�source

Eye position

(note that shadows are independent of the eye position)

Surface inside�shadow volume

(shadowed)

Surface outside�shadow volume

(illuminated)

Shadow�volume

(infinite extent)

45 of 62

Shadow Volumes

  • Build polygons for shadow volumes explicitly
  • Render shadow volume polygons from viewer’s

perspective and count inside/outside shadows

Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”

46 of 62

Shadow Volumes

Shadowing object

Light�source

Eye�position

47 of 62

Shadow Volumes

Shadowing object

Light�source

Eye�position

Unshadowed�object

+

-

-

-

+

+

Shadow Volume Count = +1+1+1-1-1-1 = 0

48 of 62

Shadow Volumes

Shadowing object

Light�source

Shadowed�object

Shadow Volume Count = +1+1+1-1 = 2

Eye�position

+

-

+

+

49 of 62

Shadow Volumes

Shadowing object

Light�source

zero

zero

+1

+1

+2

+2

+3

Unshadowed�object

Shadow Volume Count = 0

Eye�position

50 of 62

Implementing Shadow Volumes

  • For each surface, find silhouette edges
  • Build shadow volume (viewer independent) by extending away from light

Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”

51 of 62

Implementing Shadow Volumes

  • Render the scene to obtain the depth
  • Render shadow volume and keep a buffer for counting faces
    • Render front faces and increment if closer than the depth
    • Render back faces and decrement if closer than the depth
  • If buffer is non-zero, then pixel in shadow

52 of 62

Shadow Volumes

Shadowing object

Light�source

Shadowed�object

+

-

+

+

Shadow Volume Count = +1+1+1-1 = 2

Eye�position

53 of 62

Shadow Volumes: Examples

Image taken from “Doom 3”

54 of 62

Shadow Volumes

  • Advantages
    • Omni-directional light sources
    • Proper self-shadowing behavior
    • Pixel perfect shadows

55 of 62

Problems with Shadow Volumes

zero

zero

+1

+1

+2

+2

+3

+

-

+

+

-

-

Unshadowed�object

Shadow Volume Count = +1+1+1-1-1-1 = 0

56 of 62

Problems with Shadow Volumes

zero

zero

+1

+1

+2

+2

+3

Near clip�plane

Far clip�plane

Missed shadow volume intersection due to near clip plane clipping; leads to mistaken count

Unshadowed�object

Shadow Volume Count = +1+1-1-1-1 = -1

-

+

+

-

-

57 of 62

Problems with Shadow Volumes

Shadowing object

Light�source

Shadow test fails because

eye in shadow

Shadow Volume Count = 0

Eye�position

58 of 62

Outline

  • Simple/Planar Shadows
  • Shadow Maps
  • Shadow Volumes
  • Soft shadows

59 of 62

Soft Shadows

  • Point lights cause hard shadows
  • Lights are not infinitely small points in reality
  • Area light sources

cause soft shadows

http://graphics.ucsd.edu/~henrik/images/cbox.html

60 of 62

Soft Shadows

  • Point lights cause hard shadows
  • Lights are not infinitely small points in reality
  • Area light sources

cause soft shadows

http://graphics.ucsd.edu/~henrik/images/cbox.html

61 of 62

Soft Shadows

  • Simulate area lights with lots of points lights (Expensive)

Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”

The cluster of point lights.

62 of 62

Soft Shadows

  • Simulate area lights with lots of points lights
  • Blur shadows in image space (cheap, but inaccurate)

http://www.gamedev.net/reference/articles/article2193.asp