DiFi: Distance Fields - Fast Computation Using Graphics Hardware Avneesh Sud Dinesh Manocha UNC-Chapel Hill http://gamma.cs.unc.edu/difi
Distance Fields Distance Function For a site a scalar function f:r n -> R representing the distance from a point P e R n to the site Distance Field For a set of sites, the minima of all distance functions representing the distance from a point P e R n to closest site
What is a Voronoi Diagram? Given a collection of geometric primitives, it is a subdivision of space into cells such that all points in a cell are closer to one primitive than to any other Voronoi Site Voronoi Region
Ordinary Point sites Nearest Euclidean distance Higher-order Sites Generalized Higher-order site geometry Varying distance metrics 2.0 0.5 Weighted Distances
Voronoi Diagram and Distance Fields Minimization diagram of distance functions generates a Voronoi Diagram [Sharir94] Projection of lower envelope of distance functions
Why Should We Compute Them? Useful in a wide variety of applications Collision Detection Surface Reconstruction Robot Motion Planning Non-Photorealistic Rendering Surface Simplification Mesh Generation Shape Analysis
GPU Based Computation HAVOC2D, HAVOC3D [Hoff99] Evaluate distance at each pixel for all sites Accelerate using graphics hardware Point Line Triangle
GPU Based Computation HAVOC2D, HAVOC3D [Hoff99] Evaluate distance at each pixel for all sites Accelerate using graphics hardware Steps Mesh approximation of Distance Functions Render distance meshes using graphics hardware Readback final buffers
Approximating the Distance Function Avoid per-pixel distance evaluation Point-sample the distance function Reconstruct by rendering polygonal mesh Point Line Triangle
Meshing the Distance Function Shape of distance function for a 2D point is a cone Need a bounded-error tessellation of the cone
Graphics Hardware Acceleration Rasterization to reconstruct distance values Depth test to perform minimum operator Perspective, 3/4 view Parallel, top view
Readback Results Color Buffer Depth Buffer Voronoi Regions Distance Field
3D Voronoi Diagrams Graphics hardware can generate one 2D slice at a time Sweep along 3 rd dimension (Zaxis) computing 1 slice at a time Polygonal model
Shape of 3D Distance Functions Slices of the distance function for a 3D point site Distance meshes used to approximate slices
Shape of 3D Distance Functions Point Line segment Triangle 1 sheet of a hyperboloid Elliptical cone Plane
Bottlenecks Rasterization: Distance mesh can fill entire slice Complexity for n sites and k slices = O(kn) Lot of Fill! Readback: Stalls the graphics pipeline Unsuitable for interactive applications
Outline Overview Culling Techniques Application Implementation and Results Demo!
Outline Overview Culling Techniques Application Implementation and Results Demo!
Overview: Framework Previous application framework GPU Render Distance Field Readback CPU Filter Distance Field Results
Overview Reduce fill: Cull using estimated voronoi region bounds GPU Render Distance Field Readback CPU Filter Distance Field Results
Overview Reduce fill: Cull using estimated voronoi region bounds Along Z: Cull sites whose voronoi regions don t intersect with current slice In XY plane: Restrict fill per site using planar bounds of the voronoi region
Overview: Framework Avoid readback: Perform distance field application on GPU GPU Render Distance Field Readback CPU Filter Distance Field Results
Voronoi Diagram Properties Within a bounded region, all voronoi regions have a bounded volume 9 Sites, 2D
Voronoi Diagram Properties Within a bounded region, all voronoi regions have a bounded volume As site density increases, average spatial bounds decrease 27 Sites, 2D
Voronoi Diagram Properties Voronoi regions are connected Valid for L 2, L inf norms
Voronoi Diagram Properties High distance field coherence between adjacent slices Change in distance function between adjacent slices is bounded Distance functions for a point site P i to slice Z j
Voronoi Diagram Properties High distance field coherence between adjacent slices Change in distance function between adjacent slices is bounded Distance functions for a point site P i to slice Z j+1
Outline Overview Culling Techniques Site Classification Estimating Z-Bounds Estimating XY-Bounds Applications Implementation and Results Demo!
Outline Overview Culling Techniques Site Classification Estimating Z-Bounds Estimating XY-Bounds Applications Implementation and Results Demo!
Site Culling: Classification For each slice partition the set of sites Slice j S 1 S 3 S 2 S 5 X Z S 4 Sweep Direction
Site Culling: Classification For each slice partition the set of sites, using voronoi region bounds: S 1 Slice j S 2 S 3 S 5 X Z S 4 Sweep Direction
Site Culling: Classification For each slice partition the set of sites, using voronoi region bounds: Approaching (A j ) Slice j S S 1 3 S 2 A j S 5 X S 4 Z Sweep Direction
Site Culling: Classification For each slice partition the set of sites, using voronoi region bounds: Approaching (A j ) Intersecting (I j ) X Z Slice j S 1 S 3 S 2 S 4 Sweep Direction A j I j S 5
Site Culling: Classification For each slice partition the set of sites, using voronoi region bounds: Approaching (A j ) Intersecting (I j ) Receding (R j ) X R j Z Slice j S 1 S 3 S 2 S 4 I j Sweep Direction A j S 5
Site Culling: Classification For each slice partition the set of sites, using voronoi region bounds: Approaching (A j ) Intersecting (I j ) Receding (R j ) Render distance functions for Intersecting sites only X R j Z Slice j S 1 S 3 S 2 S 4 I j Sweep Direction A j S 5
Coherence Updating I j I j+1 = I j Previously Intersecting Slice j+1 S 1 S 3 S 2 X Z S 4 Sweep Direction I j S 5
Coherence Updating I j I j+1 = I j + (A j A j+1 ) Approaching Intersecting Slice j+1 S 1 S 3 S 2 A j -A j+1 S 5 X Z S 4 Sweep Direction
Coherence Updating I j I j+1 = I j + (A j A j+1 ) (R j+1 R j ) Slice j+1 S 1 S 3 Intersecting Receding R j+1 -R j S 2 S 5 X Z S 4 Sweep Direction
Coherence Updating I j I j+1 = I j + (A j A j+1 ) (R j+1 R j ) Slice j+1 S 1 S 3 R j+1 S 2 I j+1 A j+1 X Z S 4 S 5 Sweep Direction
Outline Overview Culling Techniques Site Classification Estimating Z-Bounds Estimating XY-Bounds Applications Implementation and Results Demo!
Estimating Set Partitions Computing exact set partition = Exact voronoi computation Use hardware based occlusion queries Determine number of visible fragments Compute a set of potentially intersecting sites Î j Iˆ j I j
Estimating Z-Bounds Use BB tests to cull away approaching sites (A j ) Non-culled sites moved from A j to Î j+1 Render Î j+1 using occlusion queries Occluded sites moved from Î j to R j+1 Discarded for all further slices
Outline Overview Culling Techniques Site Classification Estimating Z-Bounds Estimating XY-Bounds Applications Implementation and Results Demo!
Estimating XY Bounds Monotonic distance functions
Estimating XY Bounds Monotonic distance functions Voronoi region s XY extent bounded by depth of distance function
Estimating XY Bounds Monotonic distance functions Voronoi region s XY extent bounded by depth of distance function Estimate max depth bounds for each site!
Estimating Depth Bound Render distance function in layers using occlusion query
Estimating Depth Bound Render distance field in layers using occlusion query
Estimating Depth Bound Render distance field in layers using occlusion query
Estimating Depth Bound Render distance field in layers using occlusion query First completely occluded layer bounds the max depth
Estimating Depth Bound Render distance field in layers using occlusion query First completely occluded layer bounds the max depth
Updating Depth Bound Exploit depth field coherence Given a depth bound for current slice, estimate a bound for next slice
Outline Overview Culling Techniques Applications Implementation and Results Demo!
Application: GPU Computation Avoid frame buffer readback GPU Render Distance Field Readback CPU Filter Distance Field Results
Application: GPU Computation GPU Avoid frame buffer readback Distance Field is a 3D grid : SIMD applications suitable for GPU computation Render Distance Field Copy to Texture Run Fragment Program Readback Results
GPU Application: GPU Computation Size of Results << Size of Distance Field Readback cost of results << Readback of Distance Field Render Distance Field Copy to Texture Run Fragment Program Readback Results
Application: Simplified MAT Foskey03: Separation criteria to extract a simplified medial axis
Blum Medial Axis Locus of centers of maximal contained balls Well-understood medial representation Applications Shape analysis Mesh generation Motion planning
T -Simplified Medial Axis M q A subset of the full medial axis M Relies on separation angle S(x)
Separation Angle Angle separating the vectors from x to nearest neighbors If more than 2 nearest neighbors, maximum angle is used x p 1 S(x) p 2
Large Separation Angle Point is roughly between its nearest neighbor points x
Small Separation Angle Point is off to one side of its nearest neighbor points x
Definition M θ = {x M S(x) > θ } Start with medial axis M Throw out all points with S(x) θ
3D Example: Triceratops q = 15 q = 30 q = 60
Direction Field Gradient of Distance Field Direction image rendered for each slice (constant z) Direction vectors encoded as RGB triples Length encoded in depth buffer
Direction Field
Direction Field
Adding Voxel Faces
Adding Voxel Faces
Adding Voxel Faces
Approximates True Medial Axis
Application: Simplified MAT GPU based computation GPU Render Direction Distance Field Copy to Float Readback Texture Frag. Filter Noise, Prog: Distance Add Separation Voxel Field Faces Filter Volume Render Results Render using with Quads 3D Tex
Outline Overview Culling Techniques Applications Medial Axis Computation Proximity Queries Implementation and Results Demo!
Implementation Dell Workstation with Pentium4 CPU at 2.8Ghz nvidia GeForce FX5800 Ultra GPU 2GB RAM Windows 2000
Results: MAT Computation Total time = Time(Direction Field) + Time(Filter Voxels)
Direction Field Computation 4-20 times speedup! Model Polys Resolution HAVOC (s) DiFi (s) Shell Charge 4460 128x126x126 31.69 3.38 Head 21764 79x106x128 52.47 13.60 Bunny 69451 128x126x100 212.71 36.21 Cassini 90879 94x128x96 1102.01 47.90
Filter Voxels 2-75 times speedup! Model Resolution CPU (s) GPU (s) Shell Charge 128x126x126 3.50 0.14 Head 79x106x128 0.18 0.08 Bunny 128x126x100 0.68 0.13 Cassini 94x128x96 7.59 0.1
Outline Overview Culling Techniques Applications Medial Axis Computation Proximity Queries Results Demo!
Demo: MAT computation Triceratops model Shell model : CAD model Sharp edges, hence point sampling methods not adequate Non-manifold
Future Work Distance field computation: Not quite real time for large models Applications: Proximity Queries and Collision Detection
References A. Sud and D. Manocha. DiFi: Fast distance field computation using graphics hardware. UNC-CH Computer Science Technical Report TR03-026, 2003 http://gamma.cs.unc.edu/difi M. Foskey, M. Lin, and D. Manocha. Efficient computation of a simplified medial axis. Proc. of ACM Solid Modeling, 2003.
Acknowledgements Sponsors Greg Coombe, Mark Harris Mark Foskey Naga Govindaraju UNC GAMMA group
The End