Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth...

17
Real-time Real-time Shadow Mapping Shadow Mapping

Transcript of Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth...

Page 1: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Real-time Real-time Shadow Shadow MappingMapping

Real-time Real-time Shadow Shadow MappingMapping

Page 2: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Shadow Mapping

• Shadow mapping uses two-pass rendering- render depth texture from the light’s point-of-view

- render from the eye’s point-of-view using depth texture

• Completely image-space implementation- no knowledge of scene’s geometry is required

- must deal with aliasing artifacts

Page 3: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

First Pass(1)

• The scene is rendered from the light’s point of view into the depth texture

Page 4: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

First Pass(2)

• The result is a “depth texture” or “shadow map”- essentially a 2D function indicating the depth of the

closest pixels to the light

Page 5: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Second Pass

• The scene is rendered 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 texture- compare the depth value at light position XY in the depth

texture to fragment’s light position Z

Page 6: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Depth Texture Comparison(1)

• Two values- A = Z value from depth texture 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 so the fragment is in shadow

• If A and B are approximately equal,the fragment is lit

Page 7: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Depth Texture Comparison(2)

Page 8: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Depth Texture Comparison(3)

The A < B shadowed fragment case

Page 9: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Depth Texture Comparison(4)

The A = B shadowed fragment case

Page 10: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Using Projective Texturing(1)

Page 11: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Using Projective Texturing(2)

• Normal 2D texture mapping uses (s, t) coordinates• Now consider homogeneous texture coordinates

- r/q holds the distance from the light - (s, t, r, q) --> (s/q, t/q, r/q)- similar to homogeneous clip coordinates where

(x, y, z, w) = (x/w, y/w, z/w)

• 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

Page 12: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Ambient Shadows

• Improvement for completely black shadows

Page 13: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Near and Far planes

• Distance between near and far planes should be minimized for better precision of Z value

Page 14: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Z-Fighting

• Problem take place when eye space pixel coordinates are transformed into light space to get the respective depth texture samples due to machine rounding errors in this stage

Page 15: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Aliasing Problems

• There is still the problem of aliasing

Page 16: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Summary

Page 17: Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.

Implementation

• First pass uses the OpenSceneGraph library which based on OpenGL

• Second pass is done by hardware using cg and glsl language shaders