Presentation is loading. Please wait.

Presentation is loading. Please wait.

09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.

Similar presentations


Presentation on theme: "09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms."— Presentation transcript:

1 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms

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

3 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Planar Reflections (Flat Mirrors) Use the stencil buffer, color buffer and depth buffer Basic idea: –We need to draw all the stuff around the mirror –We need to draw the stuff in the mirror, reflected, without drawing over the things around the mirror Key point: You can reflect the viewpoint about the mirror to see what is seen in the mirror, or you can reflect the world about the mirror

4 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Reflecting Objects If the mirror passes through the origin, and is aligned with a coordinate axis, then just negate appropriate coordinate Otherwise, transform into mirror space, reflect, transform back MirrorWall

5 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Small Problem Reflecting changes the apparent vertex order as seen by the viewer –Why is this a problem? Reflecting the view has the same effect, but this time it also shifts the left-right sense in the frame buffer –Works, just harder to understand what’s happening

6 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Rendering Reflected First First pass: –Render the reflected scene without mirror, depth test on Second pass: –Disable the color buffer, Enable the stencil buffer to always pass but set the buffer, Render the mirror polygon –Now, set the stencil test to only pass points outside the mirror –Clear the color buffer - does not clear points inside mirror area Third Pass: –Enable the color buffer again, Disable the stencil buffer –Render the original scene, without the mirror –Depth buffer stops from writing over things in mirror

7 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Reflection Example The stencil buffer after the second pass The color buffer after the second pass – the reflected scene cleared outside the stencil

8 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Reflection Example The color buffer after the final pass

9 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Making it Faster Under what circumstances can you skip the second pass (the stencil buffer pass)? These are examples of designing for efficient rendering

10 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Making it Faster Under what circumstances can you skip the second pass (the stencil buffer pass)? –Infinite mirror plane (effectively infinite) –Solid object covering mirror plane These are examples of designing for efficient rendering

11 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Reflected Scene First (issues) Objects behind the mirror cause problems: –Will appear in reflected view in front of mirror –Solution is to use clipping plane to cut away things on wrong side of mirror Curved mirrors by reflecting vertices differently Doesn’t do: –Reflections of mirrors in mirrors (recursive reflections) –Multiple mirrors in one scene (that aren’t seen in each other)

12 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Rendering Normal First First pass: –Render the scene without the mirror Second pass: –Clear the stencil, Render the mirror, setting the stencil if the depth test passes Third pass: –Clear the depth buffer with the stencil active, passing things inside the mirror only –Reflect the world and draw using the stencil test. Only things seen in the mirror will be drawn

13 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Normal First Addendum Same problem with objects behind mirror –Same solution Can manage multiple mirrors –Render normal view, then do other passes for each mirror –Only works for non-overlapping mirrors (in view) –But, could be extended with more tests and passes A recursive formulation exists for mirrors that see other mirrors

14 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Frame Buffer Blending When a fragment gets to the frame buffer, it is blended with the existing pixel, and the result goes in the buffer Blending is of the form: –s=source fragment, d = destination buffer, RGBA color –In words: You get to specify how much of the fragment to take, and how much of the destination, and you add the pieces together All done per-channel

15 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Blending Factors The default is: S rgba =(1,1,1,1), D rgba =(0,0,0,0) –Overwrite buffer contents with incoming fragment You can use the colors themselves as blending functions: eg S rgba =(R d,G d,B d,A d ), D rgba =(0,0,0,0) –What use is this? –Hint: What if there is an image in the buffer and the source is a constant gray image? A light map? Common is to use the source alpha: –S rgba =(A s,A s,A s,A s ), D rgba =(1-A s,1-A s,1-A s,1-A s ) –What does this achieve? When might you use it? Note that blending can simulate multi-texturing with multi-pass

16 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Accumulation Buffer The accumulation buffer is not available for writing directly It is more like a place to hold and compute on pixel data Operations: –Load the contents of a color buffer into the accumulation buffer –Accumulate the contents of a color buffer, which means multiply them by a value then add them into the buffer –Return the buffer contents to a color buffer (scaled by a constant) –Add or multiply all pixel values by a given constant It would appear that it is too slow for games –Lots of copying data too and fro

17 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Accum. Buffer Algorithms Anti-aliasing: Render multiple frames with the image plane jittered slightly, and add them together –Hardware now does this for you, but this would be higher quality Motion blur: Render multiple frames representing samples in time, and add them together –More like strobing the object Depth of field: Render multiple frames moving both the viewpoint and the image plane in concert –Keep a point – the focal point – fixed in the image plane while things in front and behind appear to shift

18 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Why Shadows? Shadows tell us about the relative locations and motions of objects

19 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Shadows and Motion

20 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Facts about Shadows Shadows can be considered as areas hidden from the light source –Suggests the use of hidden surface algorithms A shadow on A due to B can be found by projecting B onto A with the light as the center of projection –Suggests the use of projection transformations For scenes with static lights and geometry, the shadows are fixed –Can pre-process such cases –Cost is in moving lights or objects Point lights have hard edges, and area lights have soft edges

21 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Ground Plane Shadows Shadows cast by point light sources onto planes are an important case that is relatively easy to compute –Shadows cast by objects (cars, players) onto the ground Accurate if shadows don’t overlap –Can be fixed, but not well (x p,y p,z p ) (x sw,y sw,z sw ) L(directional light)

22 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Ground Shadow Math The shadow point lies on the line from the light through the vertex: The shadow is on the ground, z sw =0, so  =z p /z l, giving: Matrix form:

23 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Drawing the Shadow We now have a matrix that transforms an object into its shadow Drawing the shadow: –Draw the ground and the object –Multiply the shadow matrix into the model transformation –Redraw the object in gray with blending on Tricks: –Lift the shadow a little off the plane to avoid z-buffer quantization errors (can be done with extra term in matrix) –Works for other planes by transforming into plane space, then shadow, then back again –Take care with vertex ordering for the shadow (it reverses)

24 09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Point Light Shadows Blinn ’88 gives a matrix that works for local point light sources –Takes advantage of perspective transformation (and homogeneous coordinates) Game Programming Gems has an approximation that does not use perspective matrices, Chapter 5.7

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


Download ppt "09/18/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms."

Similar presentations


Ads by Google