Unformatted text preview:

Adding Shadows to the World Our illumination model does not incorporate shadows only diffuse specular and ambient reflection I I L kd cos I L k s cos n I a ka we always incorporate contribution of light sources even if there s an object in the way How do we get shadows more advanced rendering methods e g ray tracing and radiosity or do some clever things The Structure of Shadows Point Light Source Occluder or Blocker Shadow 1 Starting with a Restricted Solution Let s make some simplifying assumptions about the world the world contains objects a ground plane only care about shadows on this ground plane so we are willing to ignore shadows of one object on another self shadowing by a single object What problem do we need to solve given a point and a plane project an object onto this plane sounds kind of familiar Projective Shadows The point p lies at the intersection of ray L t v L and plane n u d 0 Substitute ray into plane equation n L t v L d 0 solve for t substitute back into ray equation for p L v p This gives us a linear equation for p d n L p L v L n v L plane n u d 0 2 Projective Shadows We ve derived a linear equation for a projected shadow point d n L p L v L n v L From this we can derive a corresponding projection matrix given a point v on the object compute its projection p on the ground plane p Mv where n L d Lx nx L y nx M Lz nx nx Lx n y n L d Ly n y Lz n y ny Lx nz L y nz n L d Lz nz nz Lx d Ly d Lz d n L Drawing Projective Shadows Requires an extra drawing pass for every light first we draw everything the normal way and for each light draw every object using shadow projection load our special transformation turn off lighting and draw in a very dark color Need to resolve some practical issues to make sure this works must make sure shadow is always on top of ground plane can use glPolygonOffset for that or draw plane then shadow with Z buffer off then world must make sure shadow doesn t extend past edges of ground our transformation projects onto an infinite plane but the ground may have boundaries can solve this by using the stencil buffer 3 The OpenGL Stencil Buffer Another buffer alongside the frame buffer and depth buffer typically 8 bits per pixel can subject fragments to a stencil test during rasterization those that fail the test don t get written to frame buffer turned on with glEnable GL STENCIL TEST test selected with glStencilFunc control writing into stencil buffer with glStencilOp Among other things can be used to mask drawing operations fill in the stencil pixels where drawing is allowed say with 1 draw scene with glStencilFunc GL EQUAL 1 1 fragments where stencil is not 1 are discarded see Red Book for more details Another Problem Anti Shadows Projective shadows can actually produce anti shadows everything is fine if the light is above the blocker relative to the ground plane problematic if lower than topmost point of the blocker 4 What Points are in Shadow All points for which rays to from light source are blocked In other words all the points that the light can t see this sounds like visible surface determination Casting More General Shadows Suppose we have a scene like the one below we want to be able to cast shadows on any object 5 The View from the Light Source Let s render the scene from the lights viewpoint and keep the Z buffer as shown below We ve Generated a Shadow Buffer Gives us the distance of the closest object to the light any objects further away are in shadow Suppose we re shading a surface point project back into shadow map compare distance of current point to value in the map if the current distance is greater we re in shadow One important catch to consider this discrete sampling can easily result in aliasing which leads to artifacts like point wise self shadowing 6 Drawing with Shadow Buffers and OpenGL First compute the shadow buffer for the light source Next render the scene with only ambient lighting we only want to deal with visible surfaces Compare z values in view with z values in shadow buffer but remember these are depths from two different points if this is the nearest object set pixel 1 otherwise set pixel 0 Finally render the entire scene again with lighting set things up so that colors are multiplied by just set up glBlendFunc appropriately objects in shadow will have their colors zeroed The More General Lesson Rendering is not just for producing pictures we can use it to acquire information about the world clever combinations of rendering passes are powerful tools Shadow maps are a good example of this render the world to produce shadow maps make use of blending to combine results We can also make good use of additional OpenGL buffers in particular we ve seen a simple use of the stencil buffer 7 From Hard to Soft Shadows These techniques can help us generate shadows but these shadows have perfectly sharp boundaries real shadows are soft rather than hard because lights in the real world are not point light sources The Structure of Shadows Area Light Source Occluder or Blocker Penumbra partial shadow Umbra complete shadow Penumbra partial shadow 8 From Hard to Soft Shadows Can try to build soft shadows by combining hard shadows suppose we sample several points on an area light source treat each one as a point light compute shadows now imagine averaging all these shadows together we get an approximation of the correct soft shadow objects in umbra are in shadow with respect to all samples objects in penumbra are only in some of the shadows Or we can rely on more sophisticated algorithms as we ll see later radiosity naturally produces soft shadows Multipass Rendering Enables Many Things But we can achieve many effects with multiple passes we ve already seen a couple of examples of this Multiple passes for environment maps first we render the world to create an environment map then we render again to apply this reflection Multiple passes for shadows shadow map algorithm we discussed is another good example we render the world from each light position and use multiple passes to generate shadows 9 Removing Hidden Lines with 2 Passes Notice that we see all the lines even for triangles in back which can be confusing There are many algorithms for this was once an important problem But OpenGL provides us a nice trick first draw all the polygons but in the background color now draw all the wireframe lines To make this look nice see glPolygonOffset make lines sit on top of polygons Another Simple Multipass Example Mirrors Suppose we


View Full Document

U of I CS 418 - Adding Shadows to the World

Loading Unlocking...
Login

Join to view Adding Shadows to the World and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Adding Shadows to the World and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?