Anti-aliasing and Continuity using Trapezoidal Shadow Maps Speaker: Tobias Martin Co-Author: Tiow-Seng Tan National University of Singapore Standard Shadow Maps Content Shadows in Computer Graphics Standard Shadow Maps (SSM) Problems with SSM Problem #1: Aliasing/Resolution Problem #2: Polygon Offset Problem #3: Continuity Trapezoidal Conclusion Shadow Maps Shadows in Computer Graphics Why? Spatial relationship between objects is better perceivable Realism is enhanced Our Requirements: Robust shadows in real-time (Screenshots taken from “shadowcast.exe” by Mark J. Kilgard, NVIDIA) Standard Shadow Maps (SSM) 1. Shadow Map Generation: • Transform scene into post-perspective space (PPS) of light, i.e.: vL = PL · CL · W · v • Render scene from this space • Copy depth buffer into shadow map 2. Shadow Determination: • Render scene in eye’s PPS and perform shadow test per-fragment • Fragment is in shadow iff zp > shadowmap[xp, yp], where xp, yp and zp is fragment in PPS of light (Screenshots taken from “shadowcast.exe” by Mark J. Kilgard, NVIDIA) Standard Shadow Maps (SSM) Problem #1: Resolution Problem Jagged shadow boundary appears due to low resolution in shadow map Trivial solution: Increase shadow map size to increase resolution & improve quality Standard Shadow Maps (SSM) Problem #2: Polygon Offset Due to finite precision, surfaces can cast wrong shadows on themselves Practical Solution: Adding offset to depth values to move shadow slightly away from light Current Solutions Problem #3: Continuity (1) Straightforward approximation can result in shadow discontinuities e.g. in Perspective Shadow Maps (PSM) [Stamminger and Drettakis 2002] e.g. in the Bounding Box Approximation (BB) [Brabec et al. 2002] Frame i Frame i +1 Current Solutions Problem #3: Continuity (2) What happens if shadow map depends on dynamic scene geometry? light light scene’s bounding box eye scene’s bounding box eye n frames later ”tight” hull contains shadow occluders ”expanded” hull contains shadow occluders good shadow map quality shadow map quality worsened Trapezoidal Shadow Maps (TSM) Solution Shadow map generation focuses on area potentially visible to the eye Solution to Problem #2 (Polygon Offset) Depth values are preserved, so that problem is not worsened Solution to Problem #1 (Resolution) to Problem #3 (Continuity) Frame coherent technique resulting in a continuous change in shadow map resolution Trapezoidal Shadow Maps (TSM) PPS of light NT A Shadow map resolution is increased Shadow aliasing is reduced trapezoidal space Trapezoidal Shadow Maps (TSM) Solution to Problem #1 SSM algorithm is slightly modified: Calculate shadow map in the trapezoidal space, and perform the shadow test there as well, i.e.: vT = NT · PL · CL · W · v Except for the calculation of NT the algorithm can completely be mapped to graphics hardware! Trapezoidal Shadow Maps (TSM) Side effect of the trapezoidal transformation (a) Uniform distribution (b) Non-uniform distribution a) Approximation of an eye's frustum with a trapezoid b) Applying NT may lead to severe polygon offset problems Different distribution of z-values require different offsets Trapezoidal Shadow Maps (TSM) Solution to (worsened) Problem #2: Apply NT only to the x- and y-values Maintain z in PPS of light: Store (xT , yT , zL) in the shadow map Simply applying NT Applying modified NT Trapezoidal Shadow Maps (TSM) 1st pass (Shadow Map Generation) Vertex stage: • vT = NT · PL · CL · W · v • vL = PL · CL · W · v Fragment stage: • shadowmap[xT, yT]= zL instead of zT Use additional texture coordinate vL and replace zT with zL per fragment Trapezoidal Shadow Maps (TSM) 2nd pass (Shadow Determination) Vertex stage: • vE = PE · CE · W · v • vT = NT · PL · CL · W · v • vL = PL · CL · W · v Fragment stage: • Fragment in shadow iff zL > shadowmap[xT, yT] Use additional texture coordinate vL and use zL for shadow map comparison Trapezoidal Shadow Maps (TSM) Solution to Problem #3 Base and Top Lines: Center Line 2D-Convex Hull l lt CHE Base & Top Line lb Center line governs the choices of top and base line top and base line transit smoothly from frame to frame Trapezoidal Shadow Maps (TSM) Side Lines: 80% rule governs the choices 0% Focus region of the eye 80% line Trapezoidal approximation in L Trapezoidal space due to 80% rule Trapezoidal Shadow Maps (TSM) Calculate NT that pL is mapped to 80% line in T Calculate q using 1D perspective projection (Minus signs in the proceedings got eaten up by the printer) Trapezoidal Shadow Maps (TSM) Trapezoidal Shadow Maps (TSM) Indication for Continuity Plot of the total area covered by focus region in shadow map Change in frustum are color encoded Trapezoidal Shadow Maps (TSM) General case: Eye’s frustum E is not completely within then light’s frustum L Algorithm can be easily adjusted Singularities are avoided light light eye light eye eye Results Fantasy World: BB vs. PSM vs. TSM Urban Model: PSM vs. TSM Conclusion TSM addresses 1) 2) 3) …following the 3 principles Resolution Problem Polygon Offset Problem Continuity Problem Effectiveness of 80% rule Simplicity which is difficult to achieve Continuity rather than “correctness” Q and A http://www.comp.nus.edu.sg/~tants/tsm.html TSM Literature BRABEC, S., ANNEN T., AND SEIDEL, H. 2002. Practical Shadow Mapping. Journal of Graphics Tools 7(4), 9–18. CROW, F. C. 1977. Shadow Algorithms for Computer Graphics. In Proceedings of SIGGRAPH 1977, 242–248. STAMMINGER, M., AND DRETTAKIS, G. 2002. Perspective Shadow Maps. WILLIAMS, L. 1978. Casting curved shadows on curved surfaces. In Proceedings of SIGGRAPH 1978, 270–274. WOO, A., POULIN, P., AND FOURNIER, A. 1990. A survey of shadow algorithms. IEEE Computer Graphics and Applications, 10(6), 13– 32.