Shading the scene Shadow mapping
1 shading scene
1.1 light space coordinates
1.2 depth map test
1.3 drawing scene
shading scene
the second step draw scene usual camera viewpoint, applying shadow map. process has 3 major components, first find coordinates of object seen light, second test compares coordinate against depth map, , finally, once accomplished, object must drawn either in shadow or in light.
light space coordinates
visualization of depth map projected onto scene
in order test point against depth map, position in scene coordinates must transformed equivalent position seen light. accomplished matrix multiplication. location of object on screen determined usual coordinate transformation, second set of coordinates must generated locate object in light space.
the matrix used transform world coordinates light s viewing coordinates same 1 used render shadow map in first step (under opengl product of modelview , projection matrices). produce set of homogeneous coordinates need perspective division (see 3d projection) become normalized device coordinates, in each component (x, y, or z) falls between −1 , 1 (if visible light view). many implementations (such opengl , direct3d) require additional scale , bias matrix multiplication map −1 1 values 0 1, more usual coordinates depth map (texture map) lookup. scaling can done before perspective division, , folded previous transformation calculation multiplying matrix following:
[
0.5
0
0
0.5
0
0.5
0
0.5
0
0
0.5
0.5
0
0
0
1
]
{\displaystyle {\begin{bmatrix}0.5&0&0&0.5\\0&0.5&0&0.5\\0&0&0.5&0.5\\0&0&0&1\end{bmatrix}}}
if done shader, or other graphics hardware extension, transformation applied @ vertex level, , generated value interpolated between other vertices, , passed fragment level.
depth map test
depth map test failures.
once light-space coordinates found, x , y values correspond location in depth map texture, , z value corresponds associated depth, can tested against depth map.
if z value greater value stored in depth map @ appropriate (x,y) location, object considered behind occluding object, , should marked failure, drawn in shadow drawing process. otherwise should drawn lit.
if (x,y) location falls outside depth map, programmer must either decide surface should lit or shadowed default (usually lit).
in shader implementation, test done @ fragment level. also, care needs taken when selecting type of texture map storage used hardware: if interpolation cannot done, shadow appear have sharp jagged edge (an effect can reduced greater shadow map resolution).
it possible modify depth map test produce shadows soft edge using range of values (based on proximity edge of shadow) rather pass or fail.
the shadow mapping technique can modified draw texture onto lit regions, simulating effect of projector. picture above, captioned visualization of depth map projected onto scene example of such process.
drawing scene
final scene, rendered ambient shadows.
drawing scene shadows can done in several different ways. if programmable shaders available, depth map test may performed fragment shader draws object in shadow or lighted depending on result, drawing scene in single pass (after initial earlier pass generate shadow map).
if shaders not available, performing depth map test must implemented hardware extension (such gl_arb_shadow), not allow choice between 2 lighting models (lit , shadowed), , necessitate more rendering passes:
the example pictures in article used opengl extension gl_arb_shadow_ambient accomplish shadow map process in 2 passes.
Comments
Post a Comment