360 likes | 373 Views
Learn about advanced acceleration techniques for ray-tracing, including bounding boxes, grids, spatial subdivisions, BSP and K-d trees, and more, to optimize rendering times and increase efficiency.
E N D
Computer Graphics 2Lecture x:Acceleration Techniques for Ray-Tracing Dr. Benjamin Mora University of Wales Swansea 1 Benjamin Mora
Introduction • Why do we need to accelerate Computer Graphics? • Because scenes are more and more complex. • Because we want interactive (~5 fps) or real-time techniques (>30 fps). • Because global illumination algorithms takes hours to render a single image. • Because the naïve algorithms are inefficient (and not just a little). • Because rendering times are proportional to the computational power, which is proportional to the money you invest and CO2 emissions… University of Wales Swansea 2 Benjamin Mora
Content • Ray-Tracing Oriented Techniques. • Simple Bounding Boxes (or volumes). • Grids. • Spatial Subdivisions. • BSP and K-d Trees. • Bounded Volume Hierarchies. • Octrees. • Hierarchical Grids. • Packed Ray-Tracing. • Multi-Level Ray-Tracing. University of Wales Swansea 3 Benjamin Mora
Ray-Tracing Oriented Techniques. University of Wales Swansea 4 Benjamin Mora
Ray-Tracing Oriented Techniques. • A naïve Ray-Tracer is very inefficient. • Every ray makes an intersection test with all the n primitives in the scene. (Complexity O(n) per ray). • An O(log(n)) complexity per ray can be achieved on average with better techniques. • Most acceleration techniques in Ray-Tracing use the concept of bounding boxes that are going to group a spatial subset of primitives. University of Wales Swansea 5 Benjamin Mora
(2) Bounding Boxes • Example: Naïve algorithm: 12 intersections to be tested to find the closet intersection. (1) Using a Bounding Box for this case: 2 Bounding box intersections at most must be done first+ 6 regular intersections. Because the ray do not intersect the second BB, there is no need to test the inner primitives. Can this optimization also be used in case 2, since the 2 bounding boxes are intersected? Yes, if bounding boxes tests are run in a visibility order! University of Wales Swansea 6 Benjamin Mora
Bounding Boxes • Bounding boxes are a very basic data structure for Ray-Tracing acceleration. • BBs may be: • a sphere (easier to compute). • A cube. • A polyhedra. • … • Creating the bounding box (i.e. classifying the primitives) must be done in an intelligent way… University of Wales Swansea 7 Benjamin Mora
Bounding Boxes • Basic algorithm for every ray: For every bounding box BB: if BB is in front of an already detected intersection and BB is intersected by the ray then test the intersection with all the primitives inside BB. • Improvement can be done by testing all the bounding boxes in a Front-to-back order. • Another improvement can be to create a hierarchy of BBs. • Similar to spatial subdivisions techniques. University of Wales Swansea 8 Benjamin Mora
Grids • The 3D space is subdivided with a grid. • Every cell contains a list of primitives. • Front-to-back traversal inside a grid is easy. • 3D-DDA traversal (See next lectures). • Creating the grid is easier as well (do not need heuristics, unlike BBs). • Average complexity: O(n^1/3). University of Wales Swansea 9 Benjamin Mora
BSP and Kd-Tree Demo University of Wales Swansea 10 Benjamin Mora
1 2 2 3 1 4 5 5 4 3 Spatial Subdivision Techniques: BSP Trees • The 3D space is now hierarchically subdivided according a subdividing plane. University of Wales Swansea 11 Benjamin Mora
1 2 2 3 1 5 5 3 Spatial Subdivision Techniques: BSP Trees • Ray traversal: University of Wales Swansea 12 Benjamin Mora
Spatial Subdivision Techniques: BSP Trees • Example: University of Wales Swansea 13 Benjamin Mora
Spatial Subdivision Techniques: BSP Trees • Example: University of Wales Swansea 14 Benjamin Mora
Spatial Subdivision Techniques: BSP Trees • Recursive Ray traversal (pseudo-code): int isIntersection (node n, ray r) { int result; if n is a leaf node return isThereAnIntersection(n.primitives, r); else { sortVisibility(n.child1, n.child2, r); if isIntersection(n.child1, r) result=isIntersection(n.child1, r); if result==1 return 1; if isIntersection(n.child2, r) result=isIntersection(n.child2, r); return result; } University of Wales Swansea 15 Benjamin Mora
Spatial Subdivision Techniques: BSP-Trees • Binary Space Partitioning Trees. • Logarithmic rendering complexity on average. • Quite hard to find the best heuristic for subdivision. • Each node represents a volumetric region delimited by convex polyhedron. University of Wales Swansea 16 Benjamin Mora
1 2 2 3 1 4 4 5 5 3 Spatial Subdivision Techniques: Kd-Trees • Axis-aligned BSP tree. University of Wales Swansea 17 Benjamin Mora
Spatial Subdivision Techniques: Kd-Trees • Example: University of Wales Swansea 18 Benjamin Mora
Spatial Subdivision Techniques: Kd-Trees • BSP Trees that are restricted to axis-aligned space subdivision. • Same properties as BSP trees. • Simplify intersection computations a lot. • Memory space can be reduced as well. • Only need to store a pointer to the 2 children, the subdivided axis(3 bits) and the location where the subdivision occurs (1 value). • Each node represent a volumetric region delimited by a rectangular hexahedron. • Very much used in computer graphics. University of Wales Swansea 19 Benjamin Mora
Spatial Subdivision Techniques: Kd-Trees • Heuristics to compute the tree (According Gordon Stoll, Intel, Course 41, Siggraph 2005). • Not very efficients: • Split axis: Largest Extent. • Split Location: Middle of the extent, Centre of gravity of the geometry. • Termination: A given number of primitives, limited depth. • Better: • Isolate empty regions of the volume. • Termination :small cell size. • Several time faster. University of Wales Swansea 20 Benjamin Mora
Spatial Subdivision Techniques: Kd-Trees • Surface Area Heuristic. • Finding the correct splitting position. • Recursive algorithm. • Investigate all the vertices in the node and choose the one minimizing the cost: Cost = NodeTraversalCost +TriangleRayIntersectionCost/SA(ParentNode)* (SA(leftNode) leftTriangles+SA(rightNode)*rightTriangles) University of Wales Swansea 21 Benjamin Mora
Spatial Subdivision Techniques: Kd-Trees • SAH Example University of Wales Swansea 22 Benjamin Mora
Bounding Volume Hierarchies University of Wales Swansea 23 Benjamin Mora
Bounding Volume Hierarchies • A hierarchy of bounding boxes. • MinMax of a set of triangles on x,y, and z coordinates. • Triangles in the set are fully included in the bounding box of a specific region. • Easier to compute than KD-trees and Octrees. • But are often less efficient than octrees and Kd-Trees at rendering the scene. • Often needs tp carry on traversing, even if an intersection has been detected. University of Wales Swansea 24 Benjamin Mora
Spatial Subdivision Techniques: Octrees • An octree is a 3D recursive subdivision of space. Every non-leaf node has 8 children. • Usually, the subdivision is centered on the middle of the node. • May not be as flexible as Kd-Trees. • Small non-empty regions may create “deeper” hierarchy/trees. • Useful in volume rendering. • Min-max information stored instead of empty/non-empty information. http://hpcc.engin.umich.edu/CFD/users/charlton/Thesis/html/img148.gif University of Wales Swansea 25 Benjamin Mora
Spatial Subdivision Techniques: Octrees University of Wales Swansea 26 Benjamin Mora
Considerations on Tree Traversals • All spatial subdivisions work in a similar way to accelerate ray-tracing. • A recursive top-down traversal of the tree is done. • Starting from the root node. • If node is empty=>Do nothing and Return. • If Leaf Node=>Test for an intersection with the primitives stored inside this node. If an intersection occurs, stop recursion and return the result. • Otherwise, find out the children of the current node that are intersected by the ray, sort them in a visibility order, and call again the function with these nodes. University of Wales Swansea 27 Benjamin Mora
9 C A B C 8 7 B A 6 A 3 5 1 2 4 Special case: Octrees University of Wales Swansea 28 Benjamin Mora
1 2 2 4 3 1 4 3 Special case: Octrees • A ray can intersect between two and four of the eight possible children. • Octree node visibility order (Painter’s algorithm, 2D example!) • 2 and 3 can be swapped! Viewpoint Viewpoint University of Wales Swansea 29 Benjamin Mora
Spatial Subdivision Techniques: Hierarchical Grids • Similar to octrees, but the node is now grid-subdivided. • Subdivision can be: • Regular. • Adaptive. • Not so much used! University of Wales Swansea 30 Benjamin Mora
Packet Ray-Tracing • Also called coherent ray-tracing. • Reasons: • Taking advantage of new processors: • SIMD Architectures: Single instructions applied 4 times. • Often 3x speed-up • Cell processor: 8 cores with SIMD capabilities. • Intersection test performed on 4 rays instead of one. • Taking advantage of spatial coherence. • Neighbor rays will similarly traverse the acceleration structure. • A lot of traversal steps can be avoided. • From 2x2 to 16x16 ray packets. University of Wales Swansea 31 Benjamin Mora
Multi-Level Ray-Tracing • Multi-level ray tracing algorithm Alexander Reshetov, Alexei Soupikov and Jim Hurley. Siggraph 2005 (ACM Transactions on Graphics), pp 1176-1185. • Go a step further to improve the tree traversal. • Tries to find the entry point in the tree for an as large as possible packet of rays. • See paper for more information! University of Wales Swansea 32 Benjamin Mora
Multi-Level Ray-Tracing University of Wales Swansea 33 Benjamin Mora
Multi-Level Ray-Tracing University of Wales Swansea 34 Benjamin Mora
Multi-Level Ray-Tracing University of Wales Swansea 35 Benjamin Mora
Future of Ray-Tracing • Games? • Some people do believe so… • Hard to maintain acceleration structures on dynamic scenes. • High quality rendering. • Certainly. • Movies. • Global illumination algorithms. • Etc… University of Wales Swansea 36 Benjamin Mora