430 likes | 446 Views
Shadows. Dr. Scott Schaefer. Shadows. Shadows provide clues about depth Make scenes appear more realistic. Shadows. Shadows provide clues about depth Make scenes appear more realistic. Shadow Algorithms. Simple/Planar Shadows Shadow Maps Shadow Volumes. Simple/Planar Shadows.
E N D
Shadows Dr. Scott Schaefer
Shadows • Shadows provide clues about depth • Make scenes appear more realistic
Shadows • Shadows provide clues about depth • Make scenes appear more realistic
Shadow Algorithms • Simple/Planar Shadows • Shadow Maps • Shadow Volumes
Simple/Planar Shadows • Projection of an object onto a planar surface (floor/wall) • Build projection matrix from light to wall • Draw object in black using projection matrix Image taken from http://developer.nvidia.com/object/robust_shadow_volumes.html
Simple/Planar Shadows • Fast and simple • Does not account for self-shadowing • Only works for planar surfaces (nothing else has shadows cast on it) Image taken from http://developer.nvidia.com/object/robust_shadow_volumes.html
Shadow Maps • Render scene from light’s perspective
Shadow Maps • Render scene from light’s perspective Shadow Map
Shadow Maps • Render scene from light’s perspective • Render scene from viewer’s perspective
Shadow Maps • Render scene from light’s perspective • Render scene from viewer’s perspective • For every pixel • Transform to world space • Compare distance to value in shadow map
Shadow Maps • Render scene from light’s perspective • Render scene from viewer’s perspective • For every pixel • Transform to world space • Compare distance to value in shadow map
Shadow Maps • Render scene from light’s perspective • Render scene from viewer’s perspective • For every pixel • Transform to world space • Compare distance to value in shadow map In shadow!
Shadow Maps • Render scene from light’s perspective • Render scene from viewer’s perspective • For every pixel • Transform to world space • Compare distance to value in shadow map In shadow!
Shadow Maps • Render scene from light’s perspective • Render scene from viewer’s perspective • For every pixel • Transform to world space • Compare distance to value in shadow map Not in shadow!
Shadow Maps Image taken from http://www.cse.ohio-state.edu/~haleyb/Hardware/ggDepthBuffer.jpg
Shadow Maps • Advantages • Simple to implement • Does not depend on scene complexity (except to render shadow map) • Disadvantages • Fixed resolution image leads to artifacts • Omni-directional light sources require 6 shadow maps to cover every direction
Perspective Shadow Maps • Shadow maps are limited by screen resolution and depend on object distance! Small distance
Perspective Shadow Maps • Shadow maps are limited by screen resolution and depend on object distance! Huge distance
Perspective Shadow Maps • Distort viewing transformation from light’s perspective to create a more uniform sampling from viewer’s perspective Image taken from “Perspective Shadow Maps”
Perspective Shadow Maps • Distort viewing transformation from light’s perspective to create a more uniform sampling from viewer’s perspective Image taken from “Perspective Shadow Maps”
Anatomy of a Shadow Surface outsideshadow volume (illuminated) Shadowingobject Lightsource Shadowvolume (infinite extent) Eye position (note that shadows are independent of the eye position) Surface insideshadow volume (shadowed) Partially shadowed object
Shadow Volumes • Build polygons for shadow volumes explicitly • Render shadow volume polygons from viewer’s perspective and count inside/outside shadows Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
Eyeposition Shadow Volumes Lightsource Shadowing object
Eyeposition Shadow Volumes Lightsource Shadowing object zero +1 zero +2 +2 +1 +3
+ + + Eyeposition - - - Shadow Volumes Lightsource Shadowing object zero +1 zero Unshadowedobject +2 +2 +1 +3 Shadow Volume Count = +1+1+1-1-1-1 = 0
+ + + Eyeposition - Shadow Volumes Lightsource Shadowing object zero +1 zero Shadowedobject +2 +2 +1 +3 Shadow Volume Count = +1+1+1-1 = 2
Eyeposition Shadow Volumes Lightsource Shadowing object zero +1 zero Unshadowedobject +2 +2 +1 +3 Shadow Volume Count = 0
Implementing Shadow Volumes • For each surface, find silhouette edges • Build shadow volume (viewer independent) by extending away from light Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
Implementing Shadow Volumes • Use stencil buffer to count intersections with shadow volume • Render front faces and increment if closer to viewer • Render back faces and decrement if closer to viewer • Don’t update color or depth values!!!! • If stencil buffer is non-zero, then pixel in shadow Stencil value 1 Stencil value 0 Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
Shadow Volumes: Examples Images taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
Shadow Volumes: Examples Image taken from “Doom 3”
Problems with Shadow Volumes Far clipplane zero +1 +1 +2 zero +3 +2 Near clipplane
Problems with Shadow Volumes Missed shadow volume intersection due to near clip plane clipping; leads to mistaken count Far clipplane zero +1 +1 +2 zero +3 +2 Near clipplane
Eyeposition Problems with Shadow Volumes Lightsource Shadowing object Shadow test fails! Shadow Volume Count = 0
Shadow Volumes • Advantages • Omni-directional light sources • Proper self-shadowing behavior • Pixel perfect shadows • Disadvantages • Surfaces can only use planar polygons • Silhouette computation uses CPU • Heavy on fill-rate • Near/Far clipping planes lead to problems
Soft Shadows • Point lights cause hard shadows • Lights are not infinitely small points in reality • Area light sources cause soft shadows http://graphics.ucsd.edu/~henrik/images/cbox.html
Soft Shadows • Point lights cause hard shadows • Lights are not infinitely small points in reality • Area light sources cause soft shadows http://graphics.ucsd.edu/~henrik/images/cbox.html
Soft Shadows • Simulate area lights with lots of points lights Expensive The cluster of point lights. Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
Soft Shadows • Simulate area lights with lots of points lights • Blur shadows in image space Cheap, inaccurate http://www.gamedev.net/reference/articles/article2193.asp
+ Eyeposition - - Solution: Invert Depth Test Lightsource Shadowing object Shadowed object Shadow Volume Count = -1+1-1=-1
+ Eyeposition - - Solution: Invert Depth Test Lightsource Shadowing object Now have problem with far clipping plane Shadowed object Shadow Volume Count = -1+1-1=-1