Upload
warren-henderson
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
Computer Graphics 2Lecture x:
Acceleration Techniques for Ray-Tracing
Benjamin Mora 1University of Wales
Swansea
Dr. Benjamin Mora
Introduction
2Benjamin MoraUniversity of Wales
Swansea
• 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…
Content
3Benjamin MoraUniversity of Wales
Swansea
• 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.
Ray-Tracing Oriented Techniques.
4Benjamin MoraUniversity of Wales
Swansea
Ray-Tracing Oriented Techniques.
5Benjamin MoraUniversity of Wales
Swansea
• 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.
Bounding Boxes
6Benjamin MoraUniversity of Wales
Swansea
• Example:
Naïve algorithm: 12 intersections to be tested to find the closet intersection.
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.
(1)
(2)
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!
Bounding Boxes
7Benjamin MoraUniversity of Wales
Swansea
• 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…
Bounding Boxes
8Benjamin MoraUniversity of Wales
Swansea
• 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.
Grids
9Benjamin MoraUniversity of Wales
Swansea
• 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).
BSP and Kd-Tree Demo
10Benjamin MoraUniversity of Wales
Swansea
Spatial Subdivision Techniques: BSP Trees
11Benjamin MoraUniversity of Wales
Swansea
• The 3D space is now hierarchically subdivided according a subdividing plane.
1
12
3
2 3
5
4
4 5
Spatial Subdivision Techniques: BSP Trees
12Benjamin MoraUniversity of Wales
Swansea
• Ray traversal:
1
12
2
3
3
55
Spatial Subdivision Techniques: BSP Trees
13Benjamin MoraUniversity of Wales
Swansea
• Example:
Spatial Subdivision Techniques: BSP Trees
14Benjamin MoraUniversity of Wales
Swansea
• Example:
Spatial Subdivision Techniques: BSP Trees
15Benjamin MoraUniversity of Wales
Swansea
• 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;
}
Spatial Subdivision Techniques: BSP-Trees
16Benjamin MoraUniversity of Wales
Swansea
• 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.
Spatial Subdivision Techniques: Kd-Trees
17Benjamin MoraUniversity of Wales
Swansea
• Axis-aligned BSP tree.
1
12
2
3
3
4 4
5
5
Spatial Subdivision Techniques: Kd-Trees
18Benjamin MoraUniversity of Wales
Swansea
• Example:
Spatial Subdivision Techniques: Kd-Trees
19Benjamin MoraUniversity of Wales
Swansea
• 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.
Spatial Subdivision Techniques: Kd-Trees
20Benjamin MoraUniversity of Wales
Swansea
• 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.
Spatial Subdivision Techniques: Kd-Trees
21Benjamin MoraUniversity of Wales
Swansea
• 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)
Spatial Subdivision Techniques: Kd-Trees
22Benjamin MoraUniversity of Wales
Swansea
• SAH Example
Bounding Volume Hierarchies
23Benjamin MoraUniversity of Wales
Swansea
Bounding Volume Hierarchies
24Benjamin MoraUniversity of Wales
Swansea
• 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.
Spatial Subdivision Techniques: Octrees
25Benjamin MoraUniversity of Wales
Swansea
• 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
Spatial Subdivision Techniques: Octrees
26Benjamin MoraUniversity of Wales
Swansea
Considerations on Tree Traversals
27Benjamin MoraUniversity of Wales
Swansea
• 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.
Special case: Octrees
28Benjamin MoraUniversity of Wales
Swansea
1 2
354
6
9
A
C
B
A
A B
C
78
Special case: Octrees
29Benjamin MoraUniversity of Wales
Swansea
• 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 1 23 4
2 41 3
Viewpoint
Spatial Subdivision Techniques: Hierarchical Grids
30Benjamin MoraUniversity of Wales
Swansea
• Similar to octrees, but the node is now grid-subdivided.
• Subdivision can be:– Regular.– Adaptive.
• Not so much used!
Packet Ray-Tracing
31Benjamin MoraUniversity of Wales
Swansea
• 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.
Multi-Level Ray-Tracing
32Benjamin MoraUniversity of Wales
Swansea
• Multi-level ray tracing algorithmAlexander 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!
Multi-Level Ray-Tracing
33Benjamin MoraUniversity of Wales
Swansea
Multi-Level Ray-Tracing
34Benjamin MoraUniversity of Wales
Swansea
Multi-Level Ray-Tracing
35Benjamin MoraUniversity of Wales
Swansea
Future of Ray-Tracing
36Benjamin MoraUniversity of Wales
Swansea
• Games?– Some people do believe so…– Hard to maintain acceleration structures on dynamic
scenes.
• High quality rendering.– Certainly.– Movies.– Global illumination algorithms.– Etc…