SlideShare ist ein Scribd-Unternehmen logo
1 von 100
CS 354
Shadows
Mark Kilgard
University of Texas
March 20, 2012
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
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
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?
CS 354                                                                             5

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

        Multiple choice: The effective        Multiple choice: Programmable
         memory bandwidth of a                  tessellation is good for
         graphics processor can be
         higher than its raw memory             a) displacement mapping
         bandwidth due to:
                                                b) per-pixel lighting
         a) more multiply-add
         operations per clock                   c) increasing the appearance of
                                                surface curvature
         b) not showing pixels when
         they are opaque                        d) feeding more triangles to the
                                                graphics pipeline
         c) domain-specific
         compression techniques                 e) a, c, and d
         d) off-loading work to the             f) a, b, c, and d
         network
                                                g) b, c, and d
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
CS 354                                                               7

         Shadows Provide
         Cues About Depth
        Two scenes
            Difference is in shadows




             Balls resting on ground    Balls floating off surface
CS 354                                                    8

         Computed Shadows aren’t
         Necessarily Realistic




                       Shadows of Past – Lyubomir Bukov
CS 354                                                      9

         Shadows in Gaming
         Shading + Shadows = More Drama




                       + Bump mapping
                       + Specular


          Only                          Shadows + Shading
     Diffuse + Decal                        Combined




                         + Shadows
CS 354                                            10

         Ray Tracing
         Approach to Shadows
        Shadows = global lighting effect
            Involves more than light + surface
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
CS 354                                                                 12

         Interactive
         Lighting 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 L•N)
            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
CS 354                                                       13

         Interactive Shadow
         Simplications
        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
CS 354                                                 14

         Interactive Shadow
         Rendering Techniques
        Different approaches, different tradeoffs
          Shadow maps
          Planar projected shadows
          Stenciled shadow volumes
          Pre-computed shadow textures (light maps)
CS 354                                     15

         Common Real-time
         Shadow Techniques
                  Projected     Shadow
                  planar        volumes
                  shadows




                                  Hybrid
                              approaches
     Light maps
CS 354                                                                     16

     Projective Texturing
     Shadow Maps Visualized



         Without Shadows         Projected Shadow Map       With Shadows




                  Light’s View         Light’s View Depth
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
CS 354                                                               18

         Shadow Mapping
         References
        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)
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
CS 354                                                20

         Shadow Maps for Fine
         Shadows



                                Chain-link fence is
                                shadow volume
                                nightmare!

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

         The Shadow Mapping
         Concept (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
CS 354                                                               22

         The Shadow Mapping
         Concept (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
CS 354                                                              23

         The Shadow Mapping
         Concept (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
CS 354                                                           24

         Shadow Mapping
         with a picture in 2D
        The A < B shadowed fragment case
                         depth map image plane

                              depth map Z = A
           light
           source
                                                 eye
                                                 position



                                         eye view image plane,
                                         aka the frame buffer
                    fragment’s
                    light Z = B
25

         Shadow Mapping
CS 354




         with a picture in 2D
        The A ≅ B unshadowed fragment case
                         depth map image plane

                              depth map Z = A
           light
           source
                                                 eye
                                                 position



                                         eye view image plane,
                                         aka the frame buffer
                    fragment’s
                    light Z = B
CS 354                                                 26

         Shadow Mapping
         with a picture in 2D
        Note image precision mismatch!

                                   The depth map
                                   could be at a
                                   different resolution
                                   from the framebuffer


                                   This mismatch can
                                   lead to artifacts
27

             Avoiding Artifacts with
CS 354




             Depth 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 much bias, shadow
         everything begins to                               starts too far back
         shadow

                    Just right
CS 354                                         28

         Visualizing the Shadow
         Mapping Technique (1)
        A fairly complex scene with shadows




      the point
   light source
CS 354                                            29

         Visualizing the Shadow
         Mapping Technique (2)
        Compare with and without shadows




            with shadows        without shadows
CS 354                                                         30

         Visualizing the Shadow
         Mapping Technique (3)
        The scene from the light’s point-of-view




                                             FYI: from the
                                             eye’s point-of-view
                                             again
CS 354                                                             31

         Visualizing the Shadow
         Mapping Technique (4)
        The depth buffer from the light’s point-of-view




                                           FYI: from the
                                           light’s point-of-view
                                           again
CS 354                                                             32

         Visualizing the Shadow
         Mapping Technique (5)
        Projecting the depth map onto the eye’s view




                                           FYI: depth map for
                                           light’s point-of-view
                                           again
CS 354                                                                                   33


          Shadow Map Eye Linear
          Texture Coordinate Transform
                                                           glTexGen automatically
         xe                                        xo    applies this when modelview
                         Eye                              matrix contains just the eye
         ye             view        Modeling       yo           view transform
         ze
                =     (look at)      matrix        zo
                       matrix
         we                                        wo


         s          1/2      1/2                                 Inverse       xe
                                        Light        Light
         t            1/2    1/2      frustum        view
                                                                   eye         ye
         r
              =                     (projection)   (look at)
                                                                   view
                                                                               ze
                          1/2 1/2                               (look at)
                                       matrix       matrix
         q                                                        matrix       we
                              1


         Supply this combined transform to glTexGen or shader
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]
CS 354                                                             35

         Visualizing the Shadow
         Mapping Technique (5)
        Projecting the depth map onto the eye’s view




                                           FYI: depth map for
                                           light’s point-of-view
                                           again
CS 354                                                                  36

         Visualizing the Shadow
         Mapping 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
CS 354                                                       37

         Visualizing the Shadow
         Mapping Technique (7)
        Comparing light distance to light depth map



    Green is where
    the light planar
       distance and                              Non-green is
     the light depth                             where shadows
            map are                              should be
     approximately
               equal
CS 354                                       38

         Visualizing the Shadow
         Mapping Technique (8)
        Scene with shadows




      Notice how                  Notice how
        specular                  curved
       highlights                 surfaces cast
    never appear                  shadows on
     in shadows                   each other
CS 354                                              39



         More Examples
        Smooth surfaces with object self-
         shadowing




                       Note object self-shadowing
CS 354                                40



         More Examples
        Complex objects all shadow
CS 354                                                     41



         Shadow Mapping Artifacts
        Even the floor casts shadow, but…

                                       Note shadow
                                       leakage due to
                                       infinitely thin
                                       floor

                                       Could be fixed by
                                       giving floor
                                       thickness
CS 354                                                   42



          Shadow Map Precision Artifacts
         Resolution of rendered depth map determines
          shadow mapping precision




             low-resolution            sufficient
         shadow map blockiness   shadow map resolution
CS 354                                                43

         Four Images of
         Dueling Frusta Case
                               Eye’s View with
                               projection
                               of color-coded
 Eye’s                         mipmap levels
 View                          from light:
                               Red = minification
                               Blue = magnification




 Light’s                        Light’s View with
 View                           re-projection
                                of above image
                                from the eye
CS 354                                                     44


           Interpretation of the Images
           of the Dueling Frusta Case
                            Region that is smallest in
                            the light’s view is a region
         Eye’s
                            that is very large in the
         View
                            eye’s view. This implies
                            that it would require a very
                            high-resolution shadow
                            map to avoid obvious
                            blocky shadow edge
                            artifacts.
         Light’s
         View
CS 354                                               45


         Dueling Frusta Blocky
         Shadow Edge Artifacts
 Notice that
 shadow edge
 is well defined
 in the
 distance.                       Light position
                                 out here pointing
                                 towards the
                                 viewer.

                                 Blocky
                                 shadow edge
                                 artifacts.
CS 354                                                                        46



         Shadow Acne
        Ambiguous shadow map comparisons cause very
         unsightly artifacts
            Moiré patterns form; animates poorly




               “shadow acne”                       polygon offset
             depth comparison is           provides sufficient depth offset
                 ambiguous                    for unambiguous depth
                                                    comparisons
CS 354                                                        47

         Planar Projected
         Shadows
        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
CS 354                             48

         Projected Planar Shadow
         Example
CS 354                                                        49

         Projected Planar
         Shadows
        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
CS 354                                                 50

         Projected Planar
         Shadow 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
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
CS 354                                                               52

         Projected Planar
         Shadow 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
CS 354                                              53

          Planar Projected
          Shadow Artifacts
         Bad                         Good




                                    extends off
                                    ground region

                   Z fighting   double blending
CS 354                                                                             54

         Quick Tutorial on
         Stencil 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)
CS 354                                                               55

         Stencil Testing in the
         Fragment Pipeline
          Fragment      Pixel
              +                    Scissor         Alpha
                      Ownership
                                    Test           Test
         Associated     Test
            Data


                           Depth         Stencil
                            Test          Test




                        Blending   Dithering        Logic   Frame
                                                     Op     buffer
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 )
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
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
CS 354                                                             59

         The Shadow Volume
         Concept
        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…
CS 354                                                 60

         Visualizing
         Shadow Volumes
        Occluder and light projects a shadow volume
CS 354                                            61

         Shadow Volume
         Result
        Objects within the volume are shadowed
CS 354                                                         62

         Shadow Volume
         Algorithm
        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?
CS 354                                                               63

          2D Cutaway of a
          Shadow Volume
                                      surface outside
                          shadowing   shadow volume
                          object      (illuminated)
         light
         source                                  shadow
                                                 volume
                                                 (infinite extent)



            eye
            position                     surface inside
                       partially
                       shadowed          shadow volume
                       object            (shadowed)
CS 354                                                                         64

         Tagging Pixels as
         Shadowed 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!
CS 354                                            65

         Stencil Inverting of
         Shadow Volume
        Why it works
                            shadowing
         light              object
         source
                         two inverts, left zero

                           one invert, left one


         eye            zero inverts, left zero
         position
CS 354                                           66

         Visualizing Stenciled
         Shadow Volume Tagging
   Shadowed scene     Stencil buffer




                    red = stencil value of 1
                    green = stencil value of 0
CS 354                                                     67

         Computing
         Shadow 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
CS 354                                                           68

         For Shadow Volumes
         With 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
CS 354                                                                   69

          Why Eye-to-Object Stencil
          Counting Approach Works

         Light                                   Shadowing object
         source


                    zero             +1

                                                zero



                                                         Example in 2D
                                +2         +2
         Eye               +1
                                      +3
         position
CS 354                                                                       70

          Illuminated,
          Behind Shadow Volumes (Zpass)

         Light                                            Shadowing object
         source


                     zero                 +1

                                                         zero

                            +    +        + -    -   -          Unshadowed
                                                                   object
                                     +2         +2
         Eye                +1
                                           +3
         position

          Shadow Volume Count = +1+1+1-1-1-1 = 0
CS 354                                                                    71

          Shadowed, Nested in Shadow
          Volumes (Zpass)
         Light                                         Shadowing object
         source


                      zero                 +1

                                                      zero

                             +    +        + -

                                      +2         +2          Shadowed
         Eye                 +1                                object
                                            +3
         position

          Shadow Volume Count = +1+1+1-1 = 2
CS 354                                                          72

         Illuminated, In Front of Shadow
         Volumes (Zpass)
    Light                                    Shadowing object
    source


                zero             +1

                                            zero




                            +2         +2          Shadowed
    Eye                +1                            object
                                  +3
    position

   Shadow Volume Count = 0 (no depth tests pass)
CS 354                                                             73

         Shadow Volume
         Issues
        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
CS 354                                                                        74

           Problem Created by
           Near Clip Plane (Zpass)
         Missed shadow volume
         intersection due to near
         clip plane clipping; leads
         to mistaken count                                         Far clip
                                                                   plane

                                      zero

                                                       +1
                                      +1
                                              +2
                                                            zero
                                             +3
                                                  +2

           Near clip
            plane
CS 354                                                                75



         Alternative Approach: Zfail

        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
CS 354                                                           76

         Illuminated,
         Behind Shadow Volumes (Zfail)

    Light                                     Shadowing object
    source


                 zero             +1

                                             zero

                                                    Unshadowed
                                                       object
                             +2         +2
    Eye                 +1
                                   +3
    position

   Shadow Volume Count = 0 (zero depth tests fail)
CS 354                                                                   77

          Shadowed, Nested in
          Shadow Volumes (Zfail)
         Light                                        Shadowing object
         source


                     zero             +1

                                                     zero

                                             +   +

                                 +2         +2              Shadowed
         Eye                +1                                object
                                       +3
         position

          Shadow Volume Count = +1+1 = 2
CS 354                                                                        78

          Illuminated, In Front of Shadow
          Volumes (Zfail)

         Light                                             Shadowing object
         source


                      zero                 +1

                                                          zero

                             -    -        - +    +   +

                                      +2         +2              Shadowed
         Eye                 +1                                    object
                                            +3
         position

         Shadow Volume Count = -1-1-1+1+1+1 = 0
CS 354                                                                 79

         Problem Created by
         Far Clip Plane (Zfail)
                                                     Far clip
                                                     plane

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




                                      +1

                                           zero
                        +1 +2
                                     +2
                                +3
     Near clip
      plane
CS 354                                     80

         Problem Solved by
         Eliminating Far Clip


                 zero




                                      +1

                        +1 +2
                                     +2
                                +3
     Near clip
      plane
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 when
         the far plane distance goes to infinity?
CS 354                                                                  82

         Standard glFrustum Projection
         Matrix
    2 × Near                       Right + Left                    
    Right − Left        0                                0         
                                    Right − Left
                                                                   
                     2 × Near     Top + Bottom                     
          0                                                0
 P=                Top − Bottom   Top − Bottom                     
                                    Far + Near      2 × Far × Near 
         0              0         −               −                
                                    Far − Near        Far − Near 
   
         0              0              −1                 0        
                                                                    



        Only third row depends on Far and Near
CS 354                                                                          83

         Limit of glFrustum Matrix as
         Far Plane is Moved to Infinity
                  2 × Near                       Right + Left              
                  Right − Left        0                              0     
                                                  Right − Left
                                                                           
                                    2 × Near     Top + Bottom
 lim P = Pinf   =      0                                             0     
Far →∞                           Top − Bottom   Top − Bottom               
                       0               0             −1         − 2 × Near 
                                                                           
                 
                       0              0              −1              0     
                                                                            

        First, second, and fourth rows are the same as
         in P
        But third row no longer depends on Far
            Effectively, Far equals ∞
84

         Verifying Pinf Will Not Clip
CS 354




         Infinitely 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
85

         Verifying Pinf Will Not Clip
CS 354




         Infinitely Far Away Vertices (2)
        Transform eye-space (0,0,-D,0) to clip-space
                         2 × Near                      Right + Left              
                                             0                             0
          xc   xc   Right − Left                   Right − Left                  0 
          y  y                       2 × Near     Top + Bottom
                                                                                      0 
          c  =  c =      0                                             0            
         − D   zc                  Top − Bottom   Top − Bottom                  − D 
                         0               0             −1         − 2 × Near        
          − D   wc                                                               0 
                        
                             0               0             −1              0     
                                                                                  

        Then, assuming glDepthRange(0,1), transform clip-
         space position to window-space position
                          zc             −D
               z w = 0.5 × + 0.5 = 0.5 ×    + 0.5 = 1
                          wc             −D
        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)
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)
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
CS 354                         88

         Stencil Volume
         Rendering Animation
CS 354                                                                  89

     Shadow Volumes Add “Invisible”
     Geometric Complexity



                                                     Visible geometry




  Scene with multiple light sources                  Shadow volume
                                                     geometry
            Abducted game images courtesy
            Joe Riedel at Contraband Entertainment
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
CS 354                                                            91

         Multiple Lights and
         Shadow Volumes
        Requires still more rendering passes,
         but can work!



                                         Shadows from different
                                         light sources overlap
                                         correctly
CS 354                                                     92

         Shadow Volumes from
         Area 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
CS 354                                           93

         Area Light Sources Cast Soft
         Shadows
                                    area light
                                     source




                       umbra
CS 354                                                  94



         Soft Shadow Example
        Eight samples (more would be better)



                                     Note the banding
                                     artifacts
CS 354                                                                95

         Combined
         Shadow Approaches
        Two Approaches at Once
                  just logo shadow volume

                               logo lacks shadow
                               on the teapot




                                                   just planar projected
  teapot lacks
                                                   shadows
  shadow
  on the floor
                 combined
                 approach
CS 354                                                                96

         Pre-computed
         Shadow 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
CS 354                                                     97

         Light maps can encode
         Static Pre-computed Shadows
                                           decal only

                         ×
                      (modulate)



light maps only




     =
                                    * Id Software’s Quake 2
                   combined scene                 circa 1997
CS 354                                                                         98

         Rendering
         Soft 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
CS 354                                                             99

         Rendered
         Soft Shadow Texture Example
        Shadow Texture and Final Result




    Shadow texture, accumulation   Final resulting scene, shadow
    of nine jittered occluder      texture modulated with
    projections                    wooden floor
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?

Weitere ähnliche Inhalte

Was ist angesagt?

CS 354 Performance Analysis
CS 354 Performance AnalysisCS 354 Performance Analysis
CS 354 Performance AnalysisMark Kilgard
 
Robust Stenciled Shadow Volumes
Robust Stenciled Shadow VolumesRobust Stenciled Shadow Volumes
Robust Stenciled Shadow VolumesMark Kilgard
 
CS 354 Final Exam Review
CS 354 Final Exam ReviewCS 354 Final Exam Review
CS 354 Final Exam ReviewMark Kilgard
 
CS 354 Procedural Methods
CS 354 Procedural MethodsCS 354 Procedural Methods
CS 354 Procedural MethodsMark Kilgard
 
CS 354 GPU Architecture
CS 354 GPU ArchitectureCS 354 GPU Architecture
CS 354 GPU ArchitectureMark Kilgard
 
Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John HableNaughty Dog
 
The technology behind_the_elemental_demo_16x9-1248544805
The technology behind_the_elemental_demo_16x9-1248544805The technology behind_the_elemental_demo_16x9-1248544805
The technology behind_the_elemental_demo_16x9-1248544805mistercteam
 
CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable ShadingMark Kilgard
 
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated RenderingPractical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated RenderingMark Kilgard
 
CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics PipelineMark Kilgard
 
Around the World in 80 Shaders
Around the World in 80 ShadersAround the World in 80 Shaders
Around the World in 80 Shadersstevemcauley
 
A Bit More Deferred Cry Engine3
A Bit More Deferred   Cry Engine3A Bit More Deferred   Cry Engine3
A Bit More Deferred Cry Engine3guest11b095
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture MappingMark Kilgard
 
The Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s FortuneThe Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s FortuneNaughty Dog
 
CS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path RenderingCS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path RenderingMark Kilgard
 
Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3stevemcauley
 
Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Tiago Sousa
 

Was ist angesagt? (20)

CS 354 Performance Analysis
CS 354 Performance AnalysisCS 354 Performance Analysis
CS 354 Performance Analysis
 
Robust Stenciled Shadow Volumes
Robust Stenciled Shadow VolumesRobust Stenciled Shadow Volumes
Robust Stenciled Shadow Volumes
 
CS 354 Final Exam Review
CS 354 Final Exam ReviewCS 354 Final Exam Review
CS 354 Final Exam Review
 
CS 354 Lighting
CS 354 LightingCS 354 Lighting
CS 354 Lighting
 
CS 354 Procedural Methods
CS 354 Procedural MethodsCS 354 Procedural Methods
CS 354 Procedural Methods
 
CS 354 GPU Architecture
CS 354 GPU ArchitectureCS 354 GPU Architecture
CS 354 GPU Architecture
 
CS 354 Typography
CS 354 TypographyCS 354 Typography
CS 354 Typography
 
Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John Hable
 
The technology behind_the_elemental_demo_16x9-1248544805
The technology behind_the_elemental_demo_16x9-1248544805The technology behind_the_elemental_demo_16x9-1248544805
The technology behind_the_elemental_demo_16x9-1248544805
 
CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable Shading
 
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated RenderingPractical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering
 
CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics Pipeline
 
Around the World in 80 Shaders
Around the World in 80 ShadersAround the World in 80 Shaders
Around the World in 80 Shaders
 
A Bit More Deferred Cry Engine3
A Bit More Deferred   Cry Engine3A Bit More Deferred   Cry Engine3
A Bit More Deferred Cry Engine3
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture Mapping
 
The Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s FortuneThe Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s Fortune
 
Reyes
ReyesReyes
Reyes
 
CS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path RenderingCS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path Rendering
 
Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3
 
Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666
 

Andere mochten auch

CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics MathMark Kilgard
 
CS 354 Surfaces, Programmable Tessellation, and NPR Graphics
CS 354 Surfaces, Programmable Tessellation, and NPR GraphicsCS 354 Surfaces, Programmable Tessellation, and NPR Graphics
CS 354 Surfaces, Programmable Tessellation, and NPR GraphicsMark Kilgard
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing StuffMark Kilgard
 
CS 354 Project 1 Discussion
CS 354 Project 1 DiscussionCS 354 Project 1 Discussion
CS 354 Project 1 DiscussionMark Kilgard
 
CS 354 Introduction
CS 354 IntroductionCS 354 Introduction
CS 354 IntroductionMark Kilgard
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016Mark Kilgard
 
Light 3
Light 3Light 3
Light 3lihor
 
K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)
K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)
K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)LiGhT ArOhL
 

Andere mochten auch (10)

Cs559 11
Cs559 11Cs559 11
Cs559 11
 
What can light do
What can light doWhat can light do
What can light do
 
CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics Math
 
CS 354 Surfaces, Programmable Tessellation, and NPR Graphics
CS 354 Surfaces, Programmable Tessellation, and NPR GraphicsCS 354 Surfaces, Programmable Tessellation, and NPR Graphics
CS 354 Surfaces, Programmable Tessellation, and NPR Graphics
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
CS 354 Project 1 Discussion
CS 354 Project 1 DiscussionCS 354 Project 1 Discussion
CS 354 Project 1 Discussion
 
CS 354 Introduction
CS 354 IntroductionCS 354 Introduction
CS 354 Introduction
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016
 
Light 3
Light 3Light 3
Light 3
 
K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)
K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)
K TO 12 GRADE 4 TEACHER’S GUIDE IN SCIENCE (Q1-Q4)
 

Ähnlich wie CS 354 Shadows

The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" DemoThe Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demodrandom
 
Epic_GDC2011_Samaritan
Epic_GDC2011_SamaritanEpic_GDC2011_Samaritan
Epic_GDC2011_SamaritanMinGeun Park
 
Deferred shading
Deferred shadingDeferred shading
Deferred shadingFrank Chao
 
Shadow Techniques for Real-Time and Interactive Applications
Shadow Techniques for Real-Time and Interactive ApplicationsShadow Techniques for Real-Time and Interactive Applications
Shadow Techniques for Real-Time and Interactive Applicationsstefan_b
 
Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...
Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...
Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...Umbra
 
2008 brokerage 03 scalable 3 d models [compatibility mode]
2008 brokerage 03 scalable 3 d models [compatibility mode]2008 brokerage 03 scalable 3 d models [compatibility mode]
2008 brokerage 03 scalable 3 d models [compatibility mode]imec.archive
 
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsHPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsElectronic Arts / DICE
 
Introduction to 3D Computer Vision and Differentiable Rendering
Introduction to 3D Computer Vision and Differentiable RenderingIntroduction to 3D Computer Vision and Differentiable Rendering
Introduction to 3D Computer Vision and Differentiable RenderingPreferred Networks
 
Lighting you up in Battlefield 3
Lighting you up in Battlefield 3Lighting you up in Battlefield 3
Lighting you up in Battlefield 3drandom
 
Secrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics TechnologySecrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics TechnologyTiago Sousa
 
Steam presentation deux 3 d prints from photographs
Steam presentation deux  3 d prints from photographsSteam presentation deux  3 d prints from photographs
Steam presentation deux 3 d prints from photographsScott Eastellerson
 
Advanced Lighting for Interactive Applications
Advanced Lighting for Interactive ApplicationsAdvanced Lighting for Interactive Applications
Advanced Lighting for Interactive Applicationsstefan_b
 
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...JP Lee
 
Workflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser gamesWorkflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser gamesMichael Plank
 
Five Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The RunFive Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The RunElectronic Arts / DICE
 
Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...
Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...
Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...Johan Andersson
 
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)Mark Kilgard
 

Ähnlich wie CS 354 Shadows (20)

The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" DemoThe Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
 
Epic_GDC2011_Samaritan
Epic_GDC2011_SamaritanEpic_GDC2011_Samaritan
Epic_GDC2011_Samaritan
 
Deferred shading
Deferred shadingDeferred shading
Deferred shading
 
Shadow Techniques for Real-Time and Interactive Applications
Shadow Techniques for Real-Time and Interactive ApplicationsShadow Techniques for Real-Time and Interactive Applications
Shadow Techniques for Real-Time and Interactive Applications
 
Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...
Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...
Shadow Caster Culling for Efficient Shadow Mapping (Authors: Jiří Bittner, Ol...
 
2008 brokerage 03 scalable 3 d models [compatibility mode]
2008 brokerage 03 scalable 3 d models [compatibility mode]2008 brokerage 03 scalable 3 d models [compatibility mode]
2008 brokerage 03 scalable 3 d models [compatibility mode]
 
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsHPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
 
Introduction to 3D Computer Vision and Differentiable Rendering
Introduction to 3D Computer Vision and Differentiable RenderingIntroduction to 3D Computer Vision and Differentiable Rendering
Introduction to 3D Computer Vision and Differentiable Rendering
 
Lighting you up in Battlefield 3
Lighting you up in Battlefield 3Lighting you up in Battlefield 3
Lighting you up in Battlefield 3
 
Secrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics TechnologySecrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics Technology
 
Steam presentation deux 3 d prints from photographs
Steam presentation deux  3 d prints from photographsSteam presentation deux  3 d prints from photographs
Steam presentation deux 3 d prints from photographs
 
5901194.ppt
5901194.ppt5901194.ppt
5901194.ppt
 
Advanced Lighting for Interactive Applications
Advanced Lighting for Interactive ApplicationsAdvanced Lighting for Interactive Applications
Advanced Lighting for Interactive Applications
 
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
 
Workflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser gamesWorkflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser games
 
AR/SLAM and IoT
AR/SLAM and IoTAR/SLAM and IoT
AR/SLAM and IoT
 
Five Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The RunFive Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The Run
 
Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...
Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...
Frostbite Rendering Architecture and Real-time Procedural Shading & Texturing...
 
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
 
DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3
 

Mehr von Mark Kilgard

D11: a high-performance, protocol-optional, transport-optional, window system...
D11: a high-performance, protocol-optional, transport-optional, window system...D11: a high-performance, protocol-optional, transport-optional, window system...
D11: a high-performance, protocol-optional, transport-optional, window system...Mark Kilgard
 
Computers, Graphics, Engineering, Math, and Video Games for High School Students
Computers, Graphics, Engineering, Math, and Video Games for High School StudentsComputers, Graphics, Engineering, Math, and Video Games for High School Students
Computers, Graphics, Engineering, Math, and Video Games for High School StudentsMark Kilgard
 
NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017Mark Kilgard
 
NVIDIA OpenGL 4.6 in 2017
NVIDIA OpenGL 4.6 in 2017NVIDIA OpenGL 4.6 in 2017
NVIDIA OpenGL 4.6 in 2017Mark Kilgard
 
Virtual Reality Features of NVIDIA GPUs
Virtual Reality Features of NVIDIA GPUsVirtual Reality Features of NVIDIA GPUs
Virtual Reality Features of NVIDIA GPUsMark Kilgard
 
Migrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMigrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMark Kilgard
 
EXT_window_rectangles
EXT_window_rectanglesEXT_window_rectangles
EXT_window_rectanglesMark Kilgard
 
Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...
Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...
Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...Mark Kilgard
 
Accelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware PipelineAccelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware PipelineMark Kilgard
 
NV_path rendering Functional Improvements
NV_path rendering Functional ImprovementsNV_path rendering Functional Improvements
NV_path rendering Functional ImprovementsMark Kilgard
 
OpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsOpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsMark Kilgard
 
SIGGRAPH Asia 2012: GPU-accelerated Path Rendering
SIGGRAPH Asia 2012: GPU-accelerated Path RenderingSIGGRAPH Asia 2012: GPU-accelerated Path Rendering
SIGGRAPH Asia 2012: GPU-accelerated Path RenderingMark Kilgard
 
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and BeyondSIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and BeyondMark Kilgard
 
Programming with NV_path_rendering: An Annex to the SIGGRAPH Asia 2012 paper...
Programming with NV_path_rendering:  An Annex to the SIGGRAPH Asia 2012 paper...Programming with NV_path_rendering:  An Annex to the SIGGRAPH Asia 2012 paper...
Programming with NV_path_rendering: An Annex to the SIGGRAPH Asia 2012 paper...Mark Kilgard
 
GPU accelerated path rendering fastforward
GPU accelerated path rendering fastforwardGPU accelerated path rendering fastforward
GPU accelerated path rendering fastforwardMark Kilgard
 
GPU-accelerated Path Rendering
GPU-accelerated Path RenderingGPU-accelerated Path Rendering
GPU-accelerated Path RenderingMark Kilgard
 
SIGGRAPH 2012: GPU-Accelerated 2D and Web Rendering
SIGGRAPH 2012: GPU-Accelerated 2D and Web RenderingSIGGRAPH 2012: GPU-Accelerated 2D and Web Rendering
SIGGRAPH 2012: GPU-Accelerated 2D and Web RenderingMark Kilgard
 
SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012Mark Kilgard
 
GTC 2012: GPU-Accelerated Path Rendering
GTC 2012: GPU-Accelerated Path RenderingGTC 2012: GPU-Accelerated Path Rendering
GTC 2012: GPU-Accelerated Path Rendering Mark Kilgard
 

Mehr von Mark Kilgard (20)

D11: a high-performance, protocol-optional, transport-optional, window system...
D11: a high-performance, protocol-optional, transport-optional, window system...D11: a high-performance, protocol-optional, transport-optional, window system...
D11: a high-performance, protocol-optional, transport-optional, window system...
 
Computers, Graphics, Engineering, Math, and Video Games for High School Students
Computers, Graphics, Engineering, Math, and Video Games for High School StudentsComputers, Graphics, Engineering, Math, and Video Games for High School Students
Computers, Graphics, Engineering, Math, and Video Games for High School Students
 
NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017
 
NVIDIA OpenGL 4.6 in 2017
NVIDIA OpenGL 4.6 in 2017NVIDIA OpenGL 4.6 in 2017
NVIDIA OpenGL 4.6 in 2017
 
Virtual Reality Features of NVIDIA GPUs
Virtual Reality Features of NVIDIA GPUsVirtual Reality Features of NVIDIA GPUs
Virtual Reality Features of NVIDIA GPUs
 
Migrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMigrating from OpenGL to Vulkan
Migrating from OpenGL to Vulkan
 
EXT_window_rectangles
EXT_window_rectanglesEXT_window_rectangles
EXT_window_rectangles
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...
Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...
Slides: Accelerating Vector Graphics Rendering using the Graphics Hardware Pi...
 
Accelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware PipelineAccelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
 
NV_path rendering Functional Improvements
NV_path rendering Functional ImprovementsNV_path rendering Functional Improvements
NV_path rendering Functional Improvements
 
OpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsOpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUs
 
SIGGRAPH Asia 2012: GPU-accelerated Path Rendering
SIGGRAPH Asia 2012: GPU-accelerated Path RenderingSIGGRAPH Asia 2012: GPU-accelerated Path Rendering
SIGGRAPH Asia 2012: GPU-accelerated Path Rendering
 
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and BeyondSIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
 
Programming with NV_path_rendering: An Annex to the SIGGRAPH Asia 2012 paper...
Programming with NV_path_rendering:  An Annex to the SIGGRAPH Asia 2012 paper...Programming with NV_path_rendering:  An Annex to the SIGGRAPH Asia 2012 paper...
Programming with NV_path_rendering: An Annex to the SIGGRAPH Asia 2012 paper...
 
GPU accelerated path rendering fastforward
GPU accelerated path rendering fastforwardGPU accelerated path rendering fastforward
GPU accelerated path rendering fastforward
 
GPU-accelerated Path Rendering
GPU-accelerated Path RenderingGPU-accelerated Path Rendering
GPU-accelerated Path Rendering
 
SIGGRAPH 2012: GPU-Accelerated 2D and Web Rendering
SIGGRAPH 2012: GPU-Accelerated 2D and Web RenderingSIGGRAPH 2012: GPU-Accelerated 2D and Web Rendering
SIGGRAPH 2012: GPU-Accelerated 2D and Web Rendering
 
SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012
 
GTC 2012: GPU-Accelerated Path Rendering
GTC 2012: GPU-Accelerated Path RenderingGTC 2012: GPU-Accelerated Path Rendering
GTC 2012: GPU-Accelerated Path Rendering
 

Kürzlich hochgeladen

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Kürzlich hochgeladen (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

CS 354 Shadows

  • 1. CS 354 Shadows Mark Kilgard University of Texas March 20, 2012
  • 2. 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
  • 3. 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
  • 4. 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?
  • 5. CS 354 5 On a sheet of paper Daily Quiz • Write your EID, name, and date • Write #1, #2 followed by its answer  Multiple choice: The effective  Multiple choice: Programmable memory bandwidth of a tessellation is good for graphics processor can be higher than its raw memory a) displacement mapping bandwidth due to: b) per-pixel lighting a) more multiply-add operations per clock c) increasing the appearance of surface curvature b) not showing pixels when they are opaque d) feeding more triangles to the graphics pipeline c) domain-specific compression techniques e) a, c, and d d) off-loading work to the f) a, b, c, and d network g) b, c, and d
  • 6. 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
  • 7. CS 354 7 Shadows Provide Cues About Depth  Two scenes  Difference is in shadows Balls resting on ground Balls floating off surface
  • 8. CS 354 8 Computed Shadows aren’t Necessarily Realistic Shadows of Past – Lyubomir Bukov
  • 9. CS 354 9 Shadows in Gaming Shading + Shadows = More Drama + Bump mapping + Specular Only Shadows + Shading Diffuse + Decal Combined + Shadows
  • 10. CS 354 10 Ray Tracing Approach to Shadows  Shadows = global lighting effect  Involves more than light + surface
  • 11. 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
  • 12. CS 354 12 Interactive Lighting 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 L•N)  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
  • 13. CS 354 13 Interactive Shadow Simplications  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
  • 14. CS 354 14 Interactive Shadow Rendering Techniques  Different approaches, different tradeoffs  Shadow maps  Planar projected shadows  Stenciled shadow volumes  Pre-computed shadow textures (light maps)
  • 15. CS 354 15 Common Real-time Shadow Techniques Projected Shadow planar volumes shadows Hybrid approaches Light maps
  • 16. CS 354 16 Projective Texturing Shadow Maps Visualized Without Shadows Projected Shadow Map With Shadows Light’s View Light’s View Depth
  • 17. 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
  • 18. CS 354 18 Shadow Mapping References  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)
  • 19. 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
  • 20. CS 354 20 Shadow Maps for Fine Shadows Chain-link fence is shadow volume nightmare! Chain-link fence’s shadow appears on truck & ground with shadow maps
  • 21. CS 354 21 The Shadow Mapping Concept (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
  • 22. CS 354 22 The Shadow Mapping Concept (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
  • 23. CS 354 23 The Shadow Mapping Concept (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
  • 24. CS 354 24 Shadow Mapping with a picture in 2D  The A < B shadowed fragment case depth map image plane depth map Z = A light source eye position eye view image plane, aka the frame buffer fragment’s light Z = B
  • 25. 25 Shadow Mapping CS 354 with a picture in 2D  The A ≅ B unshadowed fragment case depth map image plane depth map Z = A light source eye position eye view image plane, aka the frame buffer fragment’s light Z = B
  • 26. CS 354 26 Shadow Mapping with a picture in 2D  Note image precision mismatch! The depth map could be at a different resolution from the framebuffer This mismatch can lead to artifacts
  • 27. 27 Avoiding Artifacts with CS 354 Depth 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 much bias, shadow everything begins to starts too far back shadow Just right
  • 28. CS 354 28 Visualizing the Shadow Mapping Technique (1)  A fairly complex scene with shadows the point light source
  • 29. CS 354 29 Visualizing the Shadow Mapping Technique (2)  Compare with and without shadows with shadows without shadows
  • 30. CS 354 30 Visualizing the Shadow Mapping Technique (3)  The scene from the light’s point-of-view FYI: from the eye’s point-of-view again
  • 31. CS 354 31 Visualizing the Shadow Mapping Technique (4)  The depth buffer from the light’s point-of-view FYI: from the light’s point-of-view again
  • 32. CS 354 32 Visualizing the Shadow Mapping Technique (5)  Projecting the depth map onto the eye’s view FYI: depth map for light’s point-of-view again
  • 33. CS 354 33 Shadow Map Eye Linear Texture Coordinate Transform glTexGen automatically xe xo applies this when modelview Eye matrix contains just the eye ye view Modeling yo view transform ze = (look at) matrix zo matrix we wo s 1/2 1/2 Inverse xe Light Light t 1/2 1/2 frustum view eye ye r = (projection) (look at) view ze 1/2 1/2 (look at) matrix matrix q matrix we 1 Supply this combined transform to glTexGen or shader
  • 34. 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]
  • 35. CS 354 35 Visualizing the Shadow Mapping Technique (5)  Projecting the depth map onto the eye’s view FYI: depth map for light’s point-of-view again
  • 36. CS 354 36 Visualizing the Shadow Mapping 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
  • 37. CS 354 37 Visualizing the Shadow Mapping Technique (7)  Comparing light distance to light depth map Green is where the light planar distance and Non-green is the light depth where shadows map are should be approximately equal
  • 38. CS 354 38 Visualizing the Shadow Mapping Technique (8)  Scene with shadows Notice how Notice how specular curved highlights surfaces cast never appear shadows on in shadows each other
  • 39. CS 354 39 More Examples  Smooth surfaces with object self- shadowing Note object self-shadowing
  • 40. CS 354 40 More Examples  Complex objects all shadow
  • 41. CS 354 41 Shadow Mapping Artifacts  Even the floor casts shadow, but… Note shadow leakage due to infinitely thin floor Could be fixed by giving floor thickness
  • 42. CS 354 42 Shadow Map Precision Artifacts  Resolution of rendered depth map determines shadow mapping precision low-resolution sufficient shadow map blockiness shadow map resolution
  • 43. CS 354 43 Four Images of Dueling Frusta Case Eye’s View with projection of color-coded Eye’s mipmap levels View from light: Red = minification Blue = magnification Light’s Light’s View with View re-projection of above image from the eye
  • 44. CS 354 44 Interpretation of the Images of the Dueling Frusta Case Region that is smallest in the light’s view is a region Eye’s that is very large in the View eye’s view. This implies that it would require a very high-resolution shadow map to avoid obvious blocky shadow edge artifacts. Light’s View
  • 45. CS 354 45 Dueling Frusta Blocky Shadow Edge Artifacts Notice that shadow edge is well defined in the distance. Light position out here pointing towards the viewer. Blocky shadow edge artifacts.
  • 46. CS 354 46 Shadow Acne  Ambiguous shadow map comparisons cause very unsightly artifacts  Moiré patterns form; animates poorly “shadow acne” polygon offset depth comparison is provides sufficient depth offset ambiguous for unambiguous depth comparisons
  • 47. CS 354 47 Planar Projected Shadows  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
  • 48. CS 354 48 Projected Planar Shadow Example
  • 49. CS 354 49 Projected Planar Shadows  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
  • 50. CS 354 50 Projected Planar Shadow 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
  • 51. 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
  • 52. CS 354 52 Projected Planar Shadow 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
  • 53. CS 354 53 Planar Projected Shadow Artifacts Bad Good extends off ground region Z fighting double blending
  • 54. CS 354 54 Quick Tutorial on Stencil 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)
  • 55. CS 354 55 Stencil Testing in the Fragment Pipeline Fragment Pixel + Scissor Alpha Ownership Test Test Associated Test Data Depth Stencil Test Test Blending Dithering Logic Frame Op buffer
  • 56. 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 )
  • 57. 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
  • 58. 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
  • 59. CS 354 59 The Shadow Volume Concept  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…
  • 60. CS 354 60 Visualizing Shadow Volumes  Occluder and light projects a shadow volume
  • 61. CS 354 61 Shadow Volume Result  Objects within the volume are shadowed
  • 62. CS 354 62 Shadow Volume Algorithm  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?
  • 63. CS 354 63 2D Cutaway of a Shadow Volume surface outside shadowing shadow volume object (illuminated) light source shadow volume (infinite extent) eye position surface inside partially shadowed shadow volume object (shadowed)
  • 64. CS 354 64 Tagging Pixels as Shadowed 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!
  • 65. CS 354 65 Stencil Inverting of Shadow Volume  Why it works shadowing light object source two inverts, left zero one invert, left one eye zero inverts, left zero position
  • 66. CS 354 66 Visualizing Stenciled Shadow Volume Tagging Shadowed scene Stencil buffer red = stencil value of 1 green = stencil value of 0
  • 67. CS 354 67 Computing Shadow 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
  • 68. CS 354 68 For Shadow Volumes With 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
  • 69. CS 354 69 Why Eye-to-Object Stencil Counting Approach Works Light Shadowing object source zero +1 zero Example in 2D +2 +2 Eye +1 +3 position
  • 70. CS 354 70 Illuminated, Behind Shadow Volumes (Zpass) Light Shadowing object source zero +1 zero + + + - - - Unshadowed object +2 +2 Eye +1 +3 position Shadow Volume Count = +1+1+1-1-1-1 = 0
  • 71. CS 354 71 Shadowed, Nested in Shadow Volumes (Zpass) Light Shadowing object source zero +1 zero + + + - +2 +2 Shadowed Eye +1 object +3 position Shadow Volume Count = +1+1+1-1 = 2
  • 72. CS 354 72 Illuminated, In Front of Shadow Volumes (Zpass) Light Shadowing object source zero +1 zero +2 +2 Shadowed Eye +1 object +3 position Shadow Volume Count = 0 (no depth tests pass)
  • 73. CS 354 73 Shadow Volume Issues  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
  • 74. CS 354 74 Problem Created by Near Clip Plane (Zpass) Missed shadow volume intersection due to near clip plane clipping; leads to mistaken count Far clip plane zero +1 +1 +2 zero +3 +2 Near clip plane
  • 75. CS 354 75 Alternative Approach: Zfail  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
  • 76. CS 354 76 Illuminated, Behind Shadow Volumes (Zfail) Light Shadowing object source zero +1 zero Unshadowed object +2 +2 Eye +1 +3 position Shadow Volume Count = 0 (zero depth tests fail)
  • 77. CS 354 77 Shadowed, Nested in Shadow Volumes (Zfail) Light Shadowing object source zero +1 zero + + +2 +2 Shadowed Eye +1 object +3 position Shadow Volume Count = +1+1 = 2
  • 78. CS 354 78 Illuminated, In Front of Shadow Volumes (Zfail) Light Shadowing object source zero +1 zero - - - + + + +2 +2 Shadowed Eye +1 object +3 position Shadow Volume Count = -1-1-1+1+1+1 = 0
  • 79. CS 354 79 Problem Created by Far Clip Plane (Zfail) Far clip plane Missed shadow volume intersection due to far clip plane clipping; zero leads to mistaken count +1 zero +1 +2 +2 +3 Near clip plane
  • 80. CS 354 80 Problem Solved by Eliminating Far Clip zero +1 +1 +2 +2 +3 Near clip plane
  • 81. 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 when the far plane distance goes to infinity?
  • 82. CS 354 82 Standard glFrustum Projection Matrix  2 × Near Right + Left   Right − Left 0 0  Right − Left    2 × Near Top + Bottom  0 0 P= Top − Bottom Top − Bottom   Far + Near 2 × Far × Near   0 0 − −   Far − Near Far − Near    0 0 −1 0    Only third row depends on Far and Near
  • 83. CS 354 83 Limit of glFrustum Matrix as Far Plane is Moved to Infinity  2 × Near Right + Left   Right − Left 0 0  Right − Left   2 × Near Top + Bottom lim P = Pinf = 0 0  Far →∞  Top − Bottom Top − Bottom   0 0 −1 − 2 × Near      0 0 −1 0    First, second, and fourth rows are the same as in P  But third row no longer depends on Far  Effectively, Far equals ∞
  • 84. 84 Verifying Pinf Will Not Clip CS 354 Infinitely 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
  • 85. 85 Verifying Pinf Will Not Clip CS 354 Infinitely Far Away Vertices (2)  Transform eye-space (0,0,-D,0) to clip-space  2 × Near Right + Left  0 0  xc   xc   Right − Left Right − Left   0   y  y   2 × Near Top + Bottom   0   c  =  c =  0 0    − D   zc   Top − Bottom Top − Bottom  − D       0 0 −1 − 2 × Near     − D   wc     0    0 0 −1 0    Then, assuming glDepthRange(0,1), transform clip- space position to window-space position zc −D z w = 0.5 × + 0.5 = 0.5 × + 0.5 = 1 wc −D  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)
  • 86. 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)
  • 87. 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
  • 88. CS 354 88 Stencil Volume Rendering Animation
  • 89. CS 354 89 Shadow Volumes Add “Invisible” Geometric Complexity Visible geometry Scene with multiple light sources Shadow volume geometry Abducted game images courtesy Joe Riedel at Contraband Entertainment
  • 90. 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
  • 91. CS 354 91 Multiple Lights and Shadow Volumes  Requires still more rendering passes, but can work! Shadows from different light sources overlap correctly
  • 92. CS 354 92 Shadow Volumes from Area 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
  • 93. CS 354 93 Area Light Sources Cast Soft Shadows area light source umbra
  • 94. CS 354 94 Soft Shadow Example  Eight samples (more would be better) Note the banding artifacts
  • 95. CS 354 95 Combined Shadow Approaches  Two Approaches at Once just logo shadow volume logo lacks shadow on the teapot just planar projected teapot lacks shadows shadow on the floor combined approach
  • 96. CS 354 96 Pre-computed Shadow 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
  • 97. CS 354 97 Light maps can encode Static Pre-computed Shadows decal only × (modulate) light maps only = * Id Software’s Quake 2 combined scene circa 1997
  • 98. CS 354 98 Rendering Soft 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
  • 99. CS 354 99 Rendered Soft Shadow Texture Example  Shadow Texture and Final Result Shadow texture, accumulation Final resulting scene, shadow of nine jittered occluder texture modulated with projections wooden floor
  • 100. 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?