340 likes | 604 Views
Week 10 - Monday. CS361. Last time. What did we talk about last time? Global illumination Shadows Projection shadows Soft shadows. Questions?. Project 3. Project 3. Assignment 4. Planar shadows summarized. Project the object onto a plane Gives a hard shadow
E N D
Week 10 - Monday CS361
Last time • What did we talk about last time? • Global illumination • Shadows • Projection shadows • Soft shadows
Planar shadows summarized • Project the object onto a plane • Gives a hard shadow • Needs tricks if the object is bigger than the plane • Gets an antishadow if the light is between occluder and receiver • Soften the shadow • Render the shadow multiple times • Blur the projection • Put gradients around the edges
Shadows on a curved surface • Think of shadows from the light's perspective • It "sees" whatever is not blocked by the occluder • We can render the occluder as black onto a white texture • Then, compute (u,v) coordinates of this texture for each triangle on the receiver • There is often hardware support for this • This is known as the shadow texture technique
Shadow texture issues • Weaknesses • The program has to know which objects are occluders and which are receivers • It has to be careful not to cast onto receivers that do not have the light blocked (antishadows) • Occluders cannot shadow themselves • Strengths • If the occluders do not change shape, the shadow texture can be reused • A variation of the idea can be used to make complicated shadow textures (e.g. Venetian blinds)
Shadow volumes • Shadow volumes are another technique for casting shadows onto arbitrary objects • Setup: • Imagine a point and a triangle • Extending lines from the point through the triangle vertices makes an infinite pyramid • If the point is a light, anything in the truncated pyramid under the triangle is in shadow • The truncated pyramid is the shadow volume
Shadow volumes in principle • Follow a ray from the eye through a pixel until it hits the object to be displayed • Increment a counter each time the ray crosses a frontfacing face of the shadow volume • Decrement a counter each time the ray crosses a backfacing face of the shadow volume • If the counter is greater than zero, the pixel is in shadow • Idea works for multiple triangles casting a shadow
Shadow volumes in practice • Calculating this geometrically is tedious and slow in software • We use the stencil buffer instead • Clear the stencil buffer • Draw the scene into the frame buffer (storing color and Z-data) • Turn off Z-buffer writing (but leave testing on) • Draw the frontfacing polygons of the shadow volumes on the stencil buffer (with incrementing done) • Then draw the backfacing polygons of the shadow values on the stencil buffer (with decrementing done) • Because of the Z-test, only the visible shadow polygons are drawn on the stencil • Finally, draw the scene but only where the stencil buffer is zero
Shadow volume issues • It is possible to use color or alpha buffers instead • If shadow volumes don't overlap, we can do the information in one pass, with a single bit of information • If the viewer is inside a shadow volume, we have to change the algorithm • If shadow volume planes intersect the near plane of the viewing frustum, bad things happen
Shadow mapping • Another technique is to render the scene from the perspective of the light using the Z-buffer algorithm, but with all the lighting turned off • The Z-buffer then gives a shadow map, showing the depths of every pixel • Then, we render the scene from the viewer's perspective, and darken those pixels that are further from the light than their corresponding point in the shadow map
Another visualization • Scene without shadows • Scene from the light's viewpoint • Depth map from the light's viewpoint • Depth test fails • Scene with shadows • Depth of the light compared to depth of the image
Shadow mapping issues • Strengths: • A shadow map is fast • Linear for the number of objects • Weaknesses: • A shadow map only works for a single light from one direction (not a point light) • Objects can shadow themselves (a bias needs to be used) • Too high of a bias can make shadows look wrong
Shadow map distortion • Another issue with shadow maps is that the Z-buffer map may oversample some areas and undersample others • Similar to a texture that is stretched so that some is pixelated and some is far • We can change the view direction and projection so that the Z-buffer map from the lighting better matches the sampling the eye sees • More complex methods make multiple shadow maps along the view
Percentage closer filtering • The shadow map technique does not, by itself, make soft shadows • Soft shadows can be achieved by sampling the four closest points in the shadow map and interpolating them together • Percentage-closer filtering tries to approximate area lighting with point lights by seeing how much of the nearby surface can see the point light
Ambient occlusion • Ambient lighting is completely even and directionless • As a consequence, objects in ambient lighting without shadows look very flat • Ambient occlusion is an attempt to add shadowing to ambient lighting
Ambient occlusion theory • Without taking occlusion into account, the ambient irradiance is constant: • But for points that are blocked in some way, the radiance will be less • We use the factor kA(p) to represent the fraction of the total irradiance available at point p
Bent normals • The ideas used for ambient occlusion can be applied to other lighting • We could use an irradiance map to give diffuse lighting that is both directed and diffuse • As the figure shows, we can weight the surface normals based on visibility to produce a bent normal • We then use the bent normal for doing lookups in the irradiance map
Computing kA • The trick, of course, is how to compute kA • The visibility function approach checks to see if a ray cast from a direction intersects any other object before reaching a point • We average over all (or many) directions to get the final value • Doesn't work (without modifications) for a closed room • Obscurance is similar, except that it is based on the distance of the intersection of the ray cast, not just whether or not it does
Interreflections • Generally, ambient occlusion makes the shadows darker than they should be • In a real global illumination situation, objects interreflect, redirecting light onto surfaces that are otherwise blocked • One way to simulate this is by changing the kA term:
Dynamic computation of ambient occlusion • In static scenes, kA and bent normal nbent can be precomputed • For dynamic scenes, it must be done on the fly • There are object space methods that involve casting rays from every vertex to every other vertex to determine intersections • Optimizations can be done that divide the screen up into hierarchies
Screen space ambient occlusion • Screen space ambient occlusion methods have become popular in recent video games such as Crysis and StarCraft 2 • Scene complexity isn't an issue • In Crysis, sample points around each point are tested against the Z-buffer • More points that are behind the visible Z –buffer give a more occluded point • A very inexpensive technique is to use an unsharp mask (a filter that emphasizes edges) on the Z-buffer, and use the result to darken the image
Next time… • Reflection • Transmittance • Refraction • Caustics • Subsurface scattering
Reminders • Keep working on Project 3 • Finish Assignment 4 • Due by midnight on Thursday • Keep reading Chapter 9