Advanced Computer GraphicsShadow Techniques
Advanced Computer GraphicsShadow Techniques
CO2409 Computer Graphics
Week 20
Lecture Contents
Lecture Contents
1.Basic Shadows
2.Pre-calculated Shadows
3.Shadow Mapping
Basic Shadows
Basic Shadows
Shadows in a scene to help resolvethe relative positions of models
Naive mistake to think that shadowshappen automatically with lighting
A couple of basic techniques havelong been used:
Draw a “blob” under a model
Draw the model flattened (scaled to 0 inY) on the floor
Can project straight down or away fromthe light
Both methods require a flat floor towork correctly
ResolveShadows1
ResolveShadows2
Positions Ambiguous?
Shadows Resolve
Basic Shadows
Basic Shadows
These methods are still frequently used, why?
Basic methods are enough to resolve model positions
Very cheap techniques – good when many models
More advanced techniques are complex and slow
Advanced techniques often drawattention to themselves:
Sharp edges / too stark, problems incomplex cases
In wide-open areas, shadows will tendto blur towards blobs in any case
Viewer may not notice / appreciate betteraccuracy
ResolveShadows2
Basic Shadows arestill widely used
Pre-calculated Shadows
Pre-calculated Shadows
However, improved shadows can give a better sense ofspace and/or atmosphere
Can pre-calculate light / shadows for the static models andlights in the scene
Commonly used are staticshadow maps / lightmaps
Light / shadow textures applied overthe main model textures
The maps are pre-calculated
Using high-quality techniques
Sometimes called baking theshadows / lighting
BakedShadows
Lightmass from Unreal 3
Tool to bake shadow / lightmaps
Static Shadows / Dynamic Models
Static Shadows / Dynamic Models
Baked shadows work well forstatic environments
High quality, generated offline
Dynamic models also need to beaffected by these shadows
So store samples of the staticlighting at points where dynamicmodels will be
Both on the floor and in the air
Model uses local static lightingsamples to affect how it is lit
StaticLightSamples
ModelStaticLit
Dynamic Shadow Mapping
Dynamic Shadow Mapping
We also need to cast shadows from dynamic models
Dynamic Shadow Mapping is an extension of render-totexture techniques used for shadows
Also called perspective shadow mapping (PSM)
Or more commonly, just shadow mapping
The scene is rendered to a texture (a shadow map), from
the point of view of the light
Then the scene is renderednormally, but each pixel firsttested against shadow map
The pixel is not lit if it is in shadowfrom the light
ShadowMapping1
Shadow Mapping Method
Shadow Mapping Method
Create a render target texture for each light:
Each “pixel” in the texture is a single floating-point value
Instead of four R,G,B & A values
This is a floating-point texture
ShadowMapEx1
Render the scene from the light’spoint of view
Treat the light like a camera
For each pixel, render thedistance at that pixel only
Result is a like a depth buffer for thescene from the light’s point of view
Sometimes called a light map or(confusingly) a shadow map
Shadow Mapping Method
Shadow Mapping Method
After creating a textures for each light’s point of view, wenext render the scene normally
Using an extra step to find shadowed areas
In this main render step, we check the pixel’s visibilityfrom each light before applying lighting to it:
Find the distance from the pixel we’re rendering to the light
Also find where this pixel would appear in the light’s depth map
Find the distance stored in the light’s depth map at that point
If the distance stored in the map is less than the actual distancefrom pixel to light, then something is obscuring the pixel
The pixel in shadow from this light
This condition determines whether the pixel gets a diffuse /specular contribution from this light or not
Repeat for all lights on this pixel
Shadow Mapping Diagram
Shadow Mapping Diagram
ShadowMapEx2
ShadowMapEx3
Determining if the redpixel is in shadow fromthe white light
It is – the troll’s head isin the way. The red pixelis hidden in the light map
CubeMap
Shadow Mapping Detail 1
Shadow Mapping Detail 1
To treat a light as a camera, we need a view & projectionmatrix for it
So we need: position, orientation, FOV and near / far clip planes
A spotlight is the simplest case:
Already has a position and facing direction – can make view matrix
Has a field of view (FOV) for projection matrix
A point light shines in all directions
We make six cameras pointing in eachof the world axis directions
A FOV of 90° for each one
This is an example of a cube map
Point Light = 6 Cameras
Orthogonal
Shadow Mapping Detail 2
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 lightvery far away – outside the scene
Solve the second by using anorthogonal projection matrix
Project vertices from 3D to 2Dalong parallel lines
Not towards camera point like standardperspective projection
Don’t need FOV
Shadow Mapping Issues
Shadow Mapping Issues
Shadow mapping has two key problems:
Texels of shadow map may be visible, affects shadow quality
Polygons sometimes self-shadow
Increase shadow map resolution for better quality
But lower performance, increased memory
Better to adapt resolution based on distance from viewer
Good idea to blur or soften the shadows / map
Many methods here, e.g. Variance Shadow Mapping
Self-shadowing resolved by tweaking calculated andcompared depth
Other solutions illustrated in lab