Download Image-Space Shadow Mapping: A Technique for Adding Realistic Shadows in Computer Graphics and more Study notes Computer Science in PDF only on Docsity!
Shadows
Thanks to:
Frédo Durand
and Seth Teller
MIT
Shadows
Shadows as depth cue
Spatial relationship between objects
Michael McCool Univ of Waterloo
Spatial relationship between objects
Michael McCool Univ of Waterloo (^6)
Spatial relationship between objects
Michael McCool Univ of Waterloo
Spatial relationship between objects
Michael McCool Univ of Waterloo (^8)
Spatial relationship between objects
Michael McCool Univ of Waterloo
without with
Shadows add visual acuity
Shadows and art
- Only in Western pictures (here Caravaggio)
Shadows and art
of painting
Duality shadow-view
- A point is lit if it is visible from the light source
- Shadow computation very similar to view computation
Planar Projection
• Render a ground-plane
• Render an object Render an object
• Then render the object again, but this time
– Projected onto the plane
– Without light, so that the shadow is black
– Half transparent (using blending), to avoid
completely dark shadows
– Avoid multiple “darkening” on one spot by using
ordinary z-buffer checks
Projected Geometry
• [Blinn88] Me and my fake shadow
– Shadows for selected large receiver polygons
Projected Geometry
• Example: xz plane at y=
y y
yz z y z
y y
yx xy x
l v
lv lv
p
l v
lv lv
p
Projected Geometry
• Transformation as 4 by 4 matrix
z
y
x
y
z y
y x
v
v
v
l
l l
l l
p
r
Projected Geometry
• General case: receiver polygon in plane E
• 4x4 matrix (see Blinn)
v l
n v l
d n l
p l
E n x d
v^ v
v v v
v v
v v
v v
Projected Geometry
• Basic algorithm
– Render scene (full lighting)
– For each receiver polygon
- Compute projection matrix M
- Mult with actual transformation (modelview)
- Render selected (occluder) geometry
Planar Shadows
Shadow is projected into the plane of the floor. 26
Constructing a Shadow Matrix
void shadowMatrix(GLfloat shadowMat[4][4], GLfloat groundplane[4], GLfloat lightpos[4]) { GLfloat dot; / Find dot product between light position vector and ground plane normal. / dot = groundplane[X] * lightpos[X] + groundplane[Y] * lightpos[Y] + groundplane[Z] * lightpos[Z] + groundplane[W] * lightpos[W]; shadowMat[0][0] = dot - lightpos[X] * groundplane[X]; shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y]; shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z]; shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W]; shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X]; shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y]; shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z]; shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W]; shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X]; shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y]; shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z]; shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W]; shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X]; shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y]; shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z]; shadowMat[3][3] = dot - lightpos[W] * groundplane[W]; }
How to add shadows?
- Can be done in two ways:
- 1st^ method: Full illumination + darkening
FB = DiffuseTex0 * ( Light0 + Light1 + Light2… ) if pixel is in shadow (with respect to Light0) FB = FB * 0.
This is wrong since the contribution of Light1,2 etc. is also affected!
How to add shadows?
- 2 nd^ & correct method: Use mask for each light
FB = DiffuseTex0 * ( Light0 * Mask0 + Light1 * Mask1 +
Light2 * Mask2… )
Mask values
- 0 if pixel is in shadow (with respect to Light X)
- 1 if pixel is lit by Light X
- 0…1 for pixels on shadow edge (soft shadow edge)
Accumulation of (Light0 * Mask0)+ … can be done
using additive blending
How to add shadows?
- Algorithm
- Render scene with ambient illumination only
- For each light source
- Render scene with illumination from this light only
- Scale illumination by shadow mask
- Add up contribution to frame buffer
- Expensive but correct!
- Speed-Up
- Use more lights & masks in one pass
- Masks stored as textures
- Apply masks & sum up using e.g. register combiners
How to Render the Shadow
/* Render 50% black shadow color on top of whatever
the floor appearance is. */
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_LIGHTING); /* Force the 50% black. */
glColor4f(0.0, 0.0, 0.0, 0.5);
glPushMatrix();
/* Project the shadow. */
glMultMatrixf((GLfloat *) floorShadow);
drawDinosaur();
glPopMatrix();
Fake shadows using textures
Image from light source BW image of obstacle Final image
Figure from Moller & haines “Real Time Rendering” 38
Shadow maps
- Use texture mapping but using depth
- 2 passes (at least)
map from light source
- Store depth buffer (shadow map)
- Compute final image
- Look up the shadow map to know if points are in shadow
Figure from Foley et al. “Computer Graphics Principles and Practice”
Shadow map look up
x,y,z
the shadow map?
Figure from Foley et al. “Computer Graphics Principles and Practice”
(x,y,z)
Shadow map look up
(x,y,z)
- How do we look up the shadow map?
- Use the 4x4 camera matrix from the light source
- We get (x’,y’,z’)
- Test: ShadowMap(x’,y’)<z’
Figure from Foley et al. “Computer Graphics Principles and Practice”
(x’,y’,z’)^ (x,y,z)
Shadow maps
- In Renderman
- (High-end production software)
Shadow maps
- Can be done in hardware
- Using hardware texture mapping
- Texture coordinates u,v,w generated using 4x4 matrix
- Modern hardware permits tests on texture values
Introducing Another Technique: Shadow Mapping
- Image-space shadow determination
- Lance Williams published the basic idea in 1978
- By coincidence, same year Jim Blinn invented bump mapping (a great vintage year for graphics)
- Completely image-space algorithm
- means no knowledge of scene’s geometry is required
- must deal with aliasing artifacts
- Well known software rendering technique
- Pixar’s RenderMan uses the algorithm
- Basic shadowing technique for Toy Story, etc.
Shadow Mapping References
- Important SIGGRAPH papers
- Lance Williams, “Casting Curved Shadows on Curved
Surfaces,” SIGGRAPH 78
- William Reeves, David Salesin, and Robert Cook
(Pixar), “Rendering antialiased shadows with depth
maps,” SIGGRAPH 87
- Mark Segal, et. al. (SGI), “Fast Shadows and Lighting
Effects Using Texture Mapping,” SIGGRAPH 92
The Shadow Mapping Concept (1)
- Depth testing from the light’s point-of-view
- Two pass algorithm
- First, render depth buffer from the light’s point- of-view - the result is a “depth map” or “shadow map” - essentially a 2D function indicating the depth of the closest pixels to the light
- This depth map is used in the second pass
The Shadow Mapping Concept (2)
- Shadow determination with the depth map
- Second, render scene from the eye’s point-of-view
- For each rasterized fragment
- determine fragment’s XYZ position relative to the light
- this light position should be setup to match the frustum
used to create the depth map
- compare the depth value at light position XY in the depth
map to fragment’s light position Z
The Shadow Mapping Concept (3)
- The Shadow Map Comparison
- Two values
- A = Z value from depth map at fragment’s light XY
position
- B = Z value of fragment’s XYZ light position
- If B is greater than A, then there must be something closer to the light than the fragment
- then the fragment is shadowed
- If A and B are approximately equal, the fragment is lit 48
Shadow Mapping with a Picture in 2D (1)
light source eye position
depth map Z = A
fragment’s light Z = B
depth map image plane
eye view image plane, a.k.a. the frame buffer
The A < B shadowed fragment case
Visualizing the Shadow
Mapping Technique (5)
- Projecting the depth map onto the eye’s view
FYI: depth map forFYI: depth map for
light’s pointlight’s point--ofof--viewview
againagain
Visualizing the Shadow
Mapping Technique (6)
- Projecting light’s planar distance onto eye’s view
Visualizing the Shadow
Mapping Technique (6)
- Comparing light distance to light depth map
Green isGreen is where thewhere the light planarlight planar distance anddistance and the lightthe light depth mapdepth map areare approximatelapproximatel y equaly equal
NonNon--green isgreen is wherewhere shadowsshadows should beshould be
Visualizing the Shadow
Mapping Technique (7)
Notice howNotice how specularspecular highlightshighlights never appearnever appear in shadowsin shadows
Notice howNotice how curvedcurved surfaces castsurfaces cast shadows onshadows on each othereach other
Problems with shadow maps?
- Field of view
- Bias
- Aliasing
Field of view problem
shadow is outside
field of view of
shadow map?
map
Problems with shadow maps?
- Field of view
- Bias
- Aliasing
The bias nightmare
from the light source
ShadowMap(x’,y’)≈z’
- Avoid erroneous self shadowing
The bias nightmare
hit
hit+epsilon*light
casting
- Start the ray at hit+light*epsilon
- Add bias to avoid degeneracy
- Yet another instance of geometric robustness
Bias for shadow maps
ShadowMap(x’,y’)+bias < z’
Choosing the good bias value can be very tricky
Construct Light View Depth Map
- Realizing the theory in practice
- Constructing the depth map
- use existing hardware depth buffer
- use glPolygonOffset to bias depth value
- read back the depth buffer contents
- Depth map can be copied to a 2D texture
- unfortunately, depth values tend to require more precision than 8-bit typical for textures
- depth precision typically 16-bit or 24-bit
66
Justification for glPolygonOffset
When Constructing Shadow Maps
- Depth buffer contains “window space” depth values
- Post-perspective divide means non-linear distribution
- glPolygonOffset is guaranteed to be a window space offset
- Doing a “clip space” glTranslatef is not sufficient
- Common shadow mapping implementation mistake
- Actual bias in depth buffer units will vary over the frustum
- No way to account for slope of polygon
Percentage closer filtering
- Filter the result of the test
- But makes the bias issue more tricky
Percentage closer filtering
- 5x5 samples
- Nice antialiased shadow
- Using a bigger filter produces fake soft shadows
- But makes the bias issue more tricky
Shadows in production
maps
fallback in case of robustness issues
Movie Time!
Alaising
- Bad aliasing cases:
- Large Scenes
- High resolution shadow map required
- Close-ups to shadow boundaries
- Shadow stretches along the receiver
Aliasing
- Duelling frusta
- Light shines opposite to viewing direction
Aliasing
Four Images of Dueling Frusta Case
Eye’sEye’s ViewView
Light’sLight’s ViewView
Eye’s View withEye’s View with projectionprojection of colorof color--codedcoded mipmap levelsmipmap levels from light:from light: Red = minificationRed = minification Blue = magnificationBlue = magnification
Light’s View withLight’s View with rere--projectionprojection of above imageof above image from the eyefrom the eye
Interpretation of the Images
of the Dueling Frusta Case
Eye’s Eye’s ViewView
Light’sLight’s ViewView
Region that is smallestRegion that is smallest in the light’s view is ain the light’s view is a region that is very largeregion that is very large in the eye’s view.in the eye’s view. ThisThis implies that it wouldimplies that it would require a very highrequire a very high-- resolution shadow mapresolution shadow map to avoid obvious blockyto avoid obvious blocky shadow edge artifacts.shadow edge artifacts.
Dueling Frusta Blocky Shadow
Edge Artifacts
Light positionLight position out hereout here pointingpointing towards thetowards the viewer.viewer. BlockyBlocky shadow edgeshadow edge artifacts.artifacts.
Notice thatNotice that shadow edgeshadow edge is wellis well defined indefined in the distance.the distance.
Aliasing
- Miner’s headlamp
- Similar frusta
- Similar sampling
- One shadowmap pixel for image pixel
Good Situation, Close to the
Miner’s Lamp
Eye’sEye’s ViewView
Light’sLight’s ViewView
VeryVery similarsimilar viewsviews
Note how the colorNote how the color-- coded images sharecoded images share similar pattern andsimilar pattern and the coloration isthe coloration is uniform.uniform. ImpliesImplies single depth mapsingle depth map resolution wouldresolution would work well for mostwork well for most of the scene.of the scene.
Ghosting isGhosting is wherewhere projectionprojection would be inwould be in shadow.shadow.
Back to the Shadow Mapping Discussion...
- Assign light-space texture coordinates via texgen
- Transform eye-space (x, y, z, w) coordinates to the light’s
view frustum (match how the light’s depth map is generated)
- Further transform these coordinates to map directly into the
light view’s depth map
- Expressible as a projective transform
- Load this transform into the 4 eye linear plane equations for S, T, and Q coordinates
- (s/q, t/q) will map to light’s depth map texture
OpenGL’s Standard Vertex Coordinate Transform
- From object coordinates to window coordinates Object coordinatesObject coordinates (x, y, z, w)(x, y, z, w)
Eye coordinatesEye coordinates (x, y, z, w)(x, y, z, w)
modelviewmodelviewmatrixmatrix
dividedivideby wby w
viewport &viewport & depth rangedepth range
normalized devicenormalized device coordinatescoordinates (x, y, z)(x, y, z)
Clip coordinatesClip coordinates (x, y, z, w)(x, y, z, w)
Window coordinatesWindow coordinates ((PP (^) xx ,, PP (^) yy ), (), (DD (^) zz ))
World coordinatesWorld coordinates (x, y, z, w)(x, y, z, w) viewview matrixmatrix
projectionprojectionmatrixmatrix
OpenGL’s Standard Vertex Coordinate Transform
- From object coordinates to window coordinates Object coordinatesObject coordinates (x, y, z, w)(x, y, z, w)
Eye coordinatesEye coordinates (x, y, z, w)(x, y, z, w)
modelviewmodelview matrixmatrix
dividedivideby wby w
viewport &viewport & depth rangedepth range
normalized devicenormalized device coordinatescoordinates (x, y, z)(x, y, z)
Clip coordinatesClip coordinates (x, y, z, w)(x, y, z, w)
Window coordinatesWindow coordinates ((PP (^) xx ,, PP (^) yy ), (), (DD (^) zz ))
World coordinatesWorld coordinates (x, y, z, w)(x, y, z, w)
viewview matrixmatrix
projectionprojection matrixmatrix
Light eye coordinatesLight eye coordinates (x, y, z, w)(x, y, z, w)
Light divideLight divideby wby w
LightLight viewportviewport && depth rangedepth range
Light normalized deviceLight normalized device coordinatescoordinates (x, y, z)(x, y, z)
Light clip coordinatesLight clip coordinates (x, y, z, w)(x, y, z, w)
Light window coordinatesLight window coordinates ((PP (^) xx ,, PP (^) yy ), (), (DD (^) zz ))
Light viewLight view matrixmatrix
Light projectionLight projection matrixmatrix
OpenGL’s Standard Vertex Coordinate Transform
- From object coordinates to window coordinates Object coordinatesObject coordinates (x, y, z, w)(x, y, z, w)
Eye coordinatesEye coordinates (x, y, z, w)(x, y, z, w)
modelviewmodelview matrixmatrix
dividedivideby wby w
viewport &viewport & depth rangedepth range
normalized devicenormalized device coordinatescoordinates (x, y, z)(x, y, z)
Clip coordinatesClip coordinates (x, y, z, w)(x, y, z, w)
Window coordinatesWindow coordinates ((PP (^) xx ,, PP (^) yy ), (D), (D (^) zz ))
World coordinatesWorld coordinates (x, y, z, w)(x, y, z, w)
viewview matrixmatrix
projectionprojection matrixmatrix
Light eye coordinatesLight eye coordinates (x, y, z, w)(x, y, z, w)
Light divideLight divideby wby w
LightLight viewportviewport && depth rangedepth range
Light normalized deviceLight normalized device coordinatescoordinates (x, y, z)(x, y, z)
Light clip coordinatesLight clip coordinates (x, y, z, w)(x, y, z, w)
Light window coordinatesLight window coordinates (P(P (^) xx, P ,P (^) yy ), (D), (D (^) zz ))
Light viewLight view matrixmatrix
Light projectionLight projection matrixmatrix
OpenGL’s Standard Vertex Coordinate Transform
- From object coordinates to window coordinates Object coordinatesObject coordinates (x, y, z, w)(x, y, z, w)
Eye coordinatesEye coordinates (x, y, z, w)(x, y, z, w)
modelviewmodelview matrixmatrix
dividedivideby wby w
viewport &viewport & depth rangedepth range
normalized devicenormalized device coordinatescoordinates (x, y, z)(x, y, z)
Clip coordinatesClip coordinates (x, y, z, w)(x, y, z, w)
Window coordinatesWindow coordinates ((PP (^) xx ,, PP (^) yy ), (), (DD (^) zz ))
World coordinatesWorld coordinates (x, y, z, w)(x, y, z, w)
viewview matrixmatrix
projectionprojectionmatrixmatrix
Light eye coordinatesLight eye coordinates (x, y, z, w)(x, y, z, w)
Light divideLight divideby wby w
LightLight viewportviewport && depth rangedepth range
Light normalized deviceLight normalized device coordinatescoordinates (x, y, z)(x, y, z)
Light clip coordinatesLight clip coordinates (x, y, z, w)(x, y, z, w)
Light window coordinatesLight window coordinates ((PP (^) xx ,, PP (^) yy ), (), (DD (^) zz ))
Light viewLight view matrixmatrix
Light projectionLight projectionmatrixmatrix
OpenGL’s Standard Vertex Coordinate Transform
- From object coordinates to window coordinates Object coordinatesObject coordinates (x, y, z, w)(x, y, z, w)
Eye coordinatesEye coordinates (x, y, z, w)(x, y, z, w)
modelviewmodelview matrixmatrix
dividedivideby wby w
viewport &viewport & depth rangedepth range
normalized devicenormalized device coordinatescoordinates (x, y, z)(x, y, z)
Clip coordinatesClip coordinates (x, y, z, w)(x, y, z, w)
Window coordinatesWindow coordinates ((PP (^) xx ,, PP (^) yy ), (D), (D (^) zz ))
World coordinatesWorld coordinates (x, y, z, w)(x, y, z, w)
viewview matrixmatrix
projectionprojectionmatrixmatrix
Light eye coordinatesLight eye coordinates (x, y, z, w)(x, y, z, w)
Light clip coordinatesLight clip coordinates (x, y, z, w)(x, y, z, w)
Light viewLight view matrixmatrix
Light projectionLight projectionmatrixmatrix
T = Pl x V l x V c-
OpenGL’s Standard Vertex Coordinate Transform
- From object coordinates to window coordinates Object coordinatesObject coordinates (x, y, z, w)(x, y, z, w)
Eye coordinatesEye coordinates (x, y, z, w)(x, y, z, w)
modelviewmodelviewmatrixmatrix
dividedivide by wby w
depth rangedepth rangeviewport &viewport &
normalized devicenormalized device coordinatescoordinates (x, y, z)(x, y, z)
Clip coordinatesClip coordinates (x, y, z, w)(x, y, z, w)
Window coordinatesWindow coordinates ((PP (^) xx ,, PP (^) yy ), (), (DD (^) zz ))
World coordinatesWorld coordinates (x, y, z, w)(x, y, z, w)
matrixmatrixviewview
projectionprojection matrixmatrix
Light eye coordinatesLight eye coordinates (x, y, z, w)(x, y, z, w)
Light clip coordinatesLight clip coordinates (x, y, z, w)(x, y, z, w)
Light viewLight viewmatrixmatrix
Light projectionLight projection matrixmatrix
T = Pl x V l x V c-
T = S x Pl x V l x V c-
where S = scale and bias
eyeeye--linear planelinear plane equationsequations (s, t, r, q)(s, t, r, q)
Setting Up Eye Linear Texgen
- With OpenGL GLfloat Splane[4], Tplane[4], Rplane[4], Qplane[4]; glTexGenfv(GL_S, GL_EYE_PLANE, Splane); glTexGenfv(GL_T, GL_EYE_PLANE, Tplane); glTexGenfv(GL_R, GL_EYE_PLANE, Rplane); glTexGenfv(GL_Q, GL_EYE_PLANE, Qplane); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_GEN_Q);
- Each eye plane equation is transformed by current inverse modelview matrix - Very handy thing for us; otherwise, a pitfall - Note: texgen object planes are not transformed
by the inverse modelview
Eye Linear Texgen Transform
- Plane equations form a projective transform
- The 4 eye linear plane equations form a 4x4 matrix
- No need for the texture matrix!
s s
tt
rr
qq
Splane[0]Splane[0] Splane[1]Splane[1] Splane[2]Splane[2] Splane[3]Splane[3]
Tplane[0]Tplane[0] Tplane[1]Tplane[1] Tplane[2]Tplane[2] Tplane[3]Tplane[3]
Rplane[0]Rplane[0] Rplane[1]Rplane[1] Rplane[2]Rplane[2] Rplane[3]Rplane[3]
Qplane[0]Qplane[0] Qplane[1]Qplane[1] Qplane[2]Qplane[2] Qplane[3]Qplane[3]
xx^ ee
yy ee
zz ee
ww ee
Shadow Map Eye Linear Texgen TransformShadow Map Eye Linear Texgen Transform
LightLight frustumfrustum (projection)(projection) matrixmatrix
LightLight viewview (look at)(look at) matrixmatrix
InverseInverse eyeeye viewview (look at)(look at) matrixmatrix
EyeEye viewview (look at)(look at) matrixmatrix
ModelingModeling matrixmatrix
xx oo
yy oo
zz oo
ww oo
xx ee
yy ee
zz ee
ww^ ee
xx ee
yy^ ee
zz ee
ww ee
ss
tt
rr
qq
glTexGenglTexGen automaticallyautomatically applies this whenapplies this when modelview matrixmodelview matrix contains just the eye viewcontains just the eye view transformtransform
Supply this combined transform toSupply this combined transform to glTexGenglTexGen
Shadow Map Operation
- Automatic depth map lookups
- After the eye linear texgen with the proper transform
loaded
- (s/q, t/q) is the fragment’s corresponding location within the light’s depth texture
- r/q is the Z planar distance of the fragment relative to the light’s frustum, scaled and biased to [0,1] range
- Next compare texture value at (s/q, t/q) to
value r/q
- If texture[s/q, t/q] ≅ r/q then not shadowed
- If texture[s/q, t/q] < r/q then shadowed
Shadow Mapping Hardware Support (1)
- OpenGL now has official shadow mapping extensions
- Depth textures – adds depth texture formats
- See book on page 463
- Previously:
- ARB_depth_texture – adds depth texture formats
- ARB_shadow – adds “percentage closer” filtering for depth textures
- The two extensions are used together
- Based on prior proven SGI proprietary extensions
- SGIX_depth_texture
- SGIX_shadow
Hardware Support
- OpenGL 1.
- GL_ARB_DEPTH_TEXTURE internal texture format to store depth values
- glTexGen generation of light space coordinates as texture coordinates
- GL_ARB_SHADOW special texture mode: return texture(s,t) < r? Black : White;
Hardware Support
- P-Buffers or FBO
- offscreen rendering of shadow map
- large shadow maps sizes
- GL_ARB_RENDER_TEXTURE and WGL_NV_RENDER_TEXTURE - bind P-Buffer depth buffer as depth texture - no copy needed
Advice for Shadowed Illumination Model (1)
- Typical illumination model with decal texture:
( ambient + diffuse ) * decal + specular
The shadow map supplies a shadowing term
- Assume shadow map supplies a shadowing term, shade
- Percentage shadowed
- 100% = fully visible, 0% = fully shadowed
- Obvious updated illumination model for shadowing:
( ambient + shade * diffuse ) * decal + shade * specular
- Problem is real-world lights don’t 100% block diffuse shading on
shadowed surfaces
- Light scatters; real-world lights are not ideal points
The Need for Dimming Diffuse
No dimming; shadowed regions have 0% diffuse and 0% specular
With dimming; shadowed regions have 40% diffuse and 0% specular
Front facing shadowed regions appear unnaturally flat.
Still evidence of curvature in shadowed regions.
No specular in shadowed regions in both versions.
Advice for Shadowed Illumination Model (2)
- Illumination model with dimming: ( ambient + diffuseShade * diffuse ) * decal + specular * shade
where diffuseShade is
diffuseShade = dimming + ( 1.0 – dimming ) * shade
Easy to implement with NV_register_combiners & OpenGL 1.
“separate specular color” support
- Separate specular keeps the diffuse & specular per-vertex lighting
results distinct
- NV_register_combiners can combine the primary
(diffuse) and secondary (specular) colors per-pixel
with the above math
Careful about Back Projecting Shadow Maps (1)
- Just like standard projective textures, shadow maps can back-project
Spotlight casting shadows (a hooded light source)
Back-projection of spotlight’s cone of illumination
Pentagon would be incorrectly lit by back- projection if not specially handled
Spotlight’s of cone of illumination where “true” shadows can form
Careful about Back Projecting Shadow Maps (2)
- Techniques to eliminate back-projection:
- Modulate shadow map result with lighting result from a single per-vertex spotlight with the proper cut off (ensures is light “off” behind the spotlight)
- Use a small 1D texture where “s” is planar distance from the light (generated “s” with a planar texgen mode), then 1D texture is 0.0 for negative distances and 1. for positive distances.
- Use a clip plane positioned at the plane defined by the light position and spotlight direction
- Simply avoid drawing geometry “behind” the light when applying the shadow map (better than a clip plane)
- NV_texture_shader’s GL_PASS_THROUGH_NV mode
Combining Shadow Mapping with other Techniques
- Good in combination with techniques
- Use stencil to tag pixels as inside or outside of shadow
- Use other rendering techniques in extra passes
- bump mapping
- texture decals, etc.
- Shadow mapping can be integrated into more complex
multi-pass rendering algorithms
- Shadow mapping algorithm does not require access to vertex-level data - Easy to mix with vertex programs and such
Hardware Support
- Register Combiners / Fragment Programs
- for shadow application
- if point is in shadow:
- leave ambient light unchanged
- ambient light has no origin, thus cannot be shadowed
- dim diffuse light
- some shading remains to show surface orientation
- remove specular light
Pros and Cons
- everything that can be rendered can cast and receive a shadow
- works together with vertex programs
- full hardware support
- (almost) no overhead for static scenes
- two passes needed for dynamic scenes
- Aliasing
- Limited to light frustum
- Near/Far plane clipping
Questions?
Questions?