overview of shadow rendering · – render into texture • restricted to planar objects. 11 the...

47
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overview of Shadow Rendering Brandon Lloyd April 9, 2007 With some slides and images cannibalized from Han-Wei Shen http://www.cse.ohio-state.edu/~hwshen/781/

Upload: others

Post on 04-Aug-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Overview of Shadow Rendering

Brandon Lloyd

April 9, 2007With some slides and images cannibalized from Han-Wei Shenhttp://www.cse.ohio-state.edu/~hwshen/781/

Page 2: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

2The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Outline

• Introduction• Planar Shadows• Shadow Volumes• Shadow Maps• Soft Shadows

Page 3: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

3The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Why are shadows important?

• Improved understanding of an object’s shape and position.

• Realism

Page 4: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

4The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

What is a shadow?Light

• Shadows occur on surfaces that are not fully visible the light.Eye Object

Shadow

Page 5: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

5The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Terminology

(area) light source

receiver shadow

occluder

umbra

penumbra • umbra – fully shadowed region• penumbra – partially shadowed region

Page 6: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

6The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

“Hard” and “Soft” Shadows

• Depends on the type of light sources– Point or Directional (“Hard Shadows”)– Area (“Soft Shadows”)

point directional area

umbra penumbra

Page 7: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

7The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

“Hard” and “Soft” Shadows

Hard shadow Soft shadow – point light source – area light source

Page 8: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

8The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Outline

• Introduction• Planar Shadows• Shadow Volumes• Shadow Maps• Soft Shadows

Page 9: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

9The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Planar Shadows

• The simplest algorithm – shadowing occurs when objects cast shadows on planar surfaces (projection shadows)

shadow

lighty

y=0

lighty

shadow

n.x + d =0

Page 10: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

10The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Issues with planar shadows

• Shadow polygon generation (z fighting)– Add an offset to the shadow polygons (glPolygonOffset)– Draw receivers first, turn z-test off, then draw the

shadow polygons. After this, draw the rest of the scene.

• Shadow polygons fall outside the receiver – Using stencil buffer – draw receiver and update the

stencil buffer

• Shadows have to be rendered at each frame– Render into texture

• Restricted to planar objects

Page 11: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

11The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Outline

• Introduction• Shadow Volumes• Shadow Maps• Soft Shadows

Page 12: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

12The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

2D Cutaway of a Shadow Volume

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 13: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

13The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Overview

1.Construct shadow volumes from occluders

2.Determine if each visible point lies inside a shadow volume

Page 14: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

14The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Stencil counting

Eye

zero

zero

+1

+1+2 +2

+3

Page 15: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

15The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Illuminated, behind (zpass)

zero

zero

+1

+1+2 +2

+3

Unshadowedobject

+ ---+ +

Page 16: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

16The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Shadowed (zpass)

zero

zero

+1

+1+2 +2

+3

Shadowedobject

+ -+ +

Page 17: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

17The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Illuminated, in front (zpass)

zero

zero

+1

+1+2 +2

+3

Shadowedobject

Page 18: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

18The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Problems with near clip plane

zero

zero

+1+1+2

+2+3

Near clipplane

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

Far clipplane

Page 19: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

19The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Illuminated, behind (zfail)

zero

zero

+1

+1+2 +2

+3

Unshadowedobject

Page 20: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

20The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Shadowed (zfail)

Eyeposition

zero

zero

+1

+1+2 +2

+3

+ +

Shadowedobject

Page 21: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

21The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Illuminated, in front (zfail)

Eyeposition

zero

zero

+1

+1+2 +2

+3

- +- - + +

Shadowedobject

Page 22: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

22The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Constructing shadow volumes

• Find silhouette edges– Brute force

• Extrude edges to infinity– homogeneous coordinates (w=0)

• zfail needs caps – Near caps = tris facing light– Far caps = near caps rendered at infinity– Needs projection matrix with zfar = ∞

Page 23: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

23The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Algorithm

• Render scene with ambient lighting

• Set stencil op:– INC on front faces, DEC on backfaces

• Render shadow volumes• Disable writes where stencil≠0• Render scene with full lighting

Page 24: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

24The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Comparison with shadow maps

• Advantages– No aliasing or bias problems– Omnidirectional lights

• Disadvantages– Model must be polygonal – Requires extra passes– FILL-RATE CONSUMPTION

Page 25: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

25The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Fill-rate consumption

Final imageShadow volumes intransparent yellow

Page 26: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

26The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Clamped Shadow Volumes

Standard shadowvolumes

Discrete clamping

Page 27: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

27The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Video

Page 28: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

28The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Outline

• Introduction• Planar Shadows• Shadow Volumes• Shadow Maps

– Basic algorithm– Self shadowing– Aliasing

• Soft Shadows

Page 29: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

29The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Shadow mapsUse the depth map in the light view to determine if sample point is visible

Eye Light

Point in shadow visible to the eye by not visible to the light

Page 30: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

30The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Recipe

• Render light-view to a depth texture

• Setup up eye view matrices• Setup texture coordinates

– glTexGen …– EYE_LINEAR mode– Specify identity matrix (multiplied by

inverse model view)

Page 31: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

31The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Recipe

• Setup texture matrix

• Enable shadow map texturing (depth compare)

MVP LL ××

⎥⎥⎥⎥

⎢⎢⎢⎢

10005.05.0005.005.005.0005.0

Page 32: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

32The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Result

False self-shadowing

Image courtesy of Tomas Akenine-Möller

Page 33: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

33The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Solution - Bias

Offset the depth values by using glPolygonOffset().

– Constant – Slope dependent

Page 34: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

34The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Correct bias is non-trivial

Too much bias – floating shadow

Image courtesy of Tomas Akenine-Möller

Page 35: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

35The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Aliasing

Light pointing toward viewer

Blocky artifacts

Well-defined edge

Image courtesy of NVIDIA

Page 36: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

36The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Percentage Closer Filtering

• Average binary results of all depth map pixels covered

• Soft anti-aliased shadows

Page 37: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

37The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Poor sample distribution

Images courtesy of Stamminger and Drettakis 02

Page 38: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

38The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Solution: Warp depth image

Images courtesy of Stamminger and Drettakis 02

Page 39: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

39The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

How to warp?

Stamminger and Drettakis 02 Martin and Tan 04

Chong and Gortler 04Wimmer et al. 04

Page 40: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

40The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Outline

• Introduction• Planar Shadows• Shadow Volumes• Shadow Maps• Soft Shadows

– Overview– Sampling methods– Heuristic methods– Physically-based methods

Page 41: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

41The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Overview

Page 42: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

42The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Overview

Umbra Penumbra

• Point lights are either visible or not

• Area lights can be partially visible

Intensity

Page 43: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

43The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Page 44: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

44The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Sampling methods

4 samples 1024 samples

Page 45: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

45The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Sampling methods

• Advantages:– Converges to correct solution– Can use existing techniques (shadow

maps and shadow volumes)

• Disadvantages:– SLOW! Takes many samples to converge

Page 46: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

46The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Heuristic methods

• Advantages:– Capture qualitative

appearance– Can be very fast

• Disadvantages:– Never will converge

to correct solution

Page 47: Overview of Shadow Rendering · – Render into texture • Restricted to planar objects. 11 The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline • Introduction • Shadow Volumes

47The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Heuristic methods

shadow mapumbra region

light

d1blocker

d2