1 / 57

Acceleration Structures

Acceleration Structures. CS 148: Introduction to Computer Graphics and Imaging. Image: "BL Object 5" by Douglas Eichenberg (2003). Ray-Scene Intersection. Traversing all primitives in the scene for each ray is inefficient! Need auxiliary structures to accelerate this process.

Download Presentation

Acceleration Structures

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Acceleration Structures CS 148: Introduction to Computer Graphics and Imaging Image: "BL Object 5" by Douglas Eichenberg (2003)

  2. Ray-Scene Intersection • Traversing all primitives in the • scene for each ray is inefficient! • Need auxiliary structures to accelerate this process.

  3. Acceleration Structures for Vertex Normals (for rendering) • for each Vertex v in V • for each Triangle t in T • if Triangle t contains Vertex v • inner_loop(v,t) • O(|T| |V|) running time • for each Triangle t in T • for each v’ in {t.v1, t.v2, t.v3} • v’.relevant_triangles.append(t) • for each Vertex v in V • for each t’ in v.relevant_triangles • inner_loop(v,t’) • O(|T|+|V|) running time insert Data Structure retrieve

  4. Acceleration Structures for Ray Tracing • Two basic ideas: • Partition the objects • Flat: bounding volumes • Hierarchical: bounding volume hierarchies (BVH) • Partition the space • Flat: Uniform Grid • Hierarchical: Octree, Kd-Tree Bounding Volumes BVH Uniform Grid Kd-Tree

  5. How to evaluate an acceleration structure? • How fast is it to construct the structure? • Building a hierarchy for n primitives takes O(nlogn) time • Inserting n primitives into a uniform grid takes O(n) time • How much memory will it use? • A tree for n primitives takes O(n) space • A uniform grid subdividing the space takes O(nx*ny*nz) space • How fast is it for a ray to traverse in the structure? • Root to Leaf traversal is O(log n) • Need (efficient) methods for finding neighbors in both hierarchies and flat data structures

  6. Bounding Volume • Enclosing each object with a simpler piece of geometry • Sphere, box (axis-aligned, object-aligned) • If the ray does not hit the bounding volume, it cannot hit the enclosed object • Avoid expensive intersection test with the object

  7. Bounding Sphere • A sphere enclosing allof the vertices of the object. • Fastest bounding volume for intersection test with a ray. • Minimize the radius of the bounding sphere • For a triangle or a tetrahedron, the minimal radius is simply the radius of its circumsphere. • How about more complicated geometry?

  8. Constructing Bounding Sphere • An intuitive way: • Compute the centroid PC of all vertices • Loop through all vertices and compute the maximal |Pi-PC|2 to find the farthest vertex Pfarthest from PC • Return |Pfarthest-PC| as the minimal radius • A counter example: a crowd of points with one discrete point far away, the radius calculated in this way is about twice as big as the minimal one. • A hierarchical way: • Build the bounding sphere for each triangle • Recursively merge the neighboring spheres into a larger one until all the spheres are merged into one sphere • Return the radius of that sphere as the minimal radius • Optimal methods: • Randomized Linear programming, running in expected O(n) time.

  9. Pros and Cons of Bounding Sphere • Advantages: • Constructing a bounding sphere is fast. • Ray-sphere intersection test is easy. • No need to change when object rotates • Disadvantages: • Cannot tightly enclose the object in some cases, e.g., long and thin objects, which leads to false positives

  10. Axis-Aligned Bounding Box (AABB) • An axis-aligned box containing the object. • Constructing an AABB is trivial: • Loop through all of the vertices and find the min and max values in each dimension separately. • Use the min/max values as the bottom-left/top-right corners of the bounding box.

  11. Ray-Box (Axis Aligned) Intersection • A box is the intersection of 3 pairs of slabs in 3 dimensions • Each slab contains two parallel planes and the space between them • We can detect the intersection between the ray and the box by detecting the intersections between the ray and the three pairs of slabs. • For each pair of slabs there are two intersection points Pnear and Pfar, and there are 6 intersection points in total for 3 pairs. • If the maximal Pnear is ahead of the minimal Pfar on the ray, the ray misses the box. Otherwise it hits the box.

  12. Pseudocode float RayBoxIntersection (Ray ray, Box box, Interval [tmin, tmax]) { calculate tnear,x , tfar,x , tnear,y , tfar,y , tnear,z , tfar,z on 3 axes; tnear=max(tnear,x , tnear,y, tnear,z); tfar=min(tfar,x , tfar,y, tfar,z); if(tnear<tfar && tnear>=tmin&& tnear<=tmax){ return tnear; ////report intersection at tnear } else{ return -1; ////no intersection } }

  13. Pros and Cons of AABB • Advantages • Constructing an AABB is simple. • Simply scan over all vertices and find min and max values in each dimension in O(n) time • Ray-box intersection test is fast. • Disadvantages • Need to recalculate the bounding box any time an object rotates (unless the ray is transformed into object space) • Cannot tightly enclose the object (similar to spheres)

  14. Oriented Bounding Box (OBB) • The orientation of the box depends on the orientation of the object • Don’t need to recompute the box when an object rotates • Can pre-compute OBB in object space and transform OBB to world space with the object (same is true for spheres)

  15. Constructing OBB • How to compute the orientation of the object? • Singular Value Decomposition • Compute the covariance matrix and the eigenvalues and the corresponding eigenvectors of the 3x3 matrix • Using these eigenvectors as the basis of the local coordinate system of the bounding box

  16. Constructing an OBB for a Triangle Mesh • Compute the mean centroid of all triangles: where pi, qi, and ri are the vertices of ith triangle, and n is the number of triangles. • Construct the 3x3 covariance matrix C, the element Cjk is computed as: where and • Calculate the eigenvectors e1, e2, e3 of C and take them as the basis vectors for the local coordinate system of the OBB. • All of the eigenvectors are mutually orthogonal since C is symmetric. • Find the extremal vertices along each basis vector and resize the bounding box to bound those vertices (similar to the AABB) [Gottschalk et.al. 96]

  17. Ray-Box (Object Oriented) Intersection • Similar to Ray-AABB intersection • Calculate the maximum tnear and the minimum tfar • The planes of the slabs are not axis aligned any more • Recall how to compute intersection between a ray and an arbitrary plane in 3D space Ray-AABB intersection Ray-OBB intersection

  18. Or we can transform the ray… • Transform the ray into the OBB coordinate system and perform ray-AABB intersection test. World Coordinate OBB Coordinate

  19. Pros and Cons of OBB • Advantages • Fit the object tighter than AABB • Disadvantages • Extra cost for ray-box intersection • Finding an OBB is computationally expensive (but is done as a precomputation) • Finding the minimal OBB is hard (but an approximation – such as the one we just proposed - is usually good enough)

  20. Bounding Volume Hierarchies (BVH) • A bounding volume hierarchy is a tree • Each leaf encloses a primitive object • Each interior node encloses all the bounding volumes of its children

  21. Constructing the BVH • Bottom up • Begin with the bounding volume for each primitive • Recursively merge them into larger volumes according to some criteria • E.g., merge nearest neighbors, minimizing the sum of surface area • Stop in case of a single bounding volume at the root • Top down • Begin with the group of all primitives and its bounding volume • Recursively split primitives and the corresponding bounding volume according to some criteria • E.g., split primitives w.r.t coordinate axis, minimizing the sum of surface area • Stop when all leaf nodes are indivisible.

  22. Example: Splitting Strategies in Constructing OBB Tree to Bound a Object Split using center points along the longest axis of object bounded with OBB [Gottschalk et.al. 96] [Kamat and Martinez, 2007]

  23. Where/When to create the BVHs? • Create the BVH individually for each object • The BVH is in object space • Can be translated with the object and does not need to be updated • Create BVH for unioning together all BVs of all objects in a scene • This global BVH is in the world space • Must be updated whenever something moves in the scene • Do both!

  24. Ray Traversal in BVH • Use hierarchy to accelerate ray intersections • Intersect node contents only if the ray intersects the bounding volume

  25. How to backtrack the ray in BVH? • Depth-first search: • Find the nearest intersection inside a node by recursively finding the intersections of all its subnodes and return the minimum t. • How to improve the efficiency? To report ray-primitive in node C, we need to recursively traverse all its subnodes (D, G, H, I) to find all the ray-primitive intersections (triangles in G and I) and report the minimum one (triangle in G).

  26. Early Termination in Ray Traversal • Sort hits & detect early termination • Sort the intersections of the ray and the child node bounding volumes and terminate when the first ray-primitive intersection is found.

  27. Early Termination in Ray Traversal To report ray-primitive in node C, we can avoid testing triangles in H and I by recursively sorting the intersections of the ray and the subnodes of C (D and I of C, and subnodes G and H of D). Searching terminates when it finds the first triangle (in G) in the sorted nodes.

  28. Some cases that BVH doesn’t work well • Objects with similar sizes are approximately uniformly distributed in space • BVH has an extra log n constant that is not warranted in this case – i.e. not enough successful pruning occurs "Warm Up" by Norbert Kern (2001) “Shorebirds” by Jim Charter (2000) http://hof.povray.org/warm_up.html http://hof.povray.org/shorebir.html

  29. Partition the space instead… • Instead of using the objects to divide space just divide all of space and register objects with the cells they (or their bounding volumes) overlap

  30. Uniform Grids • Divide 3D space into nx*ny*nz axis-aligned grid cells • Perform Ray-object intersection test only when the ray hits the grid cell containing the object • The size of the grid cell is crucial to the performance • No speedup if the cell size is too big, no pruning, everything in one cell • A lot of empty cells if the cell size is too small • A practical way to choose cell size is to average the edge lengths of the bounding boxes of all primitives

  31. Constructing a Uniform Grid • Find the bounding box of the scene • Initialize the grid with that bounding box and a proper cell size • Each cell maintains a list (or an array) to store the overlapped primitives • Insert primitives into cells • One primitive may be inserted into multiple cells

  32. Ray Traversal in a Uniform Grid • Traverse all the cells pierced by the ray before the ray intersects with a primitive or reaches the boundary of the bounding box

  33. Incremental Traversal • An incremental algorithm similar to line rasterization: • From the current intersection point P on the face of cell (i, j, k), perform ray-plane intersection tests with the next 3 grid planes along the ray direction to get the 3 candidate intersection points for the next intersection. • The next intersection point is the nearest one among the 3 candidates. • Update the cell index according to the new intersection point. Perform ray-primitive intersection tests in the new cell. • Repeat the above process until the ray intersects with a primitive or reaches the boundary of the bounding box.

  34. Improving the Algorithm • Efficiently finding the next intersection point on the grid • The intersections with the grid planes have the same spacing in each independent dimension • Using the precomputed δtx, δty, and δtz, we don’t need to perform ray-plane intersection tests every time. • δtx =Cx/Dx, δty =Cy/Dy, δtz =Cz/Dz, in which (Cx, Cy, Cz) is the cell size and (Dx, Dy, Dz) is the ray direction.

  35. Pseudocode ////tnext denotes the t for the 3 candidate intersections on planes in 3 dimensions, ////it is initialized based on the first cell pierced by the ray in the grid Initialize tnext; ////s is a 3d (integer) vector denoting the direction for incrementing cell index along the ray, ////for each direction, if(ray.dird>0) sd=1; else sd=-1; Initialize s; void IncrementalRayTraverse(Ray ray, Vec3 cell, Vec3 tnext) { float tintersect= min(tnext,x tnext,y tnext,z); int d = the axis of tintersect; ////the face of intersection celld+=sd; ray.tmin=ray.tmax; ray.tmax= tintersect; tnext,d+= δtd ; process ray-primitive intersections in the new cell between ray.tmin and ray.tmax }

  36. Avoid Redundant Intersection Test • A primitive may be stored in multiple cells: • For each cell, an intersection test on that primitive may be performed • Solution: associate each primitive with a bool: • If the primitive has already been determined to not intersect the ray, or is not the closest intersecting primitive, store false in the bool • Before the actual ray-primitive intersection test, check the bool first

  37. Pros and Cons of the Uniform Grids • Advantages: • Construction is fast. • Regular Layout, Cache coherent • Ray traversal is easy. • Disadvantages: • Empty cells in a sparse scene will waste memory • Hard to choose the cell size • No adaptivity

  38. Ray Traversal in Viewing Frustum • Sending rays in the camera space: • Create a uniform grid in the frustum • Avoid the traversal steps and intersection tests • Cache coherent, all the cells are aligned along the ray! • Can traverse a bunch of rays in one time

  39. Optimizing the Uniform Grid • Optimizing the storage • Spatial Hashing: use a hash table instead of a 3D array. • Avoid the extra storage for a large number of empty cells. • Optimizing the performance • Adaptive grids: rectilinear grid, embedded grid, octree Rectilinear Grid Embedded Grid Octree (Quadtree)

  40. Octree • Each node potentially has exactly 8 children: • Each node can equally subdivide its space (an AABB) into eight subboxes by 3 midplanes. • Children of a node are contained within the box of the node itself.

  41. Constructing an Octree • In a top-down way: • Find the global bounding box that contains all the primitives and correspond it to the root of the tree • Recursively partition a node into 8 octants by 3 midplanes. • If a primitive belongs to multiple octants, put it in each octant. • Recursion stops when the termination criteria are satisfied. • e.g., maximum depth, minimum number of primitives in a node.

  42. Ray Traversal in an Octree • Traverse all leaf nodes in the octree passed through by the ray and perform intersection tests for the primitives inside those leaves.

  43. Recursive Traversal • Basic idea: • For a leaf node, perform intersection test for its primitives and terminate if an intersection is detected. • For an interior node, recursively process all the subnodes inside it. • Two important questions: • How to find the first subbox at which the ray enters the current box? • How to find the next subbox (or report exit) when the ray exits a subbox?

  44. Observation • For a given ray and a box, the number of its subboxes intersected with the ray and the intersection sequence of these subboxes is only determined by the two intersection points and the corresponding box faces. …

  45. Find the First Entry Subnode • First find the entry face by computing min(tnear,x,tnear,y,tnear,z) • Recall what we did for ray-AABB intersection test • On each face there are 4 corresponding subboxes, decide which subbox the ray enters using midplanes. • Find the midplane is crossed before or after the entry. Crossed before the entry Crossed after the entry

  46. Find the Next Subnode • Build an automaton whose states correspond to the boxes and whose transitions are associated to the movements between neighboring sub-nodes visited sequentially by the ray.

  47. Recursive Traversal: Example

  48. Pros and Cons of the Octree • Advantages • Adaptivity • Memory efficiency • Disadvantages • Ray traversal is complicated • Partition strategy is not flexible • Not cache coherent

  49. Hybrid Structure • Start with a uniform grid and subdivide each node using hierarchies • Each node of a uniform grid can contain a whole octree • Improve the performance of the octree: no need to traverse the tree from a single root every time [Losasso et.al. 2006]

  50. K-d Tree • Using a hyperplane translated in one dimension

More Related