210 likes | 784 Views
Shadows: Shadow Mapping. Justin Reynolds CS 134. Problems with Common Shadow Techniques. Various limitations Projected planar shadows Only works well on flat surfaces Stenciled shadow volumes Determining the shadow volume is hard work. Another Technique: Shadow Mapping.
E N D
Shadows: Shadow Mapping Justin Reynolds CS 134
Problems with CommonShadow Techniques • Various limitations • Projected planar shadows • Only works well on flat surfaces • Stenciled shadow volumes • Determining the shadow volume is hard work
Another Technique:Shadow Mapping • Image-space shadow determination • Lance Williams published the basic idea in 1978 • 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.
Visualizing the ShadowMapping Technique (I) • A fairly complex scene with shadows the pointlight source
The Shadow Mapping Concept • Depth testing from the light’spoint-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 depth map is often stored as a texture in the graphics card memory.
Visualizing the ShadowMapping Technique (II) • The scene from the light’s point-of-view FYI: from theeye’s point-of-viewagain
The Shadow Mapping Concept (II) • Shadow determination with thedepth 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
Visualizing the ShadowMapping Technique (III) • The depth buffer from the light’s point-of-view FYI: from thelight’s point-of-viewagain
Visualizing the ShadowMapping Technique (IV) • Projecting the depth map onto the eye’s view FYI: depth map forlight’s point-of-viewagain
The Shadow Mapping Concept (III) • 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
Visualizing the ShadowMapping Technique (V) • Projecting light’s planar distance onto eye’s view
Visualizing the ShadowMapping Technique (VI) • Comparing light distance to light depth map Green is where the light planar distance and the light depth map are approximately equal Non-green is where shadows should be
Visualizing the ShadowMapping Technique (VII) • Complete scene with shadows
Back to the ShadowMapping 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
Shadow Mapping Algorithm procedure SHADOWMAPPING Render depth buffer (Z-buffer) from lights point of view, resulting in a shadow map or depth map Now, render scene from the eye’s point of view for all rasterized fragments do Determine fragment’s xyz position relative to the light That is transform each fragment’s xyz into the light’s coordinate system A = depth map(x,y) B = z-value of fragment’s xyz light position if A < B then fragment is shadowed else fragment is lit end if end for
Issues with ShadowMapping • Not without its problems • Prone to aliasing artifacts • Stitching / Z-fighting • Depth bias is not completely foolproof • Requires extra shadow map rendering pass and texture loading • Higher resolution shadow map reduces blockiness • but also increase texture copying expense
Blocky Shadow Edge Artifacts Notice that shadow edge is well defined in the distance. Light position out here pointing towards the viewer. Blocky shadow edge artifacts.
Conclusions • Shadow mapping offers real-time shadowing effects • Independent of scene complexity • Very compatible with multi-texturing • Does not mandate multi-pass as stenciled shadow volumes do • Ideal for shadows from spotlights • Consumer hardware shadow map support here today • GeForce3 and above, Xbox • Dual-texturing technique supports legacy hardware • Same basic technique used by Pixar to generate shadows in their computer-generated movies