Advanced Computer Graphics Shadow Techniques - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Advanced Computer Graphics Shadow Techniques

Description:

Other solutions illustrated in lab. Stencil Shadows ... Actually, idea from video card companies (NVidia / Creative Labs) Finding Silhouettes ... – PowerPoint PPT presentation

Number of Views:101
Avg rating:3.0/5.0
Slides: 23
Provided by: lauren80
Category:

less

Transcript and Presenter's Notes

Title: Advanced Computer Graphics Shadow Techniques


1
Advanced Computer GraphicsShadow Techniques
  • CO2409 Computer Graphics
  • Week 18

2
Lecture Contents
  • Basic Shadows
  • Pre-calculated Shadows
  • Shadow Mapping
  • Stencil Shadows

3
Basic Shadows
  • Shadows in a scene to help resolve the relative
    positions of models
  • A couple of basic techniques have long been used
  • Draw a blob under a model
  • Draw the model flattened (scaled to 0 in Y) on
    the floor
  • Can project straight down or away from the light
  • Both methods require a flat floor to work
    correctly

Positions Ambiguous?
Shadows Resolve
4
Basic Shadows
  • These methods are still frequently used, why?
  • Basic methods enough to resolve model positions
  • Very cheap techniques good when many models
  • More advanced techniques are complex and slow
  • Advanced techniques often draw attention to
    themselves
  • Sharp edges / too stark, problems in complex
    cases
  • In open areas, shadows tend to blur towards blobs
    in any case
  • Viewer may not notice / appreciate better accuracy

5
Pre-calculated Shadows
  • However, improved shadows can give a better sense
    of space and/or atmosphere
  • When used appropriately
  • If we have static models and lights, we can
    pre-calculate the lighting in the scene
  • A standard technique has been to use static
    shadow maps
  • Darkening textures applied over the main model
    textures
  • The maps are pre-calculated
  • Often using radiosity methods
  • Allows for subtle lighting effects

6
Pre-calculated Shadows
  • More recent techniques perform an offline
    mathematical simulation of light transfer in a
    scene
  • Reflections, refractions and transmission
  • One example of this technique is Pre-computed
    Radiance Transfer (PRT)
  • This results in a set of equations to calculate
    both lighting shadows to be computed in
    real-time
  • Allows for dynamic lights
  • And often some measure of model movement
  • No model/model interaction

7
Dynamic Shadow Mapping
  • Dynamic Shadow Mapping is an extension of
    render-to texture techniques used for shadows
  • Also called perspective shadow mapping (PSM) or
    just shadow mapping
  • The scene is rendered into a texture (a shadow
    map), but from the point of view of the light
  • Then the scene is rendered normally, but each
    pixel first tested against shadow map
  • The pixel is not lit if it is in shadow from the
    light

8
Shadow Mapping Method 1
  • Create a render target texture for each light
  • Each pixel in the texture is a single float
    value
  • Not four R,G,B A values
  • This is a floating-point texture. It will be the
    shadow map for the light
  • Render the scene from the lights point of view
  • Need to treat the light like a camera
  • Result is effectively a depth buffer for the
    scene

9
Shadow Mapping Method 2
  • Now render the scene normally
  • But with an extra step to find shadowed areas
  • After transforming each pixel, check its
    visibility from each light before lighting it
  • Find depth of the pixel as seen from light
  • Also transform the pixel into the lights
    viewport space to get depth stored in shadow map
  • If the depth in the shadow map is less than the
    depth of the pixel, then something is obscuring
    the pixel and it must be in shadow
  • Otherwise light it as normal

10
Shadow Mapping Diagram
11
Shadow Mapping Detail 1
  • To treat a light as a camera, we need a view and
    projection matrix for it
  • A spotlight is the simplest case with a position
    and a field of view (FOV) already
  • A point light shines in all directions
  • We render six images in a cube around the light
  • FOV of 90 for each one
  • An example of a cube map

12
Shadow Mapping Detail 2
  • A directional light poses two problems
  • No position as a camera. No FOV to use
  • Solve first problem by positioning the
    directional light very far away outside the
    scene
  • Solve the second by using an orthogonal
    projection matrix
  • Project vertices from 3D to 2D along parallel
    lines
  • Not towards camera point like standard
    perspective projection
  • Dont need FOV

13
Shadow Mapping Issues
  • Shadow mapping has two key problems
  • Texels of shadow map can be clearly visible
  • Polygons sometimes self-shadow
  • Increase shadow map resolution for better quality
  • But lower performance, increased memory
  • Better, blur or soften the shadows / map
  • Many methods here
  • Self-shadowing resolved by tweaking calculated
    and compared depth
  • Other solutions illustrated in lab

14
Stencil Shadows
  • Another method for real-time shadows is Stencil
    Shadows, an advanced stencil buffer technique
  • Stencil shadows gained great interest because of
    their much-hyped use in the game Doom3 (2003)
  • But they have a longer history
  • Shadow volumes first discussed by Frank Crow
    (1977)
  • Stencil buffer use proposed by Tim Heidmann
    (1991)
  • Used extensively Severance Blade of Darkness
    (1999)

15
Stencil Shadows Process 1
  • Render scene with ambient light only
  • For each light
  • Find silhouette of each model from the light
  • Extrude silhouette to make shadow volume
  • Render shadow volume using stencil buffer only
  • Result is non-zero stencil values where shadow
    intersects with scene (explained later)

16
Stencil Shadows Process 2
  • For each light (continued)
  • Render entire scene using only this light but
    only render if stencil is zero (not in shadow)
  • Add the result colour to the existing colour
  • Each lights contribution will be accumulated
    onto the basic ambient light to give final result



17
Stencil Operation Depth Pass
  • Shadow volumes only drawn in the stencil buffer
  • No colour or depth output
  • But the depth buffer is tested
  • Render in two passes
  • Pass 1 Render back faces, increasing the stencil
    buffer values for each visible pixel
  • Pass 2 Render front faces, decreasing the
    stencil buffer values for each visible pixel
  • This is the depth-pass method (stencil updated
    where pixels pass the depth test i.e. visible)
  • Diagrams follow

18
Depth-Pass - Diagrams
  • Depth-Pass Shadow Volumes
  • Front Faces 1
  • Back Faces -1
  • Result ! 0 in shadow

Problem with Depth-Pass Camera in Shadow Volume
19
Depth-Fail
  • Depth pass has problems instead use depth-fail
  • Pass 1 Render back faces, increasing the stencil
    buffer values for each non-visible pixel
  • Pass 2 Render front faces, decreasing the
    stencil buffer values for each non-visible pixel
  • Called Carmacks Reverse due to John Carmacks
    use in Doom3
  • Actually, idea from video card companies (NVidia
    / Creative Labs)

20
Finding Silhouettes
  • To create the shadow volume we need to find the
    silhouette of the model wrt the light
  • The edges to extrude
  • Can do this at run-time by comparing normals of
    adjacent faces with the light vector
  • If one points away and the other towards then we
    have a silhouette edge
  • Then dynamically create a shadow volume from the
    found edges
  • This can be expensive
  • CPU time dynamic resource creation

21
Pre-calculated Shadow Models
  • Instead we can create a special shadow model
    associated with each model
  • Copy the base model, but make the vertices in
    each face unique and set all vertex normals
    face normals
  • Replace every edge in the model with a infinitely
    thin quad (pair of triangles)
  • Doesnt change the model shape

Inserted quads shown stretched out for clarity
actually infinitely thin
22
Pre-calculated Shadow Models
  • Use a vertex shader to extrude the shadow model
    vertices that point away from the light
  • They will stretch out the quad-edges behind them,
    forming the required shadow volume
Write a Comment
User Comments (0)
About PowerShow.com