280 likes | 687 Views
Planar Shadow Map with Edge Buffer. Final Project for C.S. 870 By Shawn Brown. Goals. Reduce BIAS: reduce artifacts casued by self-intersection and numerical precision by storing a plane equation instead of single depth value at each pixel in shadow map.
E N D
Planar Shadow MapwithEdge Buffer Final Project for C.S. 870 By Shawn Brown
Goals • Reduce BIAS: reduce artifacts casued by self-intersection and numerical precision by storing a plane equation instead of single depth value at each pixel in shadow map. • Improve Pixilated Appearance: Reduce pixilated appearance of shadows via an edge buffer.
Shadow Maps • Introduced by Lance Williams in 1978 • An simple high performance method for generating shadows using an one or more extra frame buffers per light and z-buffering techniques
Basic Algorithm • Render from point of view of the light source. • For each pixel, record distance (z-depth) from light source in the in the shadow map frame buffer. • Render from point of view of the camera. • For each hit point • map hit point from world space into light space, • compute it’s distance from light, zC = dist(Light – HP) • find stored depth value in shadow map, zL = SM<x,y> • If (zC > zL) then in shadow else compute lighting
Shadow Mapfrom light source Rendered Imagefrom Camera Image from “Perspective shadow maps” by M. Stamminger & G. Drettakis in SIGGRAPH 2002, p. 557-562
Image Artifacts Self – Shadowing Or Numerical precision Artifacts Blocky Appearance Of Shadow
Step 1: Planar Shadow Mapping • Concept first introduced by ATI as part of their 2005 SDK • Replace single z-depth value per pixel by a 3D plane equation (Ax+By+Cz+D) across surface of pixel • Still need a small bias value for numerical precision issues 2D Analogy Rectangle vs. Trapezoid pl1 pl2 pl3 z1 z2 z3 Plane Buffer Depth Buffer
Plane & Edge Equations • Plane Equation • Ax + By + Cz + D = 0 • Alternate form N∙P=c, N=<A,B,C> • Test a point (above (>0), below (<0), equal (=0) • Can be computed from point and normal at point • D = -(A∙P.x + B∙P.y +C∙P.z) • Edge Equation • Ax + By + C = 0 • Alternate form Perp┴∙P=c, Perp=<A,B> • Test a point (left (<0), right (>0), equal (=0) • Can be computed from point and direction at point • C = -(A∙P.x + B∙P.y)
Algorithm with Planes • Render from point of view of the camera. • For each hit point • map hit point from world space into light space, • compute it’s distance from light, zC = dist(Light – HP) • Look up planar equation <A,B,C,D> = SM(x,y) • <x,y> values already known from transform • Compute z’ = -(A∙x + B∙y + D)/C • Compute distance zL = dist(<x,y,z’> - LightPos) • If (zC > zL+bias) then in shadow else compute lighting
UL UL UM UM UR UR ML ML MR MR LL LL LM LM LR LR Step 2: Add an Edge Buffer • Reduce pixilated appearance of shadow edges by adding canonical edge information to each pixel. Uniform Plane across entire pixel for shadow testing Borrow Neighbor Planes as better approximations along border pixels VS.
Border Pixels • Store Object ID’s for each pixel in shadow map. • Look at eight neighbors of each pixel • Homogenous set = interior pixel • Heterogeneous set = potential border pixel Interior pixel Border pixel
Categorize Neighborhoodsusing Border Map • Small portion of border map showing border and interior pixels • 16 distinct cases for 4 corner test, 256 cases for 8 way test
UL UM UR 4 5 6 7 8 3 9 ML 2 10 MR 1 11 0 15 14 13 12 LL LM LR Canonical Edges • 16 points equally spaced around border of Unit cube • 16 starting points x 16 ending points = 256 edges • each canonical edge can be represented by a single byte Identity Edges: 4 → 4, not a valid edge, 16 entries of this form. Solution: could add new edges Border Edges: 4 → 5, valid but not useful 4 x 16 = 48 entries of this form Solution: could add new edges Edges thru Center: 4 → 12 ambiguous, There are 16 edges of this form. Solution: use neighbor pixels for resolving ambiguity Symmetry: 4 to 12 = 12 to 4. Not a problem, directed edges needed for proper testing.
UL UL UM UM UR UR 4 4 5 5 6 6 7 7 8 8 3 3 9 9 ML ML 2 2 10 10 MR MR MM MM 1 1 11 11 0 0 15 15 14 14 13 13 12 12 LL LL LM LM LR LR 4 Corner Tests • Test ray traced objects at 4 corners against object at center • 16 test cases, test cases require 1-4 edge tests to resolve properly Original Approach Use middle points (1/2) for canonical edges Alternate Approach Use quarter points (1/4, 3/4) for canonical edges
UL UM UR 4 5 6 7 8 3 9 ML 2 10 MR MM 1 11 0 15 14 13 12 LL LM LR 8 Way Test • Test ray traced objects at 8 positions against object at center • 256 test cases, test cases require 1-8 edge tests to resolve • Use canonical edges involving ¼, ½, ¾ points
Algorithm with Edge Buffer • Render from point of view of the camera. • For each hit point • map hit point from world space into light space, • compute it’s distance from light, zC = dist(Light – HP) • Use Edge buffer to pick plane from current pixel or one of its 8 neighbors • Compute distance zL as before from picked plane • If (zC > zL+bias) then in shadow else compute lighting
Results (I) Ray Traced Shadows Planar Shadow Map
Results (II) Planar Shadow Map 4 Corner Edge Buffer
Results (III) 4 Corner Edge Buffer 4 Corner Alternate
Results (IV) Ray Traced Shadows 8 Way
Differences Planar Shadow Map 4 Corner Edge Buffer
Differences (II) 4 Corner Alternate 8 Way
Conclusion • Summary: Interesting but not compelling • Looks better (8 way > 4 corner > than planar) • Needs further refinement • Pro: Simple to implement (tedious for 8 way case) • Pro: Only needs 1 extra byte per pixel for edge classification • Con: Regular Patterns (canonical edges) • Con: No interior corners (get truncated)
Future Improvements (I) Regular Patterns • Snapping results to Canonical edges result in to much regularity in edge patterns of shadows. • Add t values (1 byte) to each edge to allow edges to more closely track actual silhouette edges • Use ray tracing and binary search to find approximate location of t value along each edge
Future Improvements (II) No true corners inside pixel • Use t values of edges in extended neighborhood to infer edges and intersections of edges inside pixel • Store <s,t> value for each corner in pixel • Allow maximum of 1-2 corners, • Merge extra corners if more than maximum
Thank You Any Questions?
References • Williams, L. “Casting curved shadows on curved surfaces”. Computer Graphics - Proceedings of SIGGRAPH 1978, 12 (3), 270–274 • M. Stamminger & G. Drettakis, “Perspective shadow maps”, ACM Transactions on Graphics (TOG), v.21 n.3, July 2002 • ATI Technical Document and sample source code, “Plane Shadow Mapping”, part of ATI Radeon 2005 SDK (Archived). • Pharr, M. & Humphreys G., “Physically Based Rendering, From Theory to Implementation” 2004, San Francisco, Elsevier – Morgan Kaufmann