Presentation is loading. Please wait.

Presentation is loading. Please wait.

09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.

Similar presentations


Presentation on theme: "09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in."— Presentation transcript:

1 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in

2 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Today Shadows part 2

3 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Shadows in Light Maps Static shadows can be incorporated into light maps –When creating the map, test for shadows by ray-casting to the light source - quite efficient Area light sources should cast soft shadows –Interpolating the texture will give soft shadows, but not good ones, and you loose hard shadows –Sampling the light will give better results: Cast multiple rays to different points on the area light, and average the results –Should still filter for best results What about light map resolution?

4 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Soft Shadow Example

5 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Shadow Shape Perception Perceptual studies (or anecdotal evidence) suggests that the shape of a shadow is not important –In other words, people correctly associate shadows with the objects that cast them even if the shapes don’t correspond

6 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Quick Dirty Shadows Blend a dark polygon into the frame-buffer in the place where the shadow should be –Cast a ray from light source, through object center, and see where it hits something –Blend a fixed shape polygon in at that location (with depth) Why dirty? –Use a fixed shape - shadow won’t match object –Use a single ray-cast to determine shadow location - no partial shadow and wrong parts of shadow may be drawn Good for things like car games for under-car shadow –Fast action and near planar receiving surfaces

7 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Drawing Quick Dirty Shadows Z equal with hit polygon Z-buffer quantization errors Z above hit polygon Apparent shadow too big ViewerLight

8 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Drawing Quick Dirty Shadows No depth test –Check that shadow can be seen by viewer (cast ray) –Just blend polygon in Again, shadow is too large and may be in wrong place –Test corners of shadow for visibility? –OK if polygons are flatter

9 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Projective Shadows Create a texture (dark on white) representing the appearance of the occluder as seen by the light –Game programmers frequently call this a shadow map –Can create it by “render to texture” with the light as viewpoint Use projective texturing to apply it to receivers Works if the appearance of the occluder from the light is reasonably constant Requires work to identify occluders and receivers Resolution issues Better than quick-dirty shadows, worse than other methods

10 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Shadow Volumes A shadow volume for an object and light is the volume of space that is shadowed –That is, all points in the volume are in shadow for that light/object pair Creating the volume: –Find silhouette edges of shadowing object as seen by the light source –Extrude these edges away from the light, forming polygons –Clip the polygons to the view volume

11 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Shadow Volume

12 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Practicalities For many algorithms, it is not necessary to find silhouette edges – just use all edges Silhouette edges can be found by looking at polygon normals –Silhouette edges are those between a front facing face and back facing face (from light’s point of view) –The result is a sequence of edges with common vertices Assuming convex shadowing objects Extend all the vertices of silhouette edges away from the light source Clip them to the view volume, and form the polygons that bound the shadow volume Final result are a set of shadow volume boundary polygons

13 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Key Observation All points inside a shadow volume are in shadow Along a ray from the eye, we can track the shadow state by looking at intersections with shadow volume boundaries –Assume the eye is not in shadow –Each time the ray crosses a front facing shadow polygon, add one to a counter –Each time the ray crosses a back facing shadow polygon, subtract one from a counter –Places where the counter is zero are lit, others are shadowed We need to count the number of shadow polygons in front of a point. Which buffer can count for us?

14 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Using Shadow Volumes +1 +1 0011

15 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Real-Time Shadow Volumes Compute shadow volumes per frame –Not a problem for only a few moving objects –Use simplified object geometry to speed things up –Vertex programs can be used to create volumes Four pass algorithm –Render scene with ambient light only (everything shadowed) –Render front facing shadow polygons to increment stencil buffer –Render back facing shadow polygons to decrement stencil buffer –Render scene again only for non-shadowed (stencil=0) regions Horrible details follow…

16 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Details Turn off any light sources and render scene with ambient light only, depth on, color buffer active Disable the color and depth buffers for writing, but leave the depth test active Initialize the stencil buffer to 0 or 1 depending on whether the viewer is in shadow or not (ray cast) Set the stencil test to always pass and the operation to increment if depth test passes Enable back face culling Render the shadow volumes - this will increment the stencil for every front facing polygon that is in front of a visible surface Cont…

17 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Details Enable front face culling, disable back face culling Set the stencil operation to decrement if the depth test passes (and leave the test as always pass) Render the shadow volumes - this decrements for all the back facing shadow polygons that are in front of visible objects. The stencil buffer now has positive values for places in shadow Set the stencil function to equality with 0, operations to keep Clear the depth buffer, and enable it and the color buffer for writing Render the scene with the lights turned on Voila, we’re done

18 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Alternate 2 Problems: Finding how many shadow volumes the viewer is in, and the near clip plane Solution: Count the number of shadow volume faces behind the visible scene –Assume shadow volumes are capped –Why does it work? New problem? –Resolved by Nvidia extension NV_depth_clamp –Resolved by smart homogeneous coordinate math –Textbook has details

19 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Why Use Shadow Volumes? They correctly account for shadows of all surfaces on all other surfaces –No shadow where there shouldn’t be shadow –No problem with multiple light sources Adaptable quality by creating shadow volumes with approximate geometry Shadow volumes for static object/light pairs can be pre- computed and don’t change More expensive than light maps, but not too bad on current hardware –Can’t combine the techniques. Why not?

20 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Why Not Use Shadow Volumes? Place very high demands on rendering pipeline –In particular, fill rate can be a major problem –Shadow volume polygons tend to cover very large parts of the screen –Using coarse occluder geometry won’t help this much Sharp shadows, and hard to make soft

21 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Variant Render fully lit, then add shadows (blend a dark polygon) where the stencil buffer is set – in what cases is it wrong? –http://www.gamasutra.com/features/19991115/bestimt_freitag_01.htm

22 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Shadow Buffer Algorithms Compute z-buffer from light viewpoint –Put it into the shadow buffer Render normal view, compare world locations of points in the z-buffer and shadow buffer –Have to transform pts into same coordinate system Points with same location in both buffers are lit. Why? Problems: –Resolution is a big issue – both depth and spatial –Only some hardware supports the required computations

23 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Project Stage 2 Incorporate lighting, shadows, reflections, pixel shaders, vertex shaders, other real-time techniques into your game –Use the most appropriate techniques for your game Demonstrate the technique with enough in-game art/model content to make the point –No need to have all content done now, but enough to show how your game will look Goals Monday Sept 29, Stage Due Monday Oct 13

24 09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Todo By Monday, Sept 22: Lock in Stage 1


Download ppt "09/23/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in."

Similar presentations


Ads by Google