Upload
helen-berry
View
213
Download
0
Embed Size (px)
Citation preview
9/20/2001 CS 638, Fall 2001
Reflection Review
• Recall from last lecture:– Rendering reflections requires rendering what is seen in the mirror,
and what is seen around the mirror
– The stencil buffer is used to avoid writing over the reflection when rendering the regular view, or vice versa
• Last time we saw how to render the reflected view first:– Render the reflected view
– Render the mirror, setting the stencil
– Clear the color buffer to clear around the mirror
– Render the stuff around the mirror, ignoring the stencil
9/20/2001 CS 638, Fall 2001
Rendering Normal View 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
9/20/2001 CS 638, Fall 2001
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
9/20/2001 CS 638, Fall 2001
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
,,,, adasbdbsgdgsrdrs DASADBSBDGSGDRSR
9/20/2001 CS 638, Fall 2001
Blending Factors
• The default is: Srgba=(1,1,1,1), Drgba=(0,0,0,0)– Overwrite buffer contents with incoming fragment
• You can use the colors themselves as blending functions: eg Srgba=(Rd,Rg,Rb,Ra), Drgba=(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:– Srgba=(As,As,As,As), Drgba=(1-As,1-As,1-As,1-As)– What does this achieve? When might you use it?
• Note that blending can simulate multi-texturing with multi-pass
9/20/2001 CS 638, Fall 2001
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– That is, I don’t know of games that use it
9/20/2001 CS 638, Fall 2001
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
9/20/2001 CS 638, Fall 2001
Why Shadows?
• Shadows tell us about the relative locations and motions of objects
9/20/2001 CS 638, Fall 2001
Shadows and Motion
http://vision.psych.umn.edu/www/kersten-lab/demos/shadows.html
Example movies came from:
9/20/2001 CS 638, Fall 2001
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
9/20/2001 CS 638, Fall 2001
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
(xp,yp,zp)
(xsw,ysw,zsw)
L(directional light)
9/20/2001 CS 638, Fall 2001
Ground Shadow Math
• The shadow point lies on the line from the light through the vertex:
• The shadow is on the ground, zsw=0, so =zp/zl, giving:
• Matrix form:
LPS
llppswllppsw yzzyyxzzxx ,
11000
0000
010
001
1
0 p
p
p
ll
ll
sw
sw
z
y
x
zy
zx
y
x
9/20/2001 CS 638, Fall 2001
Drawing the Shadow
• We now have a matrix that transforms an object into its shadow
• Drawing the shadow:– Draw the polygon– 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)
9/20/2001 CS 638, Fall 2001
Point Light Shadows
• Blinn ’88 gives a matrix that works for local point light sources– Takes advantage of perspective transformation (and homogeneous coordinates)
• Book has an approximation that does not use perspective matrices, Chapter 5.7
1100
0000
00
00
1
0 p
p
p
l
ll
ll
sw
sw
z
y
x
z
yz
xz
y
x
9/20/2001 CS 638, Fall 2001
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 multiply
rays to different points on the area light, and average the results
– Should still filter for best results
9/20/2001 CS 638, Fall 2001
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
Movie with incorrect shadows from http://www.cs.wisc.edu/~schenney/research/mcmc/dice.mov
9/20/2001 CS 638, Fall 2001
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
9/20/2001 CS 638, Fall 2001
Drawing Quick Dirty Shadows
Z equal with hit polygonZ-buffer quantization errors
Z above hit polygonApparent shadow too big
ViewerLight
9/20/2001 CS 638, Fall 2001
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/20/2001 CS 638, Fall 2001
Projective Shadows
• Create a texture that is the shape of the shadowing object as seen by the light
• Project this texture onto the other objects– That is, find texture coordinates on the other objects that pull the
right shadow/non-shadow pixel out of the texture
• Read Chapter 5.8 of “Game Programming Gems”– I expect you to know how it works, but not the formulas– Note, it doesn’t mention the texture matrix, which can avoid the
need to explicitly compute texture coordinates for objects
• Problem: Texture appears in places it shouldn’t, and it’s hard to avoid it