程序代写代做代考 10: The OpenGL Pipeline

10: The OpenGL Pipeline

13: Real Time
Shadow Mapping

COMP5822M: High Performance Graphics
Types of Shadows
Shadow Rays
Local Illumination
Projected Shadows
Shadow Maps
currently standard
Shadow Volumes
coming back

COMP5822M: High Performance Graphics
Hard & Soft Shadows
Point sources cast a hard shadow – the umbra
Area sources cast a soft shadow – the penumbra
Raytracing handles both cleanly

COMP5822M: High Performance Graphics

Projected Shadows
Render each object twice
Once properly lit
Once projected to the ground (the umbra)
Use stencil buffer to mask out other areas
Fails for self-shadows & multiple surfaces

COMP5822M: High Performance Graphics
Shadow Volumes
For each triangle
Compute a pyramid
Out to infinity
The shadow volume
Defined by 3 quads
For point P, count # of shadow volumes it is in

P

COMP5822M: High Performance Graphics
Shadow Volume Counting
Along a ray
Increment on entry to volume (front face)
Decrement on exit to volume (back face)

0

+2

+
+

COMP5822M: High Performance Graphics
Stencil Buffer Solution
Clear stencil buffer
Draw ambient / emissive
Turn off z-buffer updates
But leave testing on
Z- Buffer holds depth of closest surface
Turn off colour writing (we’re done with it)

0

+2
+
+

COMP5822M: High Performance Graphics
Shadow Stencil Render
Set stencil operation to increment
Render shadow front faces
Set stencil operation to decrement
Render shadow back faces
Shadow faces behind fragment are ignored
Stencil ends up with correct count
Render diffuse & specular where stencil is 0

COMP5822M: High Performance Graphics
Shadow Stencil Problems
Viewer is inside shadow volume
Shadow count is incorrect
Near plane of frustum intersects volume
Shadow count is incorrect
Traditional solution: cap objects
i.e. cut through & add polygons

COMP5822M: High Performance Graphics
Variation: Z-Fail
We counted shadows in front of object
Flip it and count shadows behind object
Test is still for non-0 count
Requires capping at far plane
And it runs slower than Z-Pass

COMP5822M: High Performance Graphics
Depth Clamping
Can be resolved with depth clamping
Everitt and Kilgard 2002 http://staatsmacht.org/Veranstaltungen/Interaktive%20Computergraphik%20(Stamminger)/papers/08_Everitt,Kilgard-PracticalAndRobustStenciledShadowVolumesForHardwareAcceleratedRendering-2002.pdf
Morgan McGuire et al. http://www.nvidia.co.uk/object/fast_shadow_volumes.html
Supported by NV_depth_clamp extension

COMP5822M: High Performance Graphics
Downside: Fill Rate
Shadow Volumes burn your poly count
Each triangle generates 3 quads

COMP5822M: High Performance Graphics
Vertex Shader Volumes
Send edges as degenerate quads
Use vertex shader to expand

COMP5822M: High Performance Graphics
Render shadow to texture
Use texture as a light map
Best for static light & objects
Can also render soft shadows to texture
Texture can be reused between frames
Which is good because shadows are expensive
Shadow Textures

COMP5822M: High Performance Graphics
Rendering to Texture
How do we render to texture?
Recall that the texture is in
Our texture coordinates should be unique
So we render the triangles using (u,v) coords
Note special case at boundary
We will want one vertex, two or more coords
And two or more attributes

COMP5822M: High Performance Graphics
Rendering to Texture

A
B

Object in
C
D
Object in
A
A
A
B
C
D

COMP5822M: High Performance Graphics
Soft Shadows
Approximation of area lights
Monte Carlo sample points on the light
Render image for each point
Average the images to get soft shadow

COMP5822M: High Performance Graphics
Shadows & Curved Surfaces
Generalise this one step further
We want a texture showing what is in shadow
A shadow map
Need to compute this
Once per light source
Once per object
Simple idea, expensive in practice

COMP5822M: High Performance Graphics
Optimising Shadow Maps
Can we compute one map per object?
It won’t capture lighting coefficients
Unless all lights are identical, non-specular
Instead, we compute one map per light source
But this means a shared set of texture coords
Which we can compute on the fly
We will call them shadow coords (SCS)

COMP5822M: High Performance Graphics
Shadow Maps

Light’s view
(Shadow Map)
Camera’s view

COMP5822M: High Performance Graphics
Coordinate Systems

Object
World
View
Clipping
Norm
Device
Light
Clip (L)
Norm (L)
Shadow

COMP5822M: High Performance Graphics

Shadow Map
Camera’s view
Depth Comparison
A fragment is in shadow if its depth is greater than the corresponding depth value in the shadow map
Render depth image from light

COMP5822M: High Performance Graphics
Shadow Map Vertex Shader

COMP5822M: High Performance Graphics
Main Pass Vertex Shader

COMP5822M: High Performance Graphics
Main Pass Vertex Shader II

COMP5822M: High Performance Graphics
Main Pass Fragment Shader

COMP5822M: High Performance Graphics
Main Pass Fragment Shader

COMP5822M: High Performance Graphics

Pros & Cons
Very fast in practice
But aliased at close range
Especially for large scenes
And biased
Causes shadow acne
from viewpoint
from light

COMP5822M: High Performance Graphics

Shadow Acne

Several methods for tackling bias
Wang and Molnar http://www.cs.unc.edu/techreports/94-019.pdf
Weiskopf and Ertl http://129.69.215.162/~weiskopf/publications/eg03short.pdf

COMP5822M: High Performance Graphics
Shadow Map Aliasing
Filtering causes artifacts
Magnification: large shadow texels
Minification: multiple texels per pixel

COMP5822M: High Performance Graphics
Minification
Trilinear / Anisotropic filtering unsuitable
Hardware averages the depth values
Instead, use:
Percentage-Closer Filtering (PCF)
Variance Shadow Maps

COMP5822M: High Performance Graphics
Percentage-Closer Filtering
Project screen-space pixels into shadow map
Resample resulting area & integrate
For each sample, perform depth comparison
Then compute %age that are shadowed
Use this as to attenuate the light

COMP5822M: High Performance Graphics
PCF Problems
May need many samples
Shallow angles worst
Can’t use mipmaps
They average depth comparisons

COMP5822M: High Performance Graphics
Variance Biasing
Use second moment (like standard deviation)
to represent depth extent
Collapses to squared depth when surface parallel to light projection plane

COMP5822M: High Performance Graphics
Variance Shadow Maps
Store the depth and depth squared
Use them to compute depth moments
Find upper bound on probability of occlusion

COMP5822M: High Performance Graphics
Result: Linear Filtering
This allows mipmapping, trilinear/anisotropic

COMP5822M: High Performance Graphics
Light Bleeding
Variance shadow maps are probabilistic
You get some light where it shouldn’t be
Can only solve this with more samples

COMP5822M: High Performance Graphics
Summed-Area Variance
Define a summed area variance table
This was originally used to accelerate filtering

COMP5822M: High Performance Graphics
SA Variance Shadow Maps
Allows hard & soft shadows
Reduces visible aliasing

COMP5822M: High Performance Graphics
PCF Soft Shadows
Sample near texel to find blocker depth
Use this to estimate penumbra size
Filter shadows with summed-area variance

COMP5822M: High Performance Graphics