Presentation is loading. Please wait.

Presentation is loading. Please wait.

GPGPU: Distance Fields

Similar presentations


Presentation on theme: "GPGPU: Distance Fields"— Presentation transcript:

1 GPGPU: Distance Fields
Avneesh Sud and Dinesh Manocha Feb 12, 2007

2 So Far Overview Intro to GPGPU using OpenGL
Current Architecture (Cell, G80) Programming (CUDA, Compilers) Applications (Vision)

3 Interesting Reading on Parallel Computing
The Landscape of Parallel Computing Research: A View from Berkeley

4 This Lecture Distance Fields and Voronoi Diagrams Hands on demo
Advanced: Optimization Discussion: Why fast on a GPU?

5 This Lecture Distance Fields and Voronoi Diagrams
Hands on application demo Parallel algorithm Example code: 2D Visual Debugging (imdebug) Example code: 3D Advanced: Optimization Discussion: Why fast on a GPU?

6 Outline Distance Fields and Voronoi Diagrams Hands on application demo
Advanced: Optimization Discussion: Why fast on a GPU?

7 Distance Field Given a set of geometric primitives (sites), it is a scalar field representing the minimum distance from any point to the closest site Given a set of … Here we show an example with 3 pt sites and their 2d dist field Sites 2D Distance field

8 Generalized Voronoi Diagram
Given a collection of sites, it is a subdivision of space into cells such that all points in a cell are closer to one site than to any other site Voronoi Site Voronoi cell Distance fields are closely related to Voronoi diagrams Given a collection of sites, a Voronoi diagram is a subdivision of space into cells, such that all points in a cell are closer to one primitive than to any other. Make brighter Sites Voronoi diagram

9 Voronoi Diagram and Distance Fields
Region where distance function contributes to final distance field = Voronoi Region … is the Voronoi region of that site Distance field Voronoi diagram

10 Distance Functions: 2D A scalar function f (x) representing minimum distance from a point x to a site A distance function is a … The distance function can be drawn as a graph with z = value The distance function to a pt in 2D corresponds to a cone. graph z = f (x,y) f (x,y)=√x2+y2

11 Distance Functions: 3D Distance function of a site to plane is a quadric Point Site Circular Paraboloid Line Site Elliptic Cone Plane Site Plane

12 Why Should We Compute Them?
Collision Detection & Proximity Queries Robot Motion Planning Surface Reconstruction Non-Photorealistic Rendering Surface Simplification Mesh Generation Shape Analysis Voronoi diagrams have also been useful in a wide variety of recent applications. Here are some common examples.

13 Why Difficult? Exact Computation Analytic Boundary
Compute analytic boundaries These algorithms compute analytic boundaries which requires representing and manipulating high-degree curves and surfaces and their intersections This not only makes them complex and difficult to implement, but it also makes them suffer from robustness and accuracy problems. In an attempt to overcome many of these difficulties, approximate algorithms are often used. Analytic Boundary

14 Why Difficult? Exact Computation
Compute analytic boundaries Boundaries composed of high-degree curves and surfaces and their intersections Complex and difficult to implement Robustness and accuracy problems These algorithms compute analytic boundaries which requires representing and manipulating high-degree curves and surfaces and their intersections This not only makes them complex and difficult to implement, but it also makes them suffer from robustness and accuracy problems. In an attempt to overcome many of these difficulties, approximate algorithms are often used.

15 Approximate Computation
Approximate Algorithms Approximate algorithms simplify the problem by either discretizing the sites or by discretizing the space containing the sites. In the center image, the higher-order line site is point-sampled. The Voronoi diagram of these points forms a piecewise-linear approximation to the Voronoi boundary. In the right image, a volumetric representation is constructed by determining which Voronoi regions contain each sample point. We will be computing this type of approximation. Discretize Sites Discretize Space GPU

16 Outline Distance Fields and Voronoi Diagrams Hands on application demo
Parallel algorithm Example code: 2D Visual Debugging (imdebug) Demo: 3D Advanced: Optimization Discussion: Why fast on a GPU?

17 Brute-force Algorithm
Record ID of the closest site to each sample point The brute-force approach is very simple: We begin with a bounded region of space containing the Voronoi sites. We then point-sample the space and for each sample point, we compute distances to all sites and record the ID and distance of the closest site. This forms the volumetric approximations shown in the right two images. This approach is simple and very easy to generalize since it only requires the distance between a site and a sample point. In addition, the most dominant error results from the point-sampling density which is simple to bound. Coarse point-sampling result Finer point-sampling result

18 Slight Variation…   = 
The brute-force approach is very simple: We begin with a bounded region of space containing the Voronoi sites. We then point-sample the space and for each sample point, we compute distances to all sites and record the ID and distance of the closest site. This forms the volumetric approximations shown in the right two images. This approach is simple and very easy to generalize since it only requires the distance between a site and a sample point. In addition, the most dominant error results from the point-sampling density which is simple to bound. For each site, compute distances to all sample pts Given sites and uniform sampling Composite through minimum operator Record IDs of closest sites

19 GPU Algorithm…   =  For each site, compute distances to all pixels
The brute-force approach is very simple: We begin with a bounded region of space containing the Voronoi sites. We then point-sample the space and for each sample point, we compute distances to all sites and record the ID and distance of the closest site. This forms the volumetric approximations shown in the right two images. This approach is simple and very easy to generalize since it only requires the distance between a site and a sample point. In addition, the most dominant error results from the point-sampling density which is simple to bound. For each site, compute distances to all pixels Given sites and frame buffer Composite through depth test Read-back IDs of closest sites

20 GPU Algorithm: 2D Demo: Point site Point coord Pixel coord
(uniform parameter) Pixel coord

21 GPU Algorithm: 2D Source
Initialization Setup GL State (Depth, Render Target) Setup fragment program Fragment program Computation: For each point site Set program parameters Execute fragment program Display Display results

22 GPU Algorithm: 2D Source
Show source … Compile cg source and show assembly

23 GPU Algorithm: Debugging
Visual debugging with imdebug (by Bill Baxter) Steps Modify fragment program Readback and display buffer contents

24 GPU Algorithm: Debugging
Example

25 GPU Algorithm: 2D Demo: Line site
End-Point coords (uniform parameters) Pixel coord Careful: Equation is to an infinite line

26 GPU Algorithm: 2D Line segment: Region closer to interior of line segment In remaining region?

27 GPU Algorithm: 3D Graphics hardware computes one 2D slice
Sweep along 3rd dimension (Z-axis) computing 1 slice at a time In order to use the graphics hardware for constructing 3D Voronoi diagrams, we compute the volume one slice at a time. This animation shows the Voronoi diagram computed over a teapot in 3D. Subsequently everything is in 3D - Computing distance at each voxel to all sites is slow for large # of sites and… 3D Voronoi Diagram

28 Outline Distance Fields and Voronoi Diagrams Hands on application demo
Advanced: Optimization Discussion: Why fast on a GPU?

29 GPU Optimizations Where to optimize? Make fragment program run faster
GPU / Application dependent optimizations Reduce memory bandwidth Reduce number of invocations of fragment program Geometric culling

30 GPU Optimizations: Recommended Reading
Practical Performance Analysis and Tuning GPU Programming Guide GPU Gems 2 GPU Computation Strategies and Tips (Ian Buck) GPU Program Optimization (Cliff Woolley)

31 GPU Optimizations Where to optimize? Make fragment program run faster
GPU / Application dependent optimizations Reduce memory bandwidth Reduce number of invocations of fragment program Geometric culling

32 Optimization: Fragment Program
Reduce number of instructions! Do we need dist(x, p) or dist2(x, p)? Advantage: dist() requires an additional reciprocal sqrt Show code + demo

33 Optimization: Fragment Program
Do we need to evaluate (x – p) in fragment program?

34 Optimization: Fragment Program
Do we need to evaluate (x – p) in fragment program? Rasterization/G80 lectures: GPUs have VERY FAST dedicated hardware for linear interpolation (lerp) Lerp color, textures, normals across triangle vertices

35 GPU: Linear Interpolation
Color example

36 Optimization: Fragment Program
Evaluate (x – p) at polygon vertices and use dedicated hardware to lerp at each pixel ! What about line / triangle sites? Can be linearly interpolated too ! More details later

37 GPU Optimizations Where to optimize? Make fragment program run faster
GPU / Application dependent optimizations Reduce memory bandwidth Reduce number of invocations of fragment program Geometric culling

38 Optimization: Memory Bandwidth
Reduce number of texture lookups, framebuffer writes Pack data into fewer channels Is bandwidth limited?

39 Optimization: Memory Bandwidth
Reduce number of texture lookups, framebuffer writes Pack data into fewer channels How?

40 Optimization: Memory Bandwidth
Pack data into fewer channels Using fp32 render target 32 bit = 4 billion site ids We can use only 1 channel (red) for writing site id instead of 4 channels (RGBA)

41 GPU Optimizations Where to optimize? Make fragment program run faster
GPU / Application dependent optimizations Reduce memory bandwidth Reduce number of invocations of fragment program Geometric culling

42 Linear Factorization Distance vector field: Gives vector from a point in 3D to closest point on a site Line Site Distance Vectors

43 Linear Factorization Distance functions are non-linear (quadric)
Distance Vectors can be factored into linear terms Linearly interpolated along each axis

44 Linear Factorization: 2D
Distance vectors are linearly interpolated Line Segment e f

45 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated f e p

46 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated f e b p a

47 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated f e b p a

48 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated f e b p a

49 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated f e b p a

50 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated f e e b p a

51 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated f b e p a c

52 Linear Factorization: 3D
Distance vectors are bi-linearly interpolated Distance vector in interior of a convex polygon = convex combination of distance vectors at vertices Convex polygon: from geometry of site

53 Domain Computation Compute a convex polytope bounding Voronoi region
Non-manifold sites Manifold sites Intersect polytope with each slice to get convex polygonal domain ‘Clamping’ computation – reduce fill

54 Domain Computation: Non-Manifold Point
Polygon Slice

55 Domain Computation: Line Segment
Polygon Slice

56 Domain Computation: Triangle
Prism Polygon Slice

57 Domain Computation: Manifold Edge
Triangular Prisms given by incident triangles Prism Polygon Slice

58 Domain Computation: Manifold Vertex
Slice “Cone” given by half-plane intersections Compute a bounding right circular cone Valid for hyperbolic points

59 GPU Based Algorithm Vertex Processor Fragment Processor Raster Ops
Pentium IV 3.4Ghz NVIDIA GeForce 7800 GTX Compute bounding polygon Compute distance vectors Bi-linear interpolation Compute Norm Compute Min 280 GFLOPS Vertex Processor Fragment Processor Raster Ops Rasterizer CPU 25.6 GFLOPS 35 GFLOPS Texture 1.3 TFLOPS GPU Memory

60 Outline Distance Fields and Voronoi Diagrams Hands on application demo
Advanced: Optimization Discussion: Why fast on a GPU?

61 Distance Field Timings
CSC (CPU) HAVOC DiFi: GPU 240x 313x 100 10 1 0.1 Disclaimer: Non optimized CPU code (No SSE), includes geometric culling

62 Efficiency: Parallelism
Brute-force: Insanely parallelizable All fragment processors (cores) are being utilized

63 Efficiency: Dedicated H/W
Graphics hardware efficiently performs bilinear interpolation of vertex attributes Texture coordinates Color Normals (Phong shading) Fast depth test = Atomic compare and set (32bit FP)

64 Efficiency: Bandwidth
GPU: High bandwidth to framebuffer CPU: Set of sites + grid does NOT fit in L2 cache


Download ppt "GPGPU: Distance Fields"

Similar presentations


Ads by Google