Download Shadow Techniques

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Stereo display wikipedia , lookup

Ray tracing (graphics) wikipedia , lookup

2.5D wikipedia , lookup

Rendering (computer graphics) wikipedia , lookup

Transcript
Advanced Computer Graphics
Shadow Techniques
CO2409 Computer Graphics
Week 20
Lecture Contents
1. Basic Shadows
2. Pre-calculated Shadows
3. Shadow Mapping
Basic Shadows
• Shadows in a scene to help resolve
the relative positions of models
– Naive mistake to think that shadows
happen automatically with lighting
• A couple of basic techniques have
long been used:
Positions Ambiguous?
– 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
Shadows Resolve
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 draw
attention to themselves:
– Sharp edges / too stark, problems in
complex cases
• In wide-open areas, shadows will tend
to blur towards blobs in any case
– Viewer may not notice / appreciate better
accuracy
Basic Shadows are
still widely used
Pre-calculated Shadows
• However, improved shadows can give a better sense of
space and/or atmosphere
• Can pre-calculate light / shadows for the static models and
lights in the scene
• Commonly used are static
shadow maps / lightmaps
– Light / shadow textures applied over
the main model textures
• The maps are pre-calculated
– Using high-quality techniques
• Sometimes called baking the
shadows / lighting
Lightmass from Unreal 3
Tool to bake shadow / lightmaps
Static Shadows / Dynamic Models
• Baked shadows work well for
static environments
– High quality, generated offline
• Dynamic models also need to be
affected by these shadows
• So store samples of the static
lighting at points where dynamic
models will be
– Both on the floor and in the air
• Model uses local static lighting
samples to affect how it is lit
Dynamic Shadow Mapping
• We also need to cast shadows from dynamic models
• Dynamic Shadow Mapping is an extension of render-to
texture 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 rendered
normally, but each pixel first
tested against shadow map
– The pixel is not lit if it is in shadow
from the light
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
• Render the scene from the light’s
point of view
– Treat the light like a camera
• For each pixel, render the
distance at that pixel only
– Result is a like a depth buffer for the
scene from the light’s point of view
– Sometimes called a light map or
(confusingly) a shadow map
Shadow Mapping Method
• After creating a textures for each light’s point of view, we
next render the scene normally
– Using an extra step to find shadowed areas
• In this main render step, we check the pixel’s visibility
from 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 distance
from 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
Determining if the red
pixel is in shadow from
the white light
It is – the troll’s head is
in the way. The red pixel
is hidden in the light map
Shadow Mapping Detail 1
• To treat a light as a camera, we need a view & projection
matrix 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 each
of the world axis directions
– A FOV of 90° for each one
– This is an example of a cube map
Point Light = 6 Cameras
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
– Don’t need FOV
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 and
compared depth
– Other solutions illustrated in lab