124 Views

Download Presentation
##### SIBGRAPI 2007

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**SIBGRAPI 2007**October 2007 Improved Real-TimeShadow Mapping for CAD Models Waldemar Celes TecGraf, Computer Science Dept., PUC-RIO celes@tecgraf.puc-rio.br Vitor Barata R. B. Barroso TecGraf, Computer Science Dept., PUC-RIO vbarata@tecgraf.puc-rio.br**Agenda**• Part I – Introduction • Part II – Survey • Self-shadowing • Bias techniques • Sample alignment • Filtering • Variance Shadow Maps • PCF • Perspective warping • Partitioning • Face partitioning • Z-partitioning (cascading) • Part III – Improvements • Generalized warp • Adaptive z-partitioning • Results**The Importance of Shadows**• Reveal information about spatial relationships among objects • Enhance realism • Games: Atmosphere and additional information • Scientific visualization: Facilitate model comprehension**Shadow Mapping Algorithm**• Render scene from light source’s viewpoint • Store the depth buffer in a texture (shadow map) • Render scene from camera’s viewpoint • Transform pixels back into light space (s,t,p,q) • zmap = acessed by (s/q, t/q) • zpixel = p/q • Fragment is lit ifzpixel <= zmap Camera Light Source Map zmap Occluder zpixel Shadow Light zpixel > zmap z’pixel z’map**Challenges**• Shadow mapping problems • Incorrect self-shadowing • Aliasing • CAD models • Thin and complex-silhouette objects • Non-solid objects • High depth range and depth complexity**Agenda**• Part I – Introduction • Part II – Survey • Self-shadowing • Bias techniques • Sample alignment • Filtering • Variance Shadow Maps • PCF • Perspective warping • Partitioning • Face partitioning • Z-partitioning (cascading) • Part III – Improvements • Generalized warp • Adaptive z-partitioning • Results**Self-shadowing**• Causes of self-shadowing • Numeric Precision • Discrete representation and unaligned samples • Basic solution: add a small bias to shadow map values Camera samples (pixels) Camera samples (pixels) Light samples (shadow map) Light samples (shadow map) Surface Surface Zp2 Zm2 Zm1 Zp1 Zp2 Zm2 Zm1 Zp1 Zp2 Zm2 light Zp2 Zm2 + bias light Zp1 > Zm1 shadow Zp1 Zm1 + bias light**Bias techniques**• Generalized bias function [Weiskopf03] zmap = z1 + zbias(z1,z2) • Constant bias: zbias = offset [Williams78] • Second-depth: zbias = z2-z1 [Wang94] • Midpoint: zbias = (z2–z1) / 2[Woo92] • Dual: zbias = min(zmid,zmax) [Weiskopf03] • Efficient second-depth requires solid objects • Dual yields great results, but requires 2 rendering passes • Constant bias must be tweaked for each case, but it is usually good enough with sample alignment**Sample alignment**• 2D sampled function reconstruction • Interpolate shadow map values? • Approximate camera samples at texel centers? texel center transformed pixel sample**Sample alignment**• Shadow map interpolation (or filtering) does not work well Light source Light Bleeding (B) Thick shadow (A) Occluder Surface Interpolated depths Background object**Sample alignment**• Camera sample reconstruction [Wang94] • Calculate camera “virtual samples” lying on the plane tangent to the surface • The plane equation can be obtained using the pixel position and normal, both available in fragment shaders • Calculate the coordinates of the virtual sample that lies on the plane and is properly aligned with the shadow map texel center**Variance Shadow Maps (VSMs)**• VSMs [Donnelly&Lauritzen06] produce strong light bleeding artifacts due to the model’s high depth complexity • Improvement: Summed-Area VSMs [Lauritzen07, GPU Gems 3]**Percentage-Closer Filter (PCF)**• Algorithm • Compare each pixel sample against several shadow map texels • Filter the result (0,1) of all shadow tests inside a kernel**Percentage-Closer Filter (PCF)**• Algorithm • Compare each pixel sample against several shadow map texels • Filter the result (0,1) of all shadow tests inside a kernel • Improvements • Texel-space sampling y x**Percentage-Closer Filter (PCF)**• Algorithm • Compare each pixel sample against several shadow map texels • Filter the result (0,1) of all shadow tests inside a kernel • Improvements • Texel-space sampling • Jittered sampling ymax y jitter x y x xmax**Percentage-Closer Filter (PCF)**• Algorithm • Compare each pixel sample against several shadow map texels • Filter the result (0,1) of all shadow tests inside a kernel • Improvements • Texel-space sampling • Jittered sampling • Circular kernel • Adaptive sampling • Camera virtual samples ymax y’ y jitter circular x’ x y R x xmax**Adaptive 5x5 PCF**Artifacts appear in low resolution shadow maps!**Aliasing Error Metric**• We define the aliasing error m as the ratio between the surface areas “seen” by a shadow map texel and an image pixel Light beam wL’ surface L c wc’ wc’ wc’ wc Camera beam wc’ wL’ > 1 aliasing wL’ wc’ wL**Aliasing Error Metric**• Desired: m=1 • m > 1 aliasing • m < 1 waste of resolution • Aliasing types • Perspective aliasing: wl/wc • Projection aliasing: cos(θc)/cos(θl) • Potentially unbounded • Less noticeable • Unaffected by warping techniques • Objective: minimize the maximum perspective aliasing error in the entire viewing frustum**Perspective Warping**• Deform the scene so that objects closer to the viewer are sampled in a larger shadow map area • This can also be interpreted as keeping the scene undeformed and adjusting the shadow map texel sizes • Very low cost, just calculate a transformation and multiply the scene’s viewing matrix by it**Perspective Warping**• PSM [Stamminger02]: • LiSPSM [Wimmer04]: • Standard SM: 0 t 1 map light V P y near z wC camera c far ’ wL Z-coordinate: Relative to the cameraRelative to c, the center of projection of frustum P 0 n z f 0 n’ z’ f’**Perspective Warping**• PSM [Stamminger02]: • LiSPSM [Wimmer04]: • Standard SM: • PSM • Minimizes error in the x direction, but produces linear error in z • LiSPSM • Small error in the x direction • Minimizes error in z, maximum occurs at near and far planes**Face Partitioning**map t1 t2 1 0 C B A • When the light is nearly parallel to the viewing direction, no perspective transform can produce good results for both A and C • Face-partitioning [Lloyd06]: • Divide the view frustum accord to its faces, as seen by the light source • Generate a different shadow map for each partition • Each shadow map can have its own perspective warp**Face Partitioning**• Yields great results when the light and camera are near parallel • No improvement when the light and camera are perpendicular • Costly, multiplies the number of shadow map generation passes by 4 • Z-partitioning (coming next) can produce better results for the same number of partitions [Lloyd06]**1/3**2/3 f n f n n n Z-Partitioning light V V 2 2a 2b camera y z 0 n f • The aliasing error is proportional to the (f/n) ratio [Lloyd06] • Thus, the maximum error can be reduced by partitioning the view frustum along the z-axis • The global error is minimal for self-similar partitions, that is, when every partition has the same (f/n) ratio**Agenda**• Part I – Introduction • Part II – Survey • Self-shadowing • Bias techniques • Sample alignment • Filtering • Variance Shadow Maps • PCF • Perspective warping • Partitioning • Face partitioning • Z-partitioning (cascading) • Part III – Improvements • Generalized warp • Adaptive z-partitioning • Results**Generalized LiSPSM Parameter**• Perspective warping is not suitable for near-parallel light and camera • PSM and LiSPSM both fall back to standard shadow mapping in this case • LiSPSM: • We want to keep LiSPSM’s minimal error when γ < π/2. γ = π/2 (best case) γ = 0(worst case) Viewing frustum as seen by the light source**Generalized LiSPSM Parameter**light 0 0 (z-n)sin() n’ z’ z-n n’ light f’ map z’ z’ n z a f f’ z z z a f b n V b map V z’ P a P a / tan()**Generalized LiSPSM Parameter**• Using the previous formulas and following the procedure described in [Wimmer04], we can find the ideal generalized LiSPSM parameter: • Problems: • n’2 should be negative for a very small γ! • If n’2 is too small, the minimum error increases as the warp becomes stronger than PSM • We must define a threshold γlim and make the parameter converge to standard SM for smaller values of γ:**Generalized LiSPSM Parameter**• Adjusting the parameter: GLiSPSM Corrected GLiSPSM**Seams with z-partitioning**• LiSPSM with perpendicular light and camera • mz(near) = mz(far) in each partition • mx is small and varies little • Seams are usually unnoticeable • LiSPSM with near-parallel light and camera • Converges to standard SM • Both mx and mz are maximal on the near plane of each partition • Noticeable seams appear between partitions • The ratio α=f/n should be kept small (2 to 4) in distant partitions to ensure small error**Adaptive z-partitioning**• Use γ, the angle between the light and viewing directions, as a linear interpolator • γ = π/2 optimal (f/n) • γ = 0 (f/n) = α • Calculate planes iteratively from the farthest one