cs 354 shadows

100
CS 354 Shadows Mark Kilgard University of Texas March 20, 2012

Upload: mark-kilgard

Post on 07-Sep-2014

28 views

Category:

Technology


6 download

DESCRIPTION

CS 354 Shadow Generation; University of Texas at Austin; March 20, 2012

TRANSCRIPT

Page 1: CS 354 Shadows

CS 354Shadows

Mark KilgardUniversity of TexasMarch 20, 2012

Page 2: CS 354 Shadows

CS 354 2

Today’s material

In-class quiz On GPU architecture lecture

Lecture topic Shadow Algorithms

Course status Mid-term graded, but not yet recorded Project #2 on texturing, shading, & lighting is

coming

Page 3: CS 354 Shadows

CS 354 3

My Office Hours Tuesday, before class

Painter (PAI) 5.35 8:45 a.m. to 9:15

Thursday, after class ACE 6.302 11:00 a.m. to 12

Randy’s office hours Monday & Wednesday 11 a.m. to 12:00 Painter (PAI) 5.33

Page 4: CS 354 Shadows

CS 354 4

Last time, this time

Last lecture, we Took the mid-term

This lecture Shadow generation algorithms How can we efficiently determine when and

how much light is occluded by other objects during shading?

Page 5: CS 354 Shadows

CS 354 5

Daily Quiz1. Multiple choice: The effective

memory bandwidth of a graphics processor can be higher than its raw memory bandwidth due to:

a) more multiply-add operations per clock

b) not showing pixels when they are opaque

c) domain-specific compression techniques

d) off-loading work to the network

2. Multiple choice: Programmable tessellation is good for

a) displacement mapping

b) per-pixel lighting

c) increasing the appearance of surface curvature

d) feeding more triangles to the graphics pipeline

e) a, c, and d

f) a, b, c, and d

g) b, c, and d

On a sheet of paper• Write your EID, name, and date• Write #1, #2 followed by its answer

Page 6: CS 354 Shadows

CS 354 6

Shadows

Important visual cue All real world scenes have shadows

Lack of shadows = big clue that an image is computer generated!

Occlusion from light’s point-of-view instead of viewer’s

Cue for light-object-object relationships Artistic effect

Soft vs. hard feel, dramatic or spooky feel

Page 7: CS 354 Shadows

CS 354 7

Shadows ProvideCues About Depth

Two scenes Difference is in shadows

Balls resting on ground Balls floating off surface

Page 8: CS 354 Shadows

CS 354 8

Computed Shadows aren’t Necessarily Realistic

Shadows of Past – Lyubomir Bukov

Page 9: CS 354 Shadows

CS 354 9

Shadows in GamingShading + Shadows = More Drama

OnlyDiffuse + Decal

+ Shadows

+ Bump mapping+ Specular

Shadows + Shading Combined

Page 10: CS 354 Shadows

CS 354 10

Ray TracingApproach to Shadows

Shadows = global lighting effect Involves more than light + surface

Page 11: CS 354 Shadows

CS 354 11

Ray Tracing Shadow Algorithm

Cast primary rays from eye Determine surface intersection Then, cast a secondary (shadow) ray

From surface To each light source

Page 12: CS 354 Shadows

CS 354 12

InteractiveLighting Models

Typically lack shadow support So-called “local” lighting models ignore

occlusion of light sources that create shadows Except trivial self-shadowing (i.e., clamping LN)

Global lighting models account for shadows Examples: radiosity, ray tracing But too expensive for interactive use

Interactive shadow algorithms typically operate independent of local lighting models

Page 13: CS 354 Shadows

CS 354 13

Interactive ShadowSimplications

True shadows are expensive, cut corners Simple geometry tricks

Projection Volume intersection

Pre-compute static shadow results where possible

Make simplifying assumptions Treat area light sources as points

Exploit hardware features such as stencil and depth textures

Page 14: CS 354 Shadows

CS 354 14

Interactive ShadowRendering Techniques

Different approaches, different tradeoffs Shadow maps Planar projected shadows Stenciled shadow volumes Pre-computed shadow textures (light maps)

Page 15: CS 354 Shadows

CS 354 15

Common Real-timeShadow Techniques

Shadowvolumesvolumes

Light maps

Projectedplanarshadows

Hybridapproaches

Page 16: CS 354 Shadows

CS 354 16

Projective TexturingShadow Maps Visualized

Without Shadows With ShadowsProjected Shadow Map

Light’s View Light’s View Depth

Page 17: CS 354 Shadows

CS 354 17

Shadow Mapping Image-space shadow determination

Lance Williams published the basic idea in 1978 By coincidence, same year Jim Blinn invented bump mapping (a great

vintage year for graphics) Completely image-space algorithm

means no knowledge of scene’s geometry is required must deal with aliasing artifacts

Well known software rendering technique Pixar’s RenderMan uses the algorithm

Leverages GPU hardware Depth buffering + texture mapping Multi-pass algorithm: render depth maps, then project depth

maps as textures for eye view

Page 18: CS 354 Shadows

CS 354 18

Shadow MappingReferences

Important SIGGRAPH papers Lance Williams, “Casting Curved

Shadows on Curved Surfaces,”SIGGRAPH 78

William Reeves, David Salesin, and Robert Cook (Pixar), “Rendering antialiased shadows with depth maps,” SIGGRAPH 87

Mark Segal, et. al. (SGI), “Fast Shadows and Lighting Effects Using Texture Mapping,” SIGGRAPH 92

OpenGL extensions ARB_shadow, ARB_depth_texture Standardized in OpenGL 1.4 (2002)

Page 19: CS 354 Shadows

CS 354 19

Shadow Map Example Pixar’s Luxo Jr. – state-of-the-art for 1986 Running in real-time – GeForce3 in Japan, 2001

3 light sources = 3 depth map renders per frame

Page 20: CS 354 Shadows

CS 354 20

Shadow Maps for Fine Shadows

Chain-link fence’s shadow appears on truck & ground with shadow maps

Chain-link fence is shadow volume nightmare!

Page 21: CS 354 Shadows

CS 354 21

The Shadow MappingConcept (1)

Depth testing from the light’s point-of-view Two pass algorithm First, render depth buffer from the light’s

point-of-view the result is a “depth map” or “shadow map” essentially a 2D function indicating the depth of

the closest pixels to the light This depth map is used in the second pass

Page 22: CS 354 Shadows

CS 354 22

The Shadow MappingConcept (2)

Shadow determination with the depth map Second, render scene from the eye’s point-of-

view For each rasterized fragment

determine fragment’s XYZ position relative to the light

this light position should be setup to match the frustum used to create the depth map

compare the depth value at light position XY in the depth map to fragment’s light position Z

Page 23: CS 354 Shadows

CS 354 23

The Shadow MappingConcept (3)

The Shadow Map Comparison Two values

A = Z value from depth map at fragment’s light XY position

B = Z value of fragment’s XYZ light position If B is greater than A, then there must be

something closer to the light than the fragment then the fragment is shadowed

If A and B are approximately equal, the fragment is lit

Page 24: CS 354 Shadows

CS 354 24

Shadow Mappingwith a picture in 2D

lightsource

eyeposition

depth map Z = A

fragment’slight Z = B

depth map image plane

eye view image plane,aka the frame buffer

The A < B shadowed fragment case

Page 25: CS 354 Shadows

CS 354 25

Shadow Mappingwith a picture in 2D

lightsource

eyeposition

depth map Z = A

fragment’slight Z = B

depth map image plane

eye view image plane,aka the frame buffer

The A B unshadowed fragment case

Page 26: CS 354 Shadows

CS 354 26

Shadow Mappingwith a picture in 2D

Note image precision mismatch!

The depth mapThe depth mapcould be at acould be at adifferent resolutiondifferent resolutionfrom the framebufferfrom the framebuffer

This mismatch canThis mismatch canlead to artifactslead to artifacts

Page 27: CS 354 Shadows

CS 354 27

Avoiding Artifacts withDepth Map Bias

OpenGL supports glPolygonOffset that provides window-space depth bias Used during shadow map construction

How much polygon offset bias depends

Too little bias,Too little bias,everything begins toeverything begins toshadowshadow

Too much bias, shadowToo much bias, shadowstarts too far backstarts too far back

Just rightJust right

Page 28: CS 354 Shadows

CS 354 28

Visualizing the ShadowMapping Technique (1)

A fairly complex scene with shadows

the pointlight source

Page 29: CS 354 Shadows

CS 354 29

Visualizing the ShadowMapping Technique (2)

Compare with and without shadows

with shadows without shadows

Page 30: CS 354 Shadows

CS 354 30

Visualizing the ShadowMapping Technique (3)

The scene from the light’s point-of-view

FYI: from theeye’s point-of-viewagain

Page 31: CS 354 Shadows

CS 354 31

Visualizing the ShadowMapping Technique (4)

The depth buffer from the light’s point-of-view

FYI: from thelight’s point-of-viewagain

Page 32: CS 354 Shadows

CS 354 32

Visualizing the ShadowMapping Technique (5)

Projecting the depth map onto the eye’s view

FYI: depth map forlight’s point-of-viewagain

Page 33: CS 354 Shadows

CS 354 33

Shadow Map Eye LinearTexture Coordinate Transform

1/21/2

1/21/2

1/21/2

11

1/21/2

1/21/2

1/21/2LightLight

frustumfrustum(projection)(projection)

matrixmatrix

LightLightviewview

(look at)(look at)matrixmatrix

InverseInverseeyeeyeviewview

(look at)(look at)matrixmatrix

EyeEyeviewview

(look at)(look at)matrixmatrix

ModelingModelingmatrixmatrix

xxoo

yyoo

zzoo

wwoo

xxee

yyee

zzee

wwee

==

==xxee

yyee

zzee

wwee

ssttrrqq

glTexGen automatically applies this when modelview matrix contains just the eye

view transform

Supply this combined transform to glTexGen or shader

Page 34: CS 354 Shadows

CS 354 34

Projective Texturing Mimic perspective divide but for texture

(s,t,r,q) → (s/q,t/q,r/q) Light’s view frustum needs perspective

An intuition for projective texturing The slide projector analogy

Source: Wolfgang Heidrich [99]Source: Wolfgang Heidrich [99]

Page 35: CS 354 Shadows

CS 354 35

Visualizing the ShadowMapping Technique (5)

Projecting the depth map onto the eye’s view

FYI: depth map forlight’s point-of-viewagain

Page 36: CS 354 Shadows

CS 354 36

Visualizing the ShadowMapping Technique (6)

Projecting light’s planar distance onto eye’s view Essentially r/q in the [0,1] range

Analogous to window-space depth for depth buffering

Page 37: CS 354 Shadows

CS 354 37

Visualizing the ShadowMapping Technique (7)

Comparing light distance to light depth map

Green is where the light planar

distance and the light depth

map are approximately

equal

Non-green is where shadows should be

Page 38: CS 354 Shadows

CS 354 38

Visualizing the ShadowMapping Technique (8)

Scene with shadows

Notice how specular

highlights never appear

in shadows

Notice how curved surfaces cast shadows on each other

Page 39: CS 354 Shadows

CS 354 39

More Examples Smooth surfaces with object self-

shadowing

Note object self-shadowing

Page 40: CS 354 Shadows

CS 354 40

More Examples

Complex objects all shadow

Page 41: CS 354 Shadows

CS 354 41

Shadow Mapping Artifacts

Even the floor casts shadow, but…

Note shadow leakage due toinfinitely thin floor

Could be fixed bygiving floor thickness

Page 42: CS 354 Shadows

CS 354 42

Shadow Map Precision Artifacts

Resolution of rendered depth map determines shadow mapping precision

sufficientshadow map resolution

low-resolutionshadow map blockiness

Page 43: CS 354 Shadows

CS 354 43

Four Images ofDueling Frusta Case

Eye’sView

Light’sView

Eye’s View with projectionof color-codedmipmap levelsfrom light:Red = minificationBlue = magnification

Light’s View withre-projectionof above imagefrom the eye

Page 44: CS 354 Shadows

CS 354 44

Interpretation of the Imagesof the Dueling Frusta Case

Eye’sView

Light’sView

Region that is smallest in the light’s view is a region that is very large in the eye’s view. This implies that it would require a very high-resolution shadow map to avoid obvious blocky shadow edge artifacts.

Page 45: CS 354 Shadows

CS 354 45

Dueling Frusta Blocky Shadow Edge Artifacts

Light position out here pointing towards the viewer.

Blocky shadow edge artifacts.

Notice that shadow edge is well defined in the distance.

Page 46: CS 354 Shadows

CS 354 46

Shadow Acne Ambiguous shadow map comparisons cause very

unsightly artifacts Moiré patterns form; animates poorly

polygon offsetprovides sufficient depth offset

for unambiguous depthcomparisons

“shadow acne”depth comparison is

ambiguous

Page 47: CS 354 Shadows

CS 354 47

Planar ProjectedShadows

So-called “fake” shadows Uses projective geometry trick Flattens 3D model into ground plane Shadow effect only can be applied to planes Supports either positional or directional lights

Page 48: CS 354 Shadows

CS 354 48

Projected Planar ShadowExample

Page 49: CS 354 Shadows

CS 354 49

Projected PlanarShadows

Classic computer graphics trick Given

Ground plane equation, Ax + By + Cz + D = 0 Light position (x, y, z, w)

Construct projective transform that “squishes” vertices into ground plane based on light position

Concatenate this with view transform Rendering 3D object creates shadow-like pile

of polygons in ground plane

Page 50: CS 354 Shadows

CS 354 50

Projected PlanarShadow Matrix

4x4 Projective Matrix

P - Lx A -Ly A -Lz A -Lw A -Lx B P - Ly B -Lz B -Lw B -Lx C -Ly C P - Lz C -Lw C -Lx D -Ly D -Lz D P - Lw D

where P = Lx A + Ly B + Lz C + Lw D

Page 51: CS 354 Shadows

CS 354 51

Careful about Reverse Projection

Projection can cast a shadow of an object “behind” the light w.r.t. the plane Make sure occluders are between light and ground plane

Good Bad, reverse projection

Page 52: CS 354 Shadows

CS 354 52

Projected PlanarShadow Issues Shadow must be cast on infinite planes

Stencil can limit shadow to finite planar region “Pile of polygons” creates Z-fighting artifacts

Polygon offset fixes this, but disturbs Z values Stencil testing is better solution

Difficult to blend shadow with ground texture Just blending creates “double blends” But stencil testing can eliminate “double blends” Specular highlights can show in shadow

Page 53: CS 354 Shadows

CS 354 53

Planar ProjectedShadow Artifacts

Bad Good

extends offground region

Z fighting double blending

Page 54: CS 354 Shadows

CS 354 54

Quick Tutorial onStencil Testing

An extra test for fine-grain pixel control Standard OpenGL and Direct3D feature Per-pixel test similar to depth buffering

Tests fragment against pixel’s stencil value, rejects fragments that fail

Also, can modify pixel’s stencil buffer value based on stencil/depth test results

Hardware accelerates stencil testing Typically allocated with depth buffer

8-bit stencil value paired with 24-bit depth value

Invented by Kurt Akeley and Jim Foran (SGI)

Page 55: CS 354 Shadows

CS 354 55

Stencil Testing in theFragment Pipeline

PixelOwnership

Test

StencilTest

DepthTest

Blending Dithering Logic Op

ScissorTest

AlphaTest

Frame buffer

Fragment+

AssociatedData

Page 56: CS 354 Shadows

CS 354 56

Stencil Testing

Similar to Depth Testing but Compares current reference value to pixel’s

stencil buffer value Same comparison functions as depth test:

NEVER, ALWAYS LESS, LEQUAL GREATER, GEQUAL EQUAL, NOTEQUAL

Stencil bit mask controls comparison (( ref & mask ) op ( svalue & mask )

Page 57: CS 354 Shadows

CS 354 57

Stencil Operations

Way stencil buffer values are controlled Stencil side effects of

Stencil test fails Depth test fails Depth test passes

Possible operations Increment, Decrement (saturates) Increment Wrap, Decrement Wrap (a.k.a. modulo) Keep, Replace, Zero, Invert

Page 58: CS 354 Shadows

CS 354 58

OpenGL API Stencil function

Controls when stencil test passes or fails glStencilFunc(GLenum stencil_function,

GLint reference_value, GLuint read_mask)

Stencil operations Controls how the stencil buffer is updated glStencilOp(GLenum stencil_fail,

GLenum depth_fail, GLenum depth_pass)

Stencil mask Controls bit-mask for writing stencil glStencilMask(GLuint write_mask)

Also two-sided stencil API Provides different stencil operations for front- and back-facing polygons glStencilFuncSeparate, glStencilOpSeparate, glStencilMaskSeparate

Page 59: CS 354 Shadows

CS 354 59

The Shadow VolumeConcept

Volumetric shadows, not just planar A single point light source splits the world in two

shadowed regions unshadowed regions

A shadow volume is the boundary between these shadowed and unshadowed regions

First described by [Crow 77] Professor at University of Texas!

Discrete framebuffer support Shadow count in the framebuffer from Fournier and

Dr. Fussell (1988) Translates natrually to the stencil buffer…

Page 60: CS 354 Shadows

CS 354 60

VisualizingShadow Volumes

Occluder and light projects a shadow volume

Page 61: CS 354 Shadows

CS 354 61

Shadow VolumeResult

Objects within the volume are shadowed

Page 62: CS 354 Shadows

CS 354 62

Shadow VolumeAlgorithm

High-level view of the algorithm Given the scene and a light source position,

determine the shadow volume (harder than it sounds)

Render the scene in two passes Draw scene with the light enabled,

updating only fragments in unshadowed region Draw scene with the light disabled,

updated only fragments in shadowed region But how to control update of regions?

Page 63: CS 354 Shadows

CS 354 63

2D Cutaway of aShadow Volume

shadowingobject

shadowvolume(infinite extent)

partiallyshadowed object

lightsource

eyeposition surface inside

shadow volume(shadowed)

surface outsideshadow volume(illuminated)

Page 64: CS 354 Shadows

CS 354 64

Tagging Pixels asShadowed or Unshadowed

Using stencil testing High-level algorithm does not say how to update

only either pixels in or out of the shadow volume! The stenciling approach

Clear stencil buffer to zero and depth buffer to 1.0 Render scene to leave depth buffer with closest Zs Render shadow volume into frame buffer with depth

testing but without updating color and depth, but inverting a stencil bit

This leaves stencil bit set within shadow!

Page 65: CS 354 Shadows

CS 354 65

Stencil Inverting ofShadow Volume

Why it works

eyeposition

lightsource

shadowingobject

two inverts, left zero

one invert, left one

zero inverts, left zero

Page 66: CS 354 Shadows

CS 354 66

Visualizing StenciledShadow Volume Tagging

Shadowed scene Stencil buffer

red = stencil value of 1green = stencil value of 0

Page 67: CS 354 Shadows

CS 354 67

ComputingShadow Volumes

Harder than you might think Easy for a single triangle, just project out three

infinite polygons from the triangle, opposite the light position

But shadow volume polygons should not intersect each other for invert trick to work

This makes things hard For complex objects, projecting object’s 2D

silhouette is a good approximation (flat objects are easy)

Static shadow volumes can be pre-compiled

Page 68: CS 354 Shadows

CS 354 68

For Shadow VolumesWith Intersecting Polygons

Use a stencil enter/leave counting approach Draw shadow volume twice using face culling

1st pass: render front faces and increment when depth test passes

2nd pass: render back faces and decrement when depth test passes

This two-pass way is more expensive than invert And burns more fill rate drawing shadow

volumes Inverting is better if no polygon intersections

Page 69: CS 354 Shadows

CS 354 69

Why Eye-to-Object Stencil Counting Approach Works

Shadowing object Lightsource

Eyeposition

zero

zero

+1

+1+2 +2

+3

Example in 2D

Page 70: CS 354 Shadows

CS 354 70

Illuminated,Behind Shadow Volumes (Zpass)

Shadowing object Lightsource

Eyeposition

zero

zero

+1

+1+2 +2

+3

Unshadowedobject

+ ---+ +

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

Page 71: CS 354 Shadows

CS 354 71

Shadowed, Nested in Shadow Volumes (Zpass)

Shadowing object Lightsource

Eyeposition

zero

zero

+1

+1+2 +2

+3

Shadowedobject

+ -+ +

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

Page 72: CS 354 Shadows

CS 354 72

Illuminated, In Front of Shadow Volumes (Zpass)

Shadowing object Lightsource

Eyeposition

zero

zero

+1

+1+2 +2

+3

Shadowedobject

Shadow Volume Count = 0 (no depth tests pass)

Page 73: CS 354 Shadows

CS 354 73

Shadow VolumeIssues

Practical considerations [Bergeron 86] If eye is in shadow volume, need to determine

this and flip enabled & disabled lighting passes Shadow volume only as good as its tessellation

Shadows tend to magnify limited tessellation of curved surfaces

Open models and non-planar polygons Must cap the shadow volume’s intersection with

the near clipping plane

Page 74: CS 354 Shadows

CS 354 74

Problem Created byNear Clip Plane (Zpass)

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 75: CS 354 Shadows

CS 354 75

Render scene to initialize depth buffer Depth values indicate the closest visible fragments

Use a stencil enter/leave counting approach Draw shadow volume twice using face culling

1st pass: render back faces and increment when depth test fails 2nd pass: render front faces and decrement when depth test fails

Don’t update depth or color Afterward, pixel’s stencil is non-zero if pixel in

shadow, and zero if illuminated

Alternative Approach: Zfail

Page 76: CS 354 Shadows

CS 354 76

Illuminated,Behind Shadow Volumes (Zfail)

Shadowing object Lightsource

Eyeposition

zero

zero

+1

+1+2 +2

+3

Unshadowedobject

Shadow Volume Count = 0 (zero depth tests fail)

Page 77: CS 354 Shadows

CS 354 77

Shadowed, Nested inShadow Volumes (Zfail)

Shadowing objectLightsource

Eyeposition

zero

zero

+1

+1+2 +2

+3

Shadow Volume Count = +1+1 = 2

+ +

Shadowedobject

Page 78: CS 354 Shadows

CS 354 78

Illuminated, In Front of Shadow Volumes (Zfail)

Shadowing object Lightsource

Eyeposition

zero

zero

+1

+1+2 +2

+3

Shadowedobject

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

- +- - + +

Page 79: CS 354 Shadows

CS 354 79

Problem Created byFar Clip Plane (Zfail)

zero

Near clipplane

Far clipplane

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

+1

+1 +2+2+3

zero

Page 80: CS 354 Shadows

CS 354 80

Problem Solved byEliminating Far Clip

zero

+1

+1 +2+2+3

Near clipplane

Page 81: CS 354 Shadows

CS 354 81

Avoiding Far Plane Clipping

Usual practice for perspective GL projection matrix Use glFrustum (or gluPerspective) Requires two values for near & far clip planes

Near plane’s distance from the eye Far plane’s distance from the eye

Assumes a finite far plane distance Alternative projection matrix

Still requires near plane’s distance from the eye But assume far plane is at infinity

What is the limit of the projection matrix whenthe far plane distance goes to infinity?

Page 82: CS 354 Shadows

CS 354 82

Standard glFrustum Projection Matrix

Only third row depends on Far and Near

0100

200

02

0

002

NearFarNearFar

NearFarNearFar

BottomTopBottomTop

BottomTopNear

LeftRightLeftRight

LeftRightNear

P

Page 83: CS 354 Shadows

CS 354 83

Limit of glFrustum Matrix asFar Plane is Moved to Infinity

First, second, and fourth rows are the same as in P But third row no longer depends on Far

Effectively, Far equals ∞

01002100

020

002

lim

NearBottomTopBottomTop

BottomTopNear

LeftRightLeftRight

LeftRightNear

Far infPP

Page 84: CS 354 Shadows

CS 354 84

Verifying Pinf Will Not ClipInfinitely Far Away Vertices (1)

What is the most distant possible vertex in front of the eye? Ok to use homogeneous coordinates OpenGL convention looks down the negative Z axis So most distant vertex is (0,0,-D,0) where D>0

Transform (0,0,-D,0) to window space Is such a vertex clipped by Pinf? No, it is not clipped, as explained on the next slide

Page 85: CS 354 Shadows

CS 354 85

Verifying Pinf Will Not ClipInfinitely Far Away Vertices (2)

Transform eye-space (0,0,-D,0) to clip-space

0

00

01002100

020

002

DNear

BottomTopBottomTop

BottomTopNear

LeftRightLeftRight

LeftRightNear

wzyx

DDyx

c

c

c

c

c

c

15.05.05.05.0

DD

wzzc

cw

Then, assuming glDepthRange(0,1), transform clip-space position to window-space position

So ∞ in front of eye transforms to the maximum window-space Z value, but is still within the valid depth range (i.e., not clipped)

Page 86: CS 354 Shadows

CS 354 86

Robust Shadow Volumes sans Near (or Far) Plane Capping

Use Zfail Stenciling Approach Must render geometry to close shadow volume extrusion on the

model and at infinity (explained later)

Use the Pinf Projection Matrix No worries about far plane clipping Losses some depth buffer precision (but not much)

Draw the infinite vertices of the shadow volume using homogeneous coordinates (w=0)

Page 87: CS 354 Shadows

CS 354 87

Visualize Net Stencil Rendering

Non-zero stencil state marks shadowed pixels w.r.t. the light source

Fully shaded scene Final stencil state

Page 88: CS 354 Shadows

CS 354 88

Stencil VolumeRendering Animation

Page 89: CS 354 Shadows

CS 354 89

Shadow Volumes Add “Invisible” Geometric Complexity

Visible geometry

Shadow volume geometry

Scene with multiple light sources

Abducted game images courtesyJoe Riedel at Contraband Entertainment

Page 90: CS 354 Shadows

CS 354 90

Examples of Possible Silhouette Edges for Quake2 Models

An object viewed from the same basic direction that the light is shining on the object has an identifiable light-view silhouette

An object’s light-view silhouette appears quite jumbled when viewed form a point-of-view that does not correspond well with the light’s point-of-view

Page 91: CS 354 Shadows

CS 354 91

Multiple Lights andShadow Volumes

Requires still more rendering passes,but can work!

Shadows from differentlight sources overlapcorrectly

Page 92: CS 354 Shadows

CS 354 92

Shadow Volumes fromArea Light Sources

Make soft shadows Shadow volumes work for point light sources Area light sources are common and make

soft shadows Model an area light source as a collection of

point light sources [Brotman & Badler 84] Use accumulation buffer or additive blending

to accumulate soft shadow Linear cost per shadow volume sample

Page 93: CS 354 Shadows

CS 354 93

Area Light Sources Cast Soft Shadows

umbra

area lightsource

Page 94: CS 354 Shadows

CS 354 94

Soft Shadow Example

Eight samples (more would be better)

Note the bandingartifacts

Page 95: CS 354 Shadows

CS 354 95

CombinedShadow Approaches

Two Approaches at Oncejust logo shadow volume

combinedapproach

just planar projectedshadowsteapot lacks

shadowon the floor

logo lacks shadowon the teapot

Page 96: CS 354 Shadows

CS 354 96

Pre-computedShadow Textures

Lightmaps are static shadow textures Compute lightmaps off-line with radiosity solver

local lighting models evaluated on tight grid can work well too

Lightmaps with soft shadows can be built faster with convolution approach, accelerated using the Fast Fourier Transform [Soler & Silion 98]

Pre-computed shadow textures work well for building interior with lots of diffuse surfaces

Page 97: CS 354 Shadows

CS 354 97

Light maps can encodeStatic Pre-computed Shadows

(modulate)

=

light maps onlylight maps only

decal onlydecal only

combined scenecombined scene* Id Software’s Quake 2

circa 1997

Page 98: CS 354 Shadows

CS 354 98

RenderingSoft Shadow Textures

Fast soft shadows [Heckbert & Herf 96] Render a shadow texture

For each shadowed polygon, project all light-source-occluding polygons into the shadowed polygon’s plane

* Similar to projected planar shadows* Model area light sources as multiple jittered points* Use additive blending to accumulate all contributions

Copy resulting image to the shadow texture Draw polygon in final scene with shadow texture

Page 99: CS 354 Shadows

CS 354 99

RenderedSoft Shadow Texture Example

Shadow Texture and Final Result

Shadow texture, accumulationof nine jittered occluderprojections

Final resulting scene, shadowtexture modulated withwooden floor

Page 100: CS 354 Shadows

CS 354 100

Next Class Mid-term

Return graded mid-term Review class statistics

Project 2 assigned On texturing, shading, & lighting Study GLSL

Next lecture Scene graphs How do applications organize data structures for

efficient rendering of scenes?