Real-Time Shadows Eric Haines [email protected] Tomas Moller¨ [email protected]

Real-Time Shadows Eric Haines Erich@Acm.Org Tomas Moller¨ Tompa@Acm.Org

Real-Time Shadows Eric Haines [email protected] Tomas Moller¨ [email protected] [Excerpted and updated from the book ”Real-Time Rendering”, by Tomas Moller¨ and Eric Haines, A.K. Peters, ISBN 1568811012. See http://www.realtimerendering.com/] Shadows are important elements in creating a realistic image and in providing the user with visual cues about object placement. A review of many different shadow algorithms is found in the survey published by Woo et al. [23] and in Watt and Watt’s book [21]. Here we will present the most important real-time algorithms for dynamic shadows. The first section handles the special case of shadows cast on planar surfaces, and the second section covers more general shadow algorithms, i.e., casting shadows onto arbitrary surfaces. 1 Planar Shadows A simple case of shadowing occurs when objects cast shadows on planar surfaces. Two kinds of algorithms for planar shadows are presented in this section. The terminology used here is illustrated in Figure 1, where occluders are objects that cast shadows onto receivers. Point light sources generate only fully shadowed regions, sometimes called hard shadows. If area light sources are used, then soft shadows are produced. Each shadow can have a fully shadowed region, called the umbra, and a partially shadowed region, called the penumbra. light source occluder receiver shadow umbra penumbra Figure 1: Shadow terminology: light source, occluder, receiver, shadow, umbra, and penumbra. That is, at least, how it works in the real world. As we will see, soft shadows (i.e., with penumbrae) can be simulated by the shadow map algorithm. We will also present other methods that generate more physically accurate soft shadows. Soft shadows are generally preferable, if they are possible, because the soft edges let the viewer know that the shadow is indeed a shadow. Hard-edged shadows can sometimes be misinterpreted as actual geometric features, such as a crease in a surface. More important than having a penumbra is having any shadow at all. Without some shadow as a visual cue, scenes are often unconvincing and more difficult to perceive. As Wanger shows [20], it is usually better to have an inaccurate shadow than none at all, as the eye is fairly forgiving about the shape of the shadow. For example, a blurred black circle applied as a texture on the floor can anchor a person to the ground. A simple black rectangular shape fading off around the edges, perhaps a total of 10 triangles, is often all that is needed for a car’s soft shadow. In the following sections we will go beyond these simple modeled shadows and present methods that compute shadows automatically in real-time from the occluders in a scene. 1.1 Projection Shadows In this scheme, the three-dimensional object is rendered a second time in order to create a shadow. A matrix can be derived that projects the vertices of an object onto a plane [2, 17]. Consider the situation in Figure 2, where the light source is located at , the vertex to be ¢ projected is at ¡ , and the projected vertex is at . We will derive the projection matrix for the special case where the shadowed plane is £¥¤§¦ , then this result will be generalized to work with any plane. ¨ © 0 1 )+*,.- / ! "#%$&' ( 35476 8 Figure 2: Left: A light source, located at 2 , casts a shadow onto the plane . The vertex is projected onto the plane. The projected point is called 9 . The similar triangles are used for the derivation of the projection matrix. Right: The notation of the left part of this figure is used here. The shadow is being cast =¥> ?5@BAC476 onto a plane, :<; . We start by deriving the projection for the D -coordinate. From the similar triangles in the left part of Figure 2, the following equation is obtained. E FHGJI F I N K GJI I G7K F FML N N O<P (1) I K GJI K N F F N E F I GJK N N L S S I K RGTI R K I GTK ER N N U V N N U W The Q -coordinate is obtained in the same way: , while the -coordinate L is zero. Now these equations can be converted into the projection matrix X below. b c YZ I GCI N F]\^\ c Z \_\`\^\ X R GCI I N \ \ (2) L d [ G5a I N \ \ X It is easy to verify that Xfe , which means that is indeed the projection matrix. L§g \ In the general case, the plane onto which the shadows should be cast is not the plane W , L \ l<m7n but instead hTi jMk . This case is depicted in the right part of Figure 2. The goal is again L o to find a matrix that projects e down to . To this end, the ray emanating at , which goes g h through e , is intersected by the plane . This yields the projected point : g S nCmJjBk o G G U S e o o (3) G gTL U jpk e o This equation can also be converted into a projection matrix, shown in Equation 4, which satisfies Xfe . L§g YZ b c GJI GHI GHI R GHI F q.F F q.N F q F Z c jpk o.mJn n GHI GJI GCI R GCI N q.F N q.N N q N jpk o.mJn n X GCI R GHI R GJI R RrGHI R q.F q.N q (4) L [ d jpk omJn n G G G R q.F q.N q jpk o \ As expected, this matrix turns into the matrix in Equation 2 if the plane is W (that is, L S a \ \U s \ n j and ). L L To render the shadow, simply apply this matrix to the objects that should cast shadows on the plane h , and render this projected object with a dark color and no illumination. In practice, you have to take measures to avoid allowing the projected polygons to be rendered beneath the surface receiving them. One method is to add some bias to the plane we project upon so that the shadow polygons are always rendered in front of the surface. Getting this bias just right is often tricky: too much and the shadows start to cover the objects and so break the illusion; too little and the ground plane pokes through the shadows due to precision error. As the angle of the surface normal away from the viewer increases, the bias must also increase. A safer method is to draw the ground plane first, then draw the projected polygons with the t -buffer off, then render the rest of the geometry as usual. The projected polygons are then always drawn on top of the ground plane, as no depth comparisons are made. A flaw with projection shadows is the one we ran into with reflections: the projected shadows can fall outside of our plane. To solve this problem, we can use a stencil buffer. First draw the receiver to the screen and to the stencil buffer. Then, with the u -buffer off, draw the projected polygons only where the receiver was drawn, then render the rest of the scene normally. Projecting the polygons this way works if the shadows are opaque. For semi-transparent shadows, where the underlying surface color or texture can be seen, more care is usually needed. A convex object’s shadow is guaranteed to have exactly two (or, by culling backfaces, exactly one) projected polygons covering each shadowed pixel on the plane. Objects with concavities do not have this property, so simply rendering each projected polygon as semi-transparent will give poor results. The stencil buffer can be used to ensure that each pixel is covered at most once. Do this by incrementing the stencil buffer’s count by each polygon drawn, allowing only the first projected polygon covering each pixel to be rendered. A disadvantage of the projection method, in addition to its limitation to planar surfaces, is that the shadow has to be rendered for each frame, even though the shadow may not change. Since shadows are view-independent (their shapes do not change with different viewpoints), an idea that works well in practice is to render the shadow into a texture which is then rendered as a textured rectangle. The shadow texture would only be recomputed when the shadow changes, that is, when the light source or any shadow-casting or -receiving object moves. with synthetic objects forming the texture on the fly. Another method to improve performance is to use simplified versions of the models for generating the shadow projections. This technique can often be used for other shadowing algorithms. The matrices in Equations 2 and 4 do not always generate the desired results. For example, if the light source is below the topmost point on the object, then an anti-shadow [2] is generated, since each vertex is projected through the point of the light source. Correct shadows and anti-shadows are shown in Figure 3. A similar rendering error as that found with planar reflections can occur for this kind of shadow generation. For reflections, errors occur when objects located on the opposite side of the reflector plane are not dealt with properly. In the case of shadow generation, errors occur when we use a shadow-casting object that is on the far side of the receiving plane. This is because an object beyond the shadow receiver does not cast a shadow. Shadows generated in this manner are called false shadows. This problem can be solved in the same manner as for planar reflections, i.e., with a clipping plane located at the shadow receiver that culls away all geometry beyond the receiver.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    18 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us