77
1 Shadows © Jeff Parker, 2011 "What is written without effort is in general read without pleasure.” -- Samuel Johnson

1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Embed Size (px)

Citation preview

Page 1: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

1

Shadows

© Jeff Parker, 2011

"What is written without effort is in general read without pleasure.”

-- Samuel Johnson

Page 2: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

2

Outline

Fill out your course evaluations!

Look at a vexing problem: How to deal with shadows

We will see a variety of topics that provide a good review of course topics

Hidden Surface Removal

Clipping

Counting Crossings – in or out?

zBuffer

Transformations

Aliasing

We'll look at several shadow algorithms in some detail

Images from a number of sources, including SIGGRAPH courses by Björn Kühl and by Mark Kilgard of Nvidia

Page 3: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

3

Why do we need shadows?

Why do we need shadows?

Page 4: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

4

Shadows

Shadows help to create atmosphere

Page 5: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadows provide clues

Clues to the position of objects casting and receiving shadows

Clues to the position of the light sources

Page 6: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadows provide clues

Clues about the shape of casting objects

Clues about the shape of receiving objects

Page 7: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadows make images realistic

Page 8: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadows make images realistic

Page 9: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

9

Ground Plane Shadows

Described by Blinn in “Me and My (Fake) Shadow” 1988. Given light position and ground plane, project all objects in

scene onto ground plane.

The shadow is a pile of polygons on the ground plane.

Polygons are co-planar, so pile has no height.

The trick is to construct the projection matrix, then concatenate the matrix with the model-view matrix.

Then the shadow is rasterized into the ground plane by re-rendering the object.

Page 10: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

10

Directional Shadow

We project a point P onto the plan x = 0 to get it's shadow, S

The light is directional (infinite) in direction L

Where do we hit y = 0?

S = P −αL

yS = yP −αyL

yS = 0 = yP −αyL

αyL = yP

α =yP

yL

Page 11: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

11

Directional Shadow

Use this to compute where (x, y, z) ends up

S = P −αL

α =yP

yL

S = P −yP

yL

L

xS = xP −yP

yL

xL

zS = zP −yP

yL

zL

Page 12: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

12

Directional Shadow

We can write this as a matrix operation

S = P −αL

xS = xP −yP

yL

xL

zS = zP −yP

yL

zL

1 −xL

yL

0 0

0 0 0 0

0 −zL

yL

1 0

0 0 0 1

⎢ ⎢ ⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥ ⎥ ⎥

x

y

z

1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

=

x −y

yL

xL

0

z −y

yL

zL

1

⎢ ⎢ ⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥ ⎥ ⎥

Page 13: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

13

Point Source Shadow

How does a point source differ from directional source?

Imagine the light in the second picture is on a lamp post

Page 14: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

14

Point Source Shadow

How does a point source differ from directional source?

Page 15: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

15

Point Source Shadow

We project a point P onto the plan x = 0 to get it's shadow, S

The light is directional is from a point source at L

S = P −α (P − L)

yS = yP −α (yP − yL )

yS = 0 = yP −α (yP − yL )

α (yP − yL ) = yP

α =yP

(yP − yL )

Page 16: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

16

Point Source ShadowUse this to compute where (x, y, z) ends up

We show how to compute x: z is similar

S = P −α (P − L)

α =yP

(yP − yL )

S = P −yP

(yP − yL )(P − L)

xS = xP −yP

(yP − yL )(xP − xL )

xS =xP (yP − yL )

(yP − yL )−

yP (xP − xL )

(yP − yL )

xS =xP yP − xP yL − yP xP + yP xL

(yP − yL )

xS =yP xL − xP yL

(yP − yL )

Page 17: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

17

Point Source Shadow

We can write this as a matrix operation using perspective geometry

xS =yP xL − xP yL

(yP − yL )

zS =yPzL − zP yL

(yP − yL )

−yL xL 0 0

0 0 0 0

0 zL −yL 0

0 1 0 −yL

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

xP

yP

zP

1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

=

yP xL − xP yL

0

yPzL − zP yL

yP − yL

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

Page 18: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

18

Point Source Shadow

Since yP < yL in most cases, yP-yL is negative

Rather than divide by negative, multiply through by -1

yL −xL 0 0

0 0 0 0

0 −zL yL 0

0 −1 0 yL

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

xP

yP

zP

1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

=

xP yL − yP xL

0

zP yL − yPzL

yL − yP

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

Page 19: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

19

Limitations

This only works when projecting onto planes

Assumes an infinite plane

Gives hard edged shadows

Textured surfaces are hard to deal with

To get a good match with texture floor that is not in shadow, we want to blend

If we blend, we blend once for each polygon.

But multiple polygons may overlap

See figure

Deals best with isolated objects

Does not cast shadows on other objects

Page 20: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

20

Improved algorithm

Use stencil buffer to make limits of plane and limits of shadow

Assign a unique non-zero stencil value to the pixels belonging to the ground plane. Then draw the ground plane polygons

This only works when projecting onto planes

Assumes an infinite plane

Gives hard edged shadows

Textured surfaces are hard to deal with

To match with texture floor, we want to blend

If we blend, we blend once for each polygon.

But multiple polygons may overlap

Deals best with isolated objects

Does not cast shadows on other objects

Page 21: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

21

Two Bit test

Blending is adequate for quick-and-dirty rendering, but you may be able to have more realistic rendering with a separate pass.

When selecting an otherwise unused stencil value v for tagging the planar surface’s shadow, also ensure that v+1 is also otherwise unused.

When rendering the projected shadow, instead of blending with the pixels on the planar surface, increment the pixel’s stencil value and do not update the color buffer.

Then re-render the planar surface again with lighting enabled but the blocked light source disabled and use stenciling to replace only pixel’s with the the value v+1.

Page 22: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

22

Evaluation

Can handle multiple light sources:

need unique v, v+1 for each

Still assumes ground is a plane

Still creates hard shadows

Deals best with isolated objects

Does not cast shadows on other objects

Page 23: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Miner's headlamp

What does a miner see?

Page 24: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Appel and Bouknight & Kelly

Alexander, upon meeting Diogenes, asked if there was any favor he might do for him. Diogenes replied: "Yes, stand out of my sunlight"

Create data structure telling us which polygons occlude othersProject objects onto sphere centered at light sourceFor each object, keep track of any other objects between it and the light

Diogenes - Alexander The Great

Page 25: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Appel and Bouknight & Kelly

Perform normal scan-line conversion on polygon PLook at occluding object S

If S does not cover the scan line, drawIf S covers all the scan line, draw with darker shadeIs S covers part of the scan line, split scan line in two and recurse

Page 26: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Appel and Bouknight & Kelly

EvaluationNeed to build data structureAssumes we can quickly decide if all of a scan line is hidden – assumed polygons

Page 27: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Atherton, Weiler & Greenberg

Adapt hidden surface removal to generate shadowsBuild the image from the light's point of view

Sort from back to frontBuild list of visible polygons: subdivide and clip

Split a polygon into parts: Lit and UnlitKeep lists of lit and unlit polygons

Merge lit set with rest of polygonsWhen drawing, those in unlit set are in shadow

Page 28: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Atherton, Weiler & Greenberg

Image from Allan Watt, 3D Computer Graphics

Page 29: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Atherton, Weiler & GreenbergEvaluation:Works in Object Space

Marks polygons as in light or shadowOnce we cast the shadows, can view from any pointCan handle multiple lights: repeat the algorithmTo do clipping right is hard work

Page 30: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow VolumesCrow, Shadow algorithms for computer graphics, 1977

Compute regions of shadow in 3D

Object-space algorithm

Cast shadows onto arbitrary receiver geometry

From the School of Leonardo Da Vinci

Page 31: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow VolumesExtend occluder polygons to form semi-infinite volumes

Light source is center-of-projectionEverything behind occluder is in shadowTest if point is in at least one volumeExtend to reach outside of view frustum Light Source

Shadow Region

Occluder

Page 32: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Volumes

shadowingobject

shadowvolume(infinite extent)

partiallyshadowed object

lightsource

eyeposition surface inside

shadow volume(shadowed)

surface outsideshadow volume

(illuminated)

Page 33: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Volumes

Shadow volume generation

Trivial way: One volume for each polygon

Better: Silhouette-based approach

Goal: one shadow volume per connected component

Selected occluders only

Page 34: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow VolumesDetect silhouette edges

An edge is a silhouette edge if it is an edge shared by a front-facing and back-facing triangle/polygon

1n

2n

Light

1n

2n

Light

FF

BFFF FF

Silhouette Edge (v0,v1) ! No Silhouette Edge !

0V

1V

0V

1V

Page 35: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow VolumesShadow test: in-out counter

Counter == 0: litCounter >=0: shadowed

Page 36: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Use Stencil Buffer as Counter

Render scene in ambient color – in shade

Render front-facing parts of shadow volumes with stencil operation increment (enter)

Render back-facing parts of shadow volumes with stencil operation decrement (exit)

Render scene (fully lit) with stencil test equal zero

Page 37: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow VolumesImplementation

Generate volumes in software (object space)

Counting can be done in hardware (image space)

Images from Mark Kilgard’s shadow volume demo (NVIDIA).

Page 38: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Volumes

Counting problems

Viewer in shadow (correct counter initialization)

Correct ownership of adjacent polygons (no double hits)

OpenGL renderer should do this (specification)

Clipping of shadow volumes

Near clipping plane could cut-away parts of the shadow volume.

Need to cap shadow volumes !

Page 39: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Volumes

near plane

eye

light

volume be clipped !missing stencil increment near plane

eye

light

correct stencilin-out

Page 40: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Volume Summary

Shadow volumes in object precision

CPU intensive, requires polygon representation

Shadow test in image precision

Stencil buffer count

Hardware-accelerated

Many, large shadow polygons

Fill rate, geometry processing

Frustum clipping can destroy volumes

see Robust Stencil Shadow Volumes (NVIDIA 2002)

Page 41: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Mapping

Lance Williams, Casting Curved Shadows on Curved Surfaces, 1978

Fast technique: two passes over objects

Image-space based (we'll see what that means)

Very general: can deal well with arbitrary shapes

Has issues with Aliasing when light, eye are far apart

Widely used: Pixar's RenderMan

Page 42: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Map Concept

First pass: render depth buffer from the light’s point-of-view

"Paint" all visible pointsSecond pass: render from observer's viewpoint

If the pixel is not painted, it is in the shade

Problems: How do we "paint" a pixel? Pixels do not exist in object space – they are an artifact of screen space

Page 43: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Map Concept

Fast z-Buffer Depth testing from the light’s point-of-viewNeed to remember z-Buffer for each light source

First pass: render depth buffer from the light’s point-of-view

The resulting “depth map” is called the “shadow map”2D map indicating the distance of the closest pixels to light

Second pass: render from observer's viewpointUse the shadow map to decide which pixels are in shade

Map from one view to the other

Page 44: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Second PhaseFirst pass prepares shadow map from Light's point of view

In second phase, have (x, y, z) – is it in shadow map?

Page 45: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Second Phase

Second Pass renders scene from observer's point-of-view

For each rasterized fragment

We know the (x, y, z) position

Translate into Light's view, and extract depth

If the depth matches, point is light.

If it does not, point is in shade.

It is customary to use the term z – but note that the light's z may be the observer's x, or x+y-z.

Page 46: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Example

A fairly complex scene with shadows

the pointthe pointlight sourcelight source

Page 47: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Example

Compare with and without shadows

with shadowswith shadows without shadowswithout shadows

Page 48: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Example

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

from the eye’s from the eye’s

point-of-view againpoint-of-view again

Page 49: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Example

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

from the light'sfrom the light's

point-of-viewpoint-of-view

Page 50: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Example

Projecting the depth map onto the eye’s view

from the light'sfrom the light's

point-of-viewpoint-of-view

Page 51: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Example

Comparing light distance to light depth map

Green is where Green is where the light planar the light planar

distance and distance and the light depth the light depth

map are map are approximately approximately

equalequal

Non-green is Non-green is where where shadows shadows should beshould be

Page 52: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Example

Complete scene with shadows

Notice how Notice how specular specular

highlights highlights never appear never appear

in shadowsin shadows

Notice how Notice how curved curved surfaces cast surfaces cast shadows on shadows on each othereach other

Page 53: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Comparison

Two values

A = Z value from depth map at fragment’s light XY positionB = Z value of fragment seen from the eye

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 54: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Mapping

The A < B shadowed fragment case

lightsource

eyeposition

depth map Z = A

fragment’slight Z = B

depth map image plane

eye view image plane,a.k.a. the frame buffer

Page 55: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

The A == B shadowed fragment case

Shadow Mapping

lightsource

eyeposition

depth map Z = A

fragment’slight Z = B

depth map image plane

eye view image plane,a.k.a. the frame buffer

Page 56: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

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

Shadow Mappingwith a Picture in 2D (3)

Note image precision mismatch!Note image precision mismatch!Note image precision mismatch!Note image precision mismatch!

Page 57: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Construct Shadow Map

Realizing the theory in practice

Constructing the depth map

Use existing hardware depth buffer

Use glPolygonOffset to offset depth value back

Read back the depth buffer contents

Depth map can be copied to a 2D texture

Unfortunately, depth values tend to require more precision than 8-bit typical for textures

Depth precision typically 16-bit or 24-bit

Page 58: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Dual-texture ShadowMapping Precision

Conserving your 8-bit depth map precision

Frustum confined toFrustum confined toobjects of interestobjects of interest

Frustum expanded out considerablyFrustum expanded out considerablybreaks down the shadowsbreaks down the shadows

Page 59: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

More Precision AllowsLarger Lights Frustums

Compare 8-bit to 16-bit precision for large frustum

8-bit: Large frustum breaks down the 8-bit: Large frustum breaks down the shadows, not enough precisionshadows, not enough precision

16-bit: Shadow looks just fine16-bit: Shadow looks just fine

Page 60: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Why Extra PrecisionHelps

Where the precision is for previous images

Most significant 8 bits of the Most significant 8 bits of the depth map, pseudo-color inset depth map, pseudo-color inset magnifies variationsmagnifies variations

Least significant 8 bits of the depth Least significant 8 bits of the depth map, here is where the information map, here is where the information is!is!

Page 61: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Aliasing issues

Two types of problems

Jagged shadow edgesBlocky Pixels in second pass

Page 62: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Dueling Frusta Blocky Edges

Light position Light position out here out here pointing pointing towards the towards the viewer.viewer.Blocky Blocky shadow shadow edge edge artifacts.artifacts.

Notice that Notice that shadow shadow edge is well edge is well defined in defined in the the distance.distance.

Page 63: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Boundaries

Shadow map (depth buffer) has finite resolution

Many pixels could map to the same texel

Resolution mismatch

Can be arbitrarily bad using projection!

Page 64: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

ExampleLook at shadow/lit edge

Aliasing issue in initial pass

Page 65: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Sampling Issue

Depth buffer contains “window space” depth values

Post-perspective divide means non-linear distribution

glPolygonOffset is guaranteed to be a window space offsetDoing a “clip space” glTranslatef is not sufficient

Common shadow mapping implementation mistake

Actual bias in depth buffer units will vary over the frustum

No way to account for slope of polygon

Page 66: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Precision Mismatch

Depth buffer contains “window space” depth values

Post-perspective divide means non-linear distribution

glPolygonOffset is guaranteed to be a window space offsetDoing a “clip space” glTranslatef is not sufficient

Common shadow mapping implementation mistake

Actual bias in depth buffer units will vary over the frustum

No way to account for slope of polygon

Page 67: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Depth Map Bias

Differences in polygon offset bias

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 68: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

How to do this in practice?

Realizing the theory in practice

Fragment’s light position can be generated using eye-linear texture coordinate generation

OpenGL’s GL_EYE_LINEAR texgen generate homogenous (s, t, r, q) texture coordinates as light-space (x, y, z, w)

T&L engines such as GeForce accelerate texgen!

Relies on projective texturing

Page 69: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Mapping Issues

Prone to aliasing artifacts“percentage closer” filtering helps thisnormal color filtering does not work well

Depth bias is not completely foolproof

Requires extra shadow map rendering pass and texture loading

Higher resolution shadow map reduces blockinessbut also increase texture copying expense

Page 70: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Shadow Mapping Issues

Shadows are limited to view frustumscould use six view frustums for omni-directional light

Objects outside or crossing the near and far clip planes are not properly accounted for by shadowing

Move near plane in as close as possibleBut too close throws away valuable depth map precision when using a projective frustum

Page 71: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Four Images of Dueling Frusta Case

Eye’sEye’sViewView

Light’sLight’sViewView

Eye’s View with Eye’s View with projectionprojectionof color-codedof color-codedmipmap levelsmipmap levelsfrom light:from light:Red = minificationRed = minificationBlue = Blue = magnificationmagnification

Light’s View Light’s View withwithre-projectionre-projectionof above imageof above imagefrom the eyefrom the eye

Page 72: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Interpretation of the Imagesof the Dueling Frusta Case

Eye’sEye’sViewView

Light’sLight’sViewView

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

Page 73: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Good Situation, Close to the Miner’s Lamp

Eye’sEye’sViewView

Light’sLight’sViewView

Very Very similar similar viewsviews

Note how the Note how the color-coded color-coded images share images share similar pattern similar pattern and the coloration and the coloration is uniform. is uniform. Implies single Implies single depth map depth map resolution would resolution would work well for most work well for most of the scene.of the scene.

Ghosting is Ghosting is where where projection projection would be in would be in shadow.shadow.

Page 74: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

EvaluationShadow mapping offers real-time shadowing effects

Independent of scene complexity

Very compatible with multi-texturingDoes not mandate multi-pass as stenciled shadow volumes do

Ideal for shadows from spotlightsConsumer hardware shadow map support here today

GeForce3, GeForce4 Ti, Xbox

Dual-texturing technique supports legacy hardwareSame basic technique used by Pixar to generate shadows in their computer-generated movies

Page 75: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

References

Atherton, Weiler, and Greenberg, "Polygon Shadow Generation"

James Blinn, "Me and my (fake) Shadow

Mark Kilgard, "Improving Shadows and Reflections via the Stencil Buffer"

Everitt and Kilgard, "Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering"

Shadow Maps

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

http://www.paulsprojects.net/opengl/shadowmap/shadowmap.html

Page 76: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson
Page 77: 1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

Sample Programs

SIGGRAPH Advanced OpenGL class, 1996

shadowfun.c – Mark Kilgard – Projection with Stencil

shadowvol.c – Tom McReynolds – demonstration of shadow volumes

shadowmap.c – Tom McReynolds – shadow map, using OpenGL extensions

softshadows.c – Tom McReynolds –Soft Shadows

SIGGRAPH Advanced OpenGL class, 1997

softshadow2.c – Simon Hui – Uses method of Heckbert and Herf

projtex.c – David Yu – based on Segal, Korobkin, van Widenfelt, Foran, and Haeberli, "Fast Shadows and Lighting Effects Using Texture Mapping", SIGGRAPH '92