Shadow Mapping and Shadow Volumes: Recent Developments in ...· Shadow Mapping and Shadow Volumes:

download Shadow Mapping and Shadow Volumes: Recent Developments in ...· Shadow Mapping and Shadow Volumes:

of 7

  • date post

  • Category


  • view

  • download


Embed Size (px)

Transcript of Shadow Mapping and Shadow Volumes: Recent Developments in ...· Shadow Mapping and Shadow Volumes:

  • Shadow Mapping and Shadow Volumes: Recent Developments in Real-TimeShadow Rendering

    University of British ColumbiaCS514 Advanced Computer Graphics: Image Based Rendering

    Instructor: Wolfgang Heidrich

    Project Report

    Andrew V. Nealen

    Technische Universitat Darmstadt


    In recent years , both Williams original Z-buffer shadow map-ping algorithm [Williams 1978] and Crows shadow volumes [Crow1977] have seen many variations, additions and enhancements,greatly increasing the visual quality and efficiency of renderingsusing these techniques. Additionally, the fast evolution of com-modity graphics hardware allows for a nearly complete mapping ofthese algorithms to such devices (depending on the GPUs capa-bilities) which results in real-time display rates as seen in the real-time version of Pixars Luxo Jr and the use of hardware shadowmaps therein. In this project report we describe the major contribu-tions since Williams and Crows original publications in 1978 and1977 respectively, briefly present both the shadow mapping (whichis computed in image space) and the shadow volume algorithms,present more sophisticated approaches to shadow mapping whichare better suited to high quality off-line renderers and describe thealiasing problems inherent in all shadow algorithms which operatein image space (and proposed solutions). Finally, we describe newextensions to the existing algorithms such as perspective shadowmaps as described by [Stamminger and Drettakis 2002] in the 2002SIGGRAPH conference, and robust stenciled shadow volumes byMark Kilgard [Everitt and Kilgard 2002].

    Keywords: shadows, shadow mapping, algorithms, visual realism,graphics hardware

    1 Overview

    The importance of Lance Williams original shadow algorithm[Williams 1978] is obvious, as many renderers such as Pixars Ren-derMan utilize the technique and the original paper was also electedto be of seminal nature, see [Wolfe 1998]. The basic idea is seem-ingly simple, yet its largest benefit is also its greatest drawback:the discrete nature of the image space computation and thus theintroduction of aliasing artifacts (For a more detailed description,see section 4). Since Williams original publication many enhance-ments and variations of the algorithm have been proposed and pub-lished, yet only recently (in the past few years) have more majorcontributions been made to the technique, which is not surpris-ing as it has been in these years that commodity graphics hard-ware evolution has surpassed moores law. This new computational(graphics)power has made many multi-pass algorithms more at-tractive to real-time rendering, including Williams shadow map-ping algorithm, Crows shadow volume algorithm and derivativesthereof. Poulin, Fournier and Woo [Woo et al. 1990] have summed


    Figure 1: Shadows create drama: a screen-shot from id softwaresnewest creation Doom 3. A good example using stenciled shadowvolumes.

    up the efforts up to 1990, including many off-line techniques notdescribed in this report. Due to the age of their survey the pa-per fails to present the newer developments in the field such as(for shadow mapping): support for hardware acceleration [Kilgard2001][Brabec and Seidel 2001], projective texture mapping [Segalet al. 1992][Heidrich 1999], newer soft shadow mapping techniques[Brabec and Seidel 2002][Heidrich et al. 2000] and perspectiveshadow maps [Stamminger and Drettakis 2002]. For the shadowvolume algorithm: stenciled shadow volumes [Everitt and Kilgard2002][Heidmann 1991], soft stenciled shadow volumes [Akenine-Moeller and Assarsson 2002] and hybrid methods between shadowmapping and shadow volumes [McCool 2000].

    In this project report we attempt to bridge this gap and presentto the reader a comprehensive overview of available recently devel-oped techniques, enhancements and additions to the basic shadowmapping and shadow volume algorithms. To keep within thescope of this report we only briefly describe off-line, highly so-phisticated versions of shadow mapping, but list relevant liter-ature for further reading. Also, the description of the shadowmapping and shadow volume techniques presented in this reportmay also not be as detailed as necessary for direct implementa-tion, therefore all necessary literature is referenced. An invalu-able resource for developers is NVIDIAs developer web-site at Given this information, thereader should be up to date with the current state of the art in real-

  • time shadow rendering.

    2 Alternatives to (Real-Time) ShadowMapping and Shadow Volumes

    2.1 Projected Planar Shadows

    During the research phase, which inspired this report, other alterna-tives to shadow mapping and shadow volumes were surveyed. Ofthe possible alternatives, projected planar shadows seems to be themost promising algorithm. Blinn [Blinn 1988] invented the originaltechnique, which only allows shadows to be cast on planar surfaces.Haines [Haines 2001] extended the planar shadow projection tech-nique to soft shadows, although with the same limitations of Blinnsbasic projection algorithm. Kilgard [Kilgard 1999] shows how toutilize the stencil buffer to improve the visual quality of projectedshadows.

    The idea: given a plane P : n x+d = 0 and a point light sourcel, construct a projection matrix M that projects each vertex v ontothe plane P. The point p, which is the projection of vertex v ontothe plane P can be described as

    p = l d +n ln (v l)

    v l

    This can be converted into a projection matrix which satisfiesMv = p [Haines and Moeller 1999]

    M =

    n l+d lxnx lxny lxnz lxdlynx n l+d lyny lynz lydlznx lzny n l+d lznz lzdnx ny nz n l

    Care must be taken to avoid anti-shadows, e.g. when the light

    source is between the occluder and the shadow plane. Other sub-tleties and solutions (such as utilizing the stencil buffer to preventgeometry overlapping) can be found in [Haines and Moeller 1999]and [Kilgard 1999].

    2.2 Off-line Shadow Mapping

    Stamminger and Drettakis [Stamminger and Drettakis 2002] de-scribe a slew of very sophisticated shadow mapping algorithms intheir paper on perspective shadow maps. They note that almostall of these algorithms involve multiple rendering passes (as theygenerally use more than one shadow map) and more involved datastructures and thus do not, or do not easily map to hardware. Nev-ertheless, for completeness, we list the relevant literature in thereferences section, specifically for soft shadows [Agrawala et al.2000], adaptive shadow maps [Fernando et al. 2001], deep shadowmaps [Lokovic and Veach 2000] and solar shadows [Tadamura et al.2001].

    3 The Shadow Volume Algorithm

    The shadow volume algorithm is a geometry based shadow al-gorithm which requires connectivity information of the polygonalmeshes in the scene to efficiently compute the silhouette of eachshadow casting object (each occluder). It is also a per pixel algo-rithm, which performs an in shadow test for each rendered frag-ment. This operation can be accelerated using graphics hardware(the stencil buffer) as we will describe later. In pseudocode, thealgorithm reads as follows

    procedure SHADOWVOLUMERENDERINGfor all rasterized fragments do

    draw fragment with ambient and emissive lightingupdate the Z-buffer

    end forCOMPUTEFRAGMENTSINSHADOWfor all rasterized fragments do

    if not INSHADOW(fragment) thendraw fragment with diffuse and specular lighting

    end ifend for

    As obvious, the key issue here is determining whether a ren-dered fragment is in shadow or not. This procedure maps easily toany graphics hardware with a stencil buffer. After rendering eachfragment with emissive and ambient lighting, the following must beinserted

    procedure COMPUTEFRAGMENTSINSHADOW (Z-pass)for all shadow casting objects do

    compute potential silhouette edges (PSE) of the polygonalmodelcompute the shadow volume polygons (shadow quads) fromthe light source(s) and the PSE

    end forfor all front facing shadow quads from viewpoint do

    if Z-buffer test passes thenincrement stencil buffer value

    end ifend forfor all back facing shadow quads from viewpoint do

    if Z-buffer test passes thendecrement stencil buffer value

    end ifend for

    Now to evaluate the boolean function INSHADOW (used inSHADOWVOLUMERENDERING) for each fragment we simplyquery the stencil buffer value. If the the value stored in the stencilbuffer after COMPUTEFRAGMENTSINSHADOW is greater thanzero, the fragment is in shadow and must not be drawn in the secondrendering pass.

    To understand the procedure geometrically, see figure 2 takenfrom [Akenine-Moeller and Assarsson 2002].

    Figure 2: Shadow Volume Rendering: counting entering and exit-ing rays from the viewpoint to determine whether a visible fragmentis in shadow.

    When computing the shadow query using the stencil buffer asdescribed above, the algorithm is usually titled stenciled shadow

  • volumes and was first proposed in [Heidmann 1991] and further re-fined in [Kilgard 1999]. The algorithm as described suffers from anamount of drawbacks which make it impractical for certain situa-tions, if special cases are not treated correctly. First off, the algo-rithm only works if the viewpoint is outside of shadow, otherwisethe stencil counting is inverted. This can be remedied by testing thisspecial case, inverting the shadow test, and also initializing the sten-cil buffer to 2N1 (where N is the stencil buffer precision), as thestencil buffer holds only unsigned values and decrementing from azero value would again result in incorrect shadows.

    A more elegant solution is proposed in [Everitt and Kilgard2002] , which was partially inspired by an insight of John Car-mack, lead programmer of id software [Carmack 2000]. First off,instead of computing the ste