Post on 18-Dec-2015
1
Dr. Scott Schaefer
Shadows
2/40
Shadows
Shadows provide clues about depth Make scenes appear
more realistic
3/40
Shadows
Shadows provide clues about depth Make scenes appear
more realistic
4/40
Shadow Algorithms
Simple/Planar Shadows Shadow Maps Shadow Volumes
5/40
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
6/40
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
7/40
Shadow Maps
8/40
Shadow Maps
Render scene from light’s perspective
9/40
Shadow Maps
Render scene from light’s perspective
Shadow Map
10/40
Shadow Maps
Render scene from light’s perspective Render scene from
viewer’s perspective
11/40
Shadow Maps
Render scene from light’s perspective Render scene from
viewer’s perspective For every pixel
Transform to world space
Compare distanceto value in shadow map
12/40
Shadow Maps
Render scene from light’s perspective Render scene from
viewer’s perspective For every pixel
Transform to world space
Compare distanceto value in shadow map
13/40
Shadow Maps
Render scene from light’s perspective Render scene from
viewer’s perspective For every pixel
Transform to world space
Compare distanceto value in shadow map
In shadow!
14/40
Shadow Maps
Render scene from light’s perspective Render scene from
viewer’s perspective For every pixel
Transform to world space
Compare distanceto value in shadow map
In shadow!
15/40
Shadow Maps
Render scene from light’s perspective Render scene from
viewer’s perspective For every pixel
Transform to world space
Compare distanceto value in shadow map
Not in shadow!
16/40
Shadow Maps
Image taken from http://www.cse.ohio-state.edu/~haleyb/Hardware/ggDepthBuffer.jpg
17/40
Shadow Maps
AdvantagesSimple to implementDoes not depend on scene complexity
(except to render shadow map) Disadvantages
Fixed resolution image leads to artifactsOmni-directional light sources require 6
shadow maps to cover every direction
18/40
Perspective Shadow Maps
Shadow maps are limited by screen resolution and depend on object distance!
Small distance
19/40
Perspective Shadow Maps
Shadow maps are limited by screen resolution and depend on object distance!
Huge distance
20/40
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”
21/40
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”
22/40
Anatomy of a Shadow
Shadowingobject
Partiallyshadowed object
Lightsource
Eye position
(note that shadows are independent of the eye position)
Surface insideshadow volume
(shadowed)
Surface outsideshadow volume
(illuminated)
Shadowvolume
(infinite extent)
23/40
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”
24/40
Shadow Volumes
Shadowing object Lightsource
Eyeposition
25/40
Shadow Volumes
Shadowing object Lightsource
zero
zero
+1
+1+2 +2
+3Eyeposition
26/40
Shadow Volumes
Shadowing object Lightsource
zero
zero
+1
+1+2 +2
+3Eyeposition
Unshadowedobject
+ ---+ +
Shadow Volume Count = +1+1+1-1-1-1 = 0
27/40
Shadow Volumes
Shadowing object Lightsource
zero
zero
+1
+1+2 +2
+3
Shadowedobject
+ -+ +
Shadow Volume Count = +1+1+1-1 = 2
Eyeposition
28/40
Shadow Volumes
Shadowing object Lightsource
zero
zero
+1
+1+2 +2
+3
Unshadowedobject
Shadow Volume Count = 0
Eyeposition
29/40
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”
30/40
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
Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
Stencil value 1
Stencil value 0
31/40
Shadow Volumes: Examples
Images taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
32/40
Shadow Volumes: Examples
Image taken from “Doom 3”
33/40
Problems with Shadow Volumes
zero
zero
+1+1
+2
+2
+3
Near clipplane
Far clipplane
34/40
Problems with Shadow Volumes
zero
zero
+1+1
+2
+2
+3
Near clipplane
Far clipplane
Missed shadow volume intersection due to near clip plane clipping; leads to mistaken count
35/40
Problems with Shadow Volumes
Shadowing object Lightsource
Shadow test fails!
Shadow Volume Count = 0
Eyeposition
36/40
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
37/40
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
38/40
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
39/40
Soft Shadows
Simulate area lights with lots of points lights
Image taken from “Practical & Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering”
Expensive
The cluster of point lights.
40/40
Soft Shadows
Simulate area lights with lots of points lights Blur shadows in image space
http://www.gamedev.net/reference/articles/article2193.asp
Cheap, inaccurate
41/40
42/40
Solution: Invert Depth Test
Shadowing object Lightsource
Shadowed object
Shadow Volume Count = -1+1-1=-1
Eyeposition
- +
-
43/40
Solution: Invert Depth Test
Shadowing object Lightsource
Shadowed object
Shadow Volume Count = -1+1-1=-1
Eyeposition
- +
-Now have problem
with far clipping plane