Algorithm overview Shadow mapping




1 algorithm overview

1.1 creating shadow map
1.2 shading scene

1.2.1 light space coordinates
1.2.2 depth map test
1.2.3 drawing scene







algorithm overview

rendering shadowed scene involves 2 major drawing steps. first produces shadow map itself, , second applies scene. depending on implementation (and number of lights), may require 2 or more drawing passes.


creating shadow map

scene rendered light view.



scene light view, depth map.


the first step renders scene light s point of view. point light source, view should perspective projection wide desired angle of effect (it sort of square spotlight). directional light (e.g., sun), orthographic projection should used.


from rendering, depth buffer extracted , saved. because depth information relevant, common avoid updating color buffers , disable lighting , texture calculations rendering, in order save drawing time. depth map stored texture in graphics memory.


this depth map must updated time there changes either light or objects in scene, can reused in other situations, such viewing camera moves. (if there multiple lights, separate depth map must used each light.)


in many implementations practical render subset of objects in scene shadow map in order save of time takes redraw map. also, depth offset shifts objects away light may applied shadow map rendering in attempt resolve stitching problems depth map value close depth of surface being drawn (i.e., shadow casting surface) in next step. alternatively, culling front faces , rendering of objects shadow map used similar result.


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

Popular posts from this blog

Discography Kassav'

History New York State Route 133

History Women in science