Erdem Alpay Ala Nawaiseh Why Shadows Real world

  • Slides: 34
Download presentation
Erdem Alpay Ala Nawaiseh

Erdem Alpay Ala Nawaiseh

Why Shadows? Real world has shadows More control of the game’s feel w dramatic

Why Shadows? Real world has shadows More control of the game’s feel w dramatic effects w spooky effects Without shadows the realism of a scene is lost Spatial location of models can be ambiguous

Importance of Shadows • Where is the light coming from? • Where are the

Importance of Shadows • Where is the light coming from? • Where are the objects in relation to each other?

Importance of Shadows • Where is the light coming from? • Where are the

Importance of Shadows • Where is the light coming from? • Where are the objects in relation to each other? • Shadows are being cast and the answers to these questions are easily found.

Common Real-Time Shadow Techniques Projected planar shadows Shadow volumes Hybrid approaches Light maps

Common Real-Time Shadow Techniques Projected planar shadows Shadow volumes Hybrid approaches Light maps

Planar Projected Shadows Easy To Implement and with good results when casting shadows onto

Planar Projected Shadows Easy To Implement and with good results when casting shadows onto one plane Squishes the Model onto a plane in just one matrix multiplication Very Fast Can extend to cast onto multiple planes, but each plane will require another rendering of the model.

Planar Projected Shadows 0 Plane Eq: Ax + By + Cz + D =

Planar Projected Shadows 0 Plane Eq: Ax + By + Cz + D = [x, y, z] is the difference between the center of the model and the light source. Ideally you want to use the distance from each vertex, However it is not as fast since the matrix will have to be computed on a per vertex basis instead of a per model basis. The vertices of the model are multiplied by the Planar Projection matrix.

Shadow Mapping Lance Williams published the idea in 1978 Completely image-space algorithm w No

Shadow Mapping Lance Williams published the idea in 1978 Completely image-space algorithm w No knowledge of scene’s geometry is required w must deal with aliasing artifacts Well known software rendering technique w Pixar’s Render. Man uses the algorithm w Basic shadowing technique for Toy Story, etc.

The Shadow Mapping Two pass algorithm: n n First, render depth buffer from the

The Shadow Mapping Two pass algorithm: n n First, render depth buffer from the light’s point-ofview w Essentially a 2 D function indicating the depth of the closest pixels to the light. w The result is a “depth map” or “shadow map”. Second, render scene from the eye’s point-ofview w For each rasterized fragment determine fragment’s XYZ position relative to the light w compare the depth value at light position XY in the depth map to fragment’s light position Z

The Shadow Mapping Cont. The Shadow Map Comparison n Two values w A =

The Shadow Mapping Cont. The Shadow Map Comparison n Two values w A = Z value from depth map at fragment’s light XY position w B = Z value of fragment’s XYZ light position n If B is greater than A, then there must be something closer to the light than the fragment w then the fragment is shadowed n If A and B are approximately equal, the fragment is lit

Shadow Mapping with a Picture in 2 D (1) A < B shadowed fragment

Shadow Mapping with a Picture in 2 D (1) A < B shadowed fragment case depth map’s image plane light source depth map Z = A First step

Shadow Mapping with a Picture in 2 D (1) A < B shadowed fragment

Shadow Mapping with a Picture in 2 D (1) A < B shadowed fragment case depth map’s image plane light source depth map Z = A Second Step eye position eye view image plane, a. k. a. the frame buffer fragment’s light Z = B

Shadow Mapping with a Picture in 2 D (2) A B unshadowed fragment case

Shadow Mapping with a Picture in 2 D (2) A B unshadowed fragment case depth map image plane light source depth map Z = A eye position eye view image plane, a. k. a. the frame buffer fragment’s light Z = B

Shadow Mapping with a Picture in 2 D (3) image precision mismatch! The depth

Shadow Mapping with a Picture in 2 D (3) image precision mismatch! The depth map could be at a different resolution from the frame buffer This mismatch can lead to artifacts An artifact is small error caused by the render process.

More realistic Example for mapping 1 st Pass

More realistic Example for mapping 1 st Pass

More realistic Example for mapping 2 nd Pass

More realistic Example for mapping 2 nd Pass

Z-Buffer (Depth Buffer) Speeds up games by telling the graphics processor not to render

Z-Buffer (Depth Buffer) Speeds up games by telling the graphics processor not to render objects that aren't actually in view, specifically objects or parts of objects which are covered up by other geometry. Ranges from 16 bit to 32 bit, and it can take up as much memory as an extra frame buffer. If depth test is enabled, n n when a new color that arrives for a pixel is closer to the window than the one already in the depth buffer. If it passes, it then replaces the value already in the depth buffer.

Stencil Buffer It's usually only 1 bit or 8 bit. The stencil allows applications

Stencil Buffer It's usually only 1 bit or 8 bit. The stencil allows applications to "tag" various regions of the frame buffer. The stencil buffer can tell the video card what it's allowed to redraw For example, let's say you have an air simulation game where the view is from the cockpit. It would be a waste to render the cockpit interior every frame the cockpit interior is tagged with a stencil number > 1 The stencil buffer tag will tell the video card to only redraw where it sees a 0 in the stencil buffer

What Is Shadow Volume First proposed by Frank Crow in 1977. A volume of

What Is Shadow Volume First proposed by Frank Crow in 1977. A volume of space formed by an occluder Bounded by the edges of the occluder Notice that the “far” ends of the volume goes to infinity

How does Shadow Volume works Compute the shadow volume for all visible polygons from

How does Shadow Volume works Compute the shadow volume for all visible polygons from the light source Add the shadow volume polygons to the scene database n n Tag them as shadow polygons Assign its associated light source

Approaches in shadow volumes First approach : Parity Test n When is a surface

Approaches in shadow volumes First approach : Parity Test n When is a surface is inside shadow? w Initially set parity to 0 and shoot a ray from eye to P w Invert parity when the ray crosses the shadow volume boundary w Parity = 1 it is in shadow w Parity = 0 it is not in Shadow

Approaches in shadow volumes First approach : Parity Test n Problems with Parity Test

Approaches in shadow volumes First approach : Parity Test n Problems with Parity Test

How does Shadow Volumes Works Second Approach : Counter • When is a surface

How does Shadow Volumes Works Second Approach : Counter • When is a surface is inside shadow? w Consider a camera at any point outside of the shadow and a point being shaded. Shoot a ray from camera to the point. w If the point is in the shadow volume it will have a positive value since the ray incremented the stencil buffer every time it entered the shadow volume (front facing), and decremented it when it left (back facing).

How does Shadow Volumes Works Shadowing object light source 0 eye position 1 2

How does Shadow Volumes Works Shadowing object light source 0 eye position 1 2 2 3 1 0 • If the camera is within the shadow volume the incrementing and decrementing must be reversed. • This however is extra work for a check to determine the location of the camera must be made.

Shadow Volumes Step 1: Render scene Z-values

Shadow Volumes Step 1: Render scene Z-values

Shadow Volumes Front face: +1 Back face: -1 Step 2: Render shadow volume faces

Shadow Volumes Front face: +1 Back face: -1 Step 2: Render shadow volume faces

Shadow Volumes Front face: Back face: = ± 0 (Depth test) ± 0

Shadow Volumes Front face: Back face: = ± 0 (Depth test) ± 0

Shadow Volumes ± 0 Front face: Back face: = +1 ± 0 (Depth test)

Shadow Volumes ± 0 Front face: Back face: = +1 ± 0 (Depth test) +1

Shadow Volumes +1 ± 0 Front face: Back face: = +1 -1 ± 0

Shadow Volumes +1 ± 0 Front face: Back face: = +1 -1 ± 0

Shadow Volumes ± 0 +1 ± 0 Step 3: Apply shadow mask to scene

Shadow Volumes ± 0 +1 ± 0 Step 3: Apply shadow mask to scene

Conclusion Shadow Mapping: n n offers real-time shadowing effects Independent of scene complexity Does

Conclusion Shadow Mapping: n n offers real-time shadowing effects Independent of scene complexity Does not mandate multi-pass as stenciled shadow volumes do Ideal for shadows from spotlights Shadow Volume: n n The addition of shadow volume polygons can greatly increase your database size Using the stencil buffer approach, pixel fill becomes a key speed factor More precise than shadow mapping Polygon count explodes with object complexity of geometry and number of light sources

References Shadow Mapping References n n n Lance Williams, “Casting Curved Shadows on Curved

References Shadow Mapping References n n n Lance Williams, “Casting Curved Shadows on Curved Surfaces, ” SIGGRAPH 78 (paper) William Reeves, David Salesin, and Robert Cook (Pixar), “Rendering antialiased shadows with depth maps, ” SIGGRAPH 87 (paper) http: //developer. nvidia. com/docs/IO/1830/ATT/sh adow_mapping. pdf

References Shadow Volume References n n n Lance Williams, “Casting Curved Shadows on Curved

References Shadow Volume References n n n Lance Williams, “Casting Curved Shadows on Curved Surfaces, ” SIGGRAPH 78 (paper) William Reeves, David Salesin, and Robert Cook (Pixar), “Rendering antialiased shadows with depth maps, ” SIGGRAPH 87 (paper) http: //developer. nvidia. com/docs/IO/1830/ATT/sh adow_mapping. pdf Shadow Volume Reconstruction from Depth Maps n Michael D. Mc. Cool University of Waterloo