A Cartoon Has Been Removed Due To Copyright Restrictions .

Transcription

MIT EECS 6.837Computer GraphicsWojciech MatusikA cartoon has been removed due to copyright restrictions.Real-TimeShadowsMIT EECS 6.837 – Durand1

Why are Shadows Important? Depth cue SceneLighting Realism ContactpointsImage removed due to copyright restrictions.2

Shadows as a Depth Cue source unknown. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.3

Shadows as the Origin of Painting source unknown. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.This image is in the public domain. Author: David Allan (!744-1796).4

Shadow in Ray Tracing Trace secondary (shadow) rays towards eachlight source If the closest hit point is smaller than thedistance to the light then the point is in shadow5

Today Shadow Maps– Shadow/View Duality– Texture Mapping Shadow Volumes Deep Shadow Maps Alias-free Shadow Maps6

Shadow Maps Are Important Both in high-end production software.– Pixar’s RenderMan . and in real-time rendering (e.g. games) Pixar. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/. source unknown. All rights reserved. This content isexcluded from our Creative Commons license. For moreinformation, see http://ocw.mit.edu/help/faq-fair-use/.7

Shadow/View Duality A point is lit if itis visible from thelight source Shadowcomputationsimilar to viewcomputation8

Shadow Mapping Texture mapping withdepth information 2 passes– Compute shadowmap depth fromlight source You can think ofit as a z-buffer asseen from the light– Render final image,check shadow mapto see if points arein shadow Addison-Wesley. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.Foley et al. “Computer Graphics Principles andPractice”9

Shadow Map Look Up We have a 3D point (x,y,z)WS How do we look upthe depth from theshadow map?(x',y',z')LS(x,y,z)WS Use the 4x4perspective projectionmatrix from the lightsource to get (x',y',z')LS ShadowMap(x',y') z'? Addison-Wesley. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.Foley et al. “Computer Graphics Principles andPractice”10

Shadow Map Look UpQuestions? We have a 3D point (x,y,z)WS How do we look upthe depth from theshadow map?(x',y',z')LS(x,y,z)WS Use the 4x4perspective projectionmatrix from the lightsource to get (x',y',z')LS ShadowMap(x',y') z'? Addison-Wesley. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.Foley et al. “Computer Graphics Principles andPractice”11

Limitations of Shadow Maps1. Field of View2. Bias (Epsilon)3. Aliasing Addison-Wesley. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.12

1. Field of View Problem What if point toshadow is outsidefield of view ofshadow map?– Use 6 shadow mapson the faces of a cube– . or use onlyspot lights Addison-Wesley. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.13

2. The Bias (Epsilon) Nightmare For a point visiblefrom the light sourceShadowMap(x’,y’) z’– But due to roundingerrors the depthsnever agree exactly How can weavoid erroneousself-shadowing?– Add bias (epsilon) Addison-Wesley. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.14

2. Bias (Epsilon) for Shadow MapsShadowMap(x’,y’) bias z’Choosing a good bias value can be very trickyCorrect imageNot enough bias(“surface acne”)Way too much bias15

3. Shadow Map Aliasing Under-sampling of the shadow map– Jagged shadow edges16

3. Shadow Map Filtering Should we filter the depth?(weighted average of neighboring depth values) No. filtering depth is not meaningfulSurface at z 49.850.250.11.350.0X50.0 49.8?1.21.11.41.2Filter22.9Compare1Ordinary texture map filtering. Does not work for depth maps.Image by MIT OpenCourseWare.17

3. Percentage Closer Filtering Instead we need to filter the result of the shadow test(weighted average of comparison results)Surface at z 49.850.250.11.350.0X50.0 49.8?1.21.11.41.2Compare000011111Filter0.55Sample transform stepImage by MIT OpenCourseWare.18

3. Percentage Closer Filtering 5x5 samples Nice antialiasedshadow Using a biggerfilter producesfake soft shadows Setting biasis tricky19

3. Percentage Closer Filtering 5x5 samples Nice antialiasedshadow Using a biggerfilter producesfake soft shadows Setting biasis trickyQuestions?20

Shadows in Production Often useshadow maps Ray casting asfallback in caseof robustnessissues source unknown. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.21

Hardware Shadow Maps Can be done with hardware texture mapping– Texture coordinates u,v,w generated using 4x4 matrix– Modern hardware permits tests on texture values22

Hardware Shadow Maps Questions? Can be done with hardware texture mapping– Texture coordinates u,v,w generated using 4x4 matrix– Modern hardware permits tests on texture values23

Today Shadow Maps Shadow Volumes– (The Stencil Buffer) Deep Shadow Maps Alias-free Shadow Maps24

Shadow Volumes Explicitly represent the volumeof space in shadow For each polygon– Pyramid with pointlight as apex– Include polygon to cap25

Shadow Volumes If a point is inside a shadowvolume cast by a particular light,the point does not receive anyillumination from that light Cost of naiveimplementation:#polygons * #lights26

Shadow VolumesQuestions? If a point is inside a shadowvolume cast by a particular light,the point does not receive anyillumination from that light Cost of naiveimplementation:#polygons * #lights27

Better Shadow Volumes Shoot a ray from the eye tothe visible point Increment/decrement acounter each time weintersect a shadowvolume polygon If the counter 0,the point isin shadow-1 1 128

Stencil Buffer Tag pixels in one rendering pass tocontrol their update in subsequentrendering passesframe buffer– "For all pixels in the frame buffer" "For all tagged pixels in the frame buffer" Can specify different renderingoperations for each case:– stencil test fails– stencil test passes & depth test fails– stencil test passes & depth test passesdepth bufferstencil buffer29

Stencil Buffer – Real-time Mirror Clear frame, depth & stencil buffers Draw all non-mirror geometry toframe & depth buffers Draw mirror to stencil buffer, wheredepth buffer passes Set depth to infinity, where stencilbuffer passes Draw reflected geometry towithoutstencilframe & depth buffer, wherebuffer:stencil buffer passesreflectedgeometrySee NVIDIA's stencil buffer tutorialhttp://developer.nvidia.comalso discusses blending, multiplemirrors, objects behind mirror, etc NVIDIA. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.30

Shadow Volumes w/ the Stencil BufferInitialize stencil buffer to 0Draw scene with ambient light onlyTurn off frame buffer & z-buffer updatesDraw front-facing shadow polygonsIf z-pass increment counterDraw back-facing shadow polygonsIf z-pass decrement counterTurn on frame buffer updatesTurn on lighting and0redraw pixels withcounter 0 1 231

Shadow Volumes w/ the Stencil BufferInitialize stencil buffer to 0Draw scene with ambient light onlyTurn off frame buffer & z-buffer updatesDraw front-facing shadow polygonsIf z-pass increment counterDraw back-facing shadow polygonsIf z-pass decrement counterTurn on frame buffer updatesTurn on lighting and0redraw pixels withcounter 0Questions? 1 232

If the Eye is in Shadow. . then a counter of 0 doesnot necessarily mean lit 3 Possible Solutions:1. Explicitly test eyepoint with respectto all shadow volumes2. Clip the shadowvolumes to theview frustum-13. "Z-Fail" shadowvolumes-1033

1. Test Eye with Respect to Volumes Adjust initialcounter valueExpensive0 10 134

2. Clip the Shadow Volumes Clip the shadow volumes to the view frustumand include these new polygons Messy CSG35

3. "Z-Fail" Shadow VolumesStart at infinity.Draw front-facing shadow polygonsIf z-fail, decrement counterDraw back-facing shadow polygonsIf z-fail, increment counter.00 136

3. "Z-Fail" Shadow Volumes Introduces problemswith far clipping plane Solved by clamping thedepth during clipping00 137

3. "Z-Fail" Shadow Volumes Introduces problemswith far clipping plane Solved by clamping thedepth during clipping00 1Questions?38

Optimizing Shadow Volumes Use silhouette edges only (edge wherea back-facing & front-facing polygon meet)39

Shadow Volumes Are Sort of Passé It is possible to implement shadow volumes ratherefficiently using the stencil buffer– John Carmack’s Doom 3 engine did this very well– Shadow volumes had their 15 minutes of popularity around thattimeId Software– NVIDIA even came up withhardware acceleration(“UltraShadow”) Further infoScreenshot from video game Doom 4 removed due to copyright restrictions.– Wikipedia– Aila & Akenine-Möller:Hierarchical Shadow Volumes,Proc. Graphics Hardware 200440

Shadow Volumes Are Sort of Passé The need to extractsilhouette edges andrasterize the resultingshadow polygons is justtoo much work whenscene complexities andimage resolutions grow Still, such use of thestencil buffer can beuseful for other tricks? source unknown. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.41

Shadow Volumes Are Sort of Passé The need to extractsilhouette edges andrasterize the resultingshadow polygons is justtoo much work whenscene complexities andimage resolutions grow Shadow maps are bad,but they’re the bestwe’ve got!? source unknown. All rights reserved. This content is excluded from our CreativeCommons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.42

Further Reading on Shadows Some recent techniques allow filtering the shadowmap instead of just the tests (percentage closer)– Works pretty well in some situations, although not general– Variance Shadow Maps (Donnelly, Lauritzen I3D 2006)Annen et al. 2008– Convolution Shadow Maps Annen et al., SIGGRAPH 2008 Annen et al., EGSR 2007 An interesting hybrid betweenshadow maps and ray tracing– Aila and Laine, Alias-FreeShadow Maps, EGSR 2004 ACM. All rights reserved. This content is excluded fromour Creative Commons license. For more information, seehttp://ocw.mit.edu/help/faq-fair-use/.43

Today Shadow Maps Shadow Volumes– (The Stencil Buffer) Deep Shadow Maps Alias-free Shadow Maps44

Deep shadow maps Lokovic & Veach, Pixar Shadows in participating media like smoke, insidehair, etc.– They represent notjust depth of thefirst occludingsurface, but theattenuationalong the light rays Note: shadowingonly, no scattering ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.45

Visibility function along depth Fraction of a pixel occluded, as a function of depth Due to– small occluders, semi-transparent objects, smoke &volumetric effects ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.46

Deep shadow maps Preprocess:Compute dense visibility function for each pixel ofshadow map– send lots of rays or rasterize at a high resolution– compress visibility function at each pixel to reduce memory cost At render time, shadow query– Transform visible point into light coordinates just like shadow maps– Read visibility value from compressed function47

Compression algorithm Approximation:Piecewise linear Set an error bound Decide which verticesto keep Greedy from zero do far ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.48

Deep shadow map results ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.49

Deep shadow map results ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.50

Deep shadow map results Advantage of deep shadow map over higherresolution normal shadow map:Pre-filtering for shadow antialiasing ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.51

Enables motion blur in shadows ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.52

Enables motion blur in shadows ACM. All rights reserved. This content is excluded from our Creative Commonslicense. For more information, see http://ocw.mit.edu/help/faq-fair-use/.Questions?53

Today Shadow Maps Shadow Volumes– (The Stencil Buffer) Deep Shadow Maps Alias-free Shadow Maps54

Alias-free shadow maps Aila and Laine,http://www.tml.tkk.fi/ timo/ aka Irregular z-buffer by Johnson et al.http://pl887.pairlitesite.com/papers/tog05-izb/ Following slides by Aila and Laine55

Content removed due to copyright restrictions -- please see slide 4,6-14 from Timo Aila and Samuli Laine's talk slides on "AliasFree Shadow Maps." available at -shadow-maps for further details.56

Irregular z buffer resultsA video clip demonstrating the irregular z buffer results has been removed due to copyright restrictions.57

That’s All For Today!58Image: Laineand Aila, EG 2005Image removed due to copyright restrictions -- please see Fig. 4 in S. Laine and T. Aila, ”HierarchicalPenumbra Casting.” Computer Graphics Forum 24(3) (Eurographics 2005) for further details.

MIT OpenCourseWarehttp://ocw.mit.edu6.837 Computer GraphicsFall 2012For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

Further Reading on Shadows Some recent techniques allow filtering the shadow map instead of just the tests (percentage closer) –Works pretty well in some situations, although not general – Variance Shadow Maps (Donnelly, Lauritzen I3D 2006) –Convolution Shadow Map