1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more...

43
1 Dr. Scott Schaefer Shadows

Transcript of 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more...

Page 1: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

1

Dr. Scott Schaefer

Shadows

Page 2: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

2/40

Shadows

Shadows provide clues about depth Make scenes appear

more realistic

Page 3: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

3/40

Shadows

Shadows provide clues about depth Make scenes appear

more realistic

Page 4: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

4/40

Shadow Algorithms

Simple/Planar Shadows Shadow Maps Shadow Volumes

Page 5: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

5/40

Simple/Planar Shadows

Projection of an object onto a planar

surface (floor/wall) Build projection matrix

from light to wall Draw object in black

using projection matrix

Image taken from http://developer.nvidia.com/object/robust_shadow_volumes.html

Page 6: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

6/40

Simple/Planar Shadows

Fast and simple Does not account for self-shadowing Only works for planar

surfaces (nothing else

has shadows cast on it)

Image taken from http://developer.nvidia.com/object/robust_shadow_volumes.html

Page 7: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

7/40

Shadow Maps

Page 8: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

8/40

Shadow Maps

Render scene from light’s perspective

Page 9: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

9/40

Shadow Maps

Render scene from light’s perspective

Shadow Map

Page 10: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

10/40

Shadow Maps

Render scene from light’s perspective Render scene from

viewer’s perspective

Page 11: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

11/40

Shadow Maps

Render scene from light’s perspective Render scene from

viewer’s perspective For every pixel

Transform to world space

Compare distanceto value in shadow map

Page 12: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

12/40

Shadow Maps

Render scene from light’s perspective Render scene from

viewer’s perspective For every pixel

Transform to world space

Compare distanceto value in shadow map

Page 13: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

13/40

Shadow Maps

Render scene from light’s perspective Render scene from

viewer’s perspective For every pixel

Transform to world space

Compare distanceto value in shadow map

In shadow!

Page 14: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

14/40

Shadow Maps

Render scene from light’s perspective Render scene from

viewer’s perspective For every pixel

Transform to world space

Compare distanceto value in shadow map

In shadow!

Page 15: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

15/40

Shadow Maps

Render scene from light’s perspective Render scene from

viewer’s perspective For every pixel

Transform to world space

Compare distanceto value in shadow map

Not in shadow!

Page 16: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

16/40

Shadow Maps

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

Page 17: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

17/40

Shadow Maps

AdvantagesSimple to implementDoes not depend on scene complexity

(except to render shadow map) Disadvantages

Fixed resolution image leads to artifactsOmni-directional light sources require 6

shadow maps to cover every direction

Page 18: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

18/40

Perspective Shadow Maps

Shadow maps are limited by screen resolution and depend on object distance!

Small distance

Page 19: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

19/40

Perspective Shadow Maps

Shadow maps are limited by screen resolution and depend on object distance!

Huge distance

Page 20: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

20/40

Perspective Shadow Maps

Distort viewing transformation from light’s perspective to create a more uniform sampling from viewer’s perspective

Image taken from “Perspective Shadow Maps”

Page 21: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

21/40

Perspective Shadow Maps

Distort viewing transformation from light’s perspective to create a more uniform sampling from viewer’s perspective

Image taken from “Perspective Shadow Maps”

Page 22: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

22/40

Anatomy of a Shadow

Shadowingobject

Partiallyshadowed object

Lightsource

Eye position

(note that shadows are independent of the eye position)

Surface insideshadow volume

(shadowed)

Surface outsideshadow volume

(illuminated)

Shadowvolume

(infinite extent)

Page 23: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

23/40

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”

Page 24: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

24/40

Shadow Volumes

Shadowing object Lightsource

Eyeposition

Page 25: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

25/40

Shadow Volumes

Shadowing object Lightsource

zero

zero

+1

+1+2 +2

+3Eyeposition

Page 26: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

26/40

Shadow Volumes

Shadowing object Lightsource

zero

zero

+1

+1+2 +2

+3Eyeposition

Unshadowedobject

+ ---+ +

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

Page 27: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

27/40

Shadow Volumes

Shadowing object Lightsource

zero

zero

+1

+1+2 +2

+3

Shadowedobject

+ -+ +

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

Eyeposition

Page 28: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

28/40

Shadow Volumes

Shadowing object Lightsource

zero

zero

+1

+1+2 +2

+3

Unshadowedobject

Shadow Volume Count = 0

Eyeposition

Page 29: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

29/40

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”

Page 30: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

30/40

Implementing Shadow Volumes

Use stencil buffer to count intersections with shadow volume Render front faces and increment if closer to viewer Render back faces and decrement if closer to viewer Don’t update color or depth values!!!!

If stencil buffer is non-zero, then pixel in shadow

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

Stencil value 1

Stencil value 0

Page 31: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

31/40

Shadow Volumes: Examples

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

Page 32: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

32/40

Shadow Volumes: Examples

Image taken from “Doom 3”

Page 33: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

33/40

Problems with Shadow Volumes

zero

zero

+1+1

+2

+2

+3

Near clipplane

Far clipplane

Page 34: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

34/40

Problems with Shadow Volumes

zero

zero

+1+1

+2

+2

+3

Near clipplane

Far clipplane

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

Page 35: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

35/40

Problems with Shadow Volumes

Shadowing object Lightsource

Shadow test fails!

Shadow Volume Count = 0

Eyeposition

Page 36: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

36/40

Shadow Volumes

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

Disadvantages Surfaces can only use planar polygons Silhouette computation uses CPU Heavy on fill-rate Near/Far clipping planes lead to problems

Page 37: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

37/40

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

Page 38: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

38/40

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

Page 39: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

39/40

Soft Shadows

Simulate area lights with lots of points lights

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

Expensive

The cluster of point lights.

Page 40: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

40/40

Soft Shadows

Simulate area lights with lots of points lights Blur shadows in image space

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

Cheap, inaccurate

Page 41: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

41/40

Page 42: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

42/40

Solution: Invert Depth Test

Shadowing object Lightsource

Shadowed object

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

Eyeposition

- +

-

Page 43: 1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.

43/40

Solution: Invert Depth Test

Shadowing object Lightsource

Shadowed object

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

Eyeposition

- +

-Now have problem

with far clipping plane