CS 655 Ray Tracing Optimizations Ray Tracing Problems • Slow Compare every ray vs. every object • Rays are discrete Aliasing problems No coherence taken advantage of • We would like to optimize our ray tracer Efficiency Generality Quality Optimizations • Approaches to optimizing the ray tracer: Data structures Numerical methods Computational geometry Optics Statistical methods Distributed computing Ray Tracing Optimizations • Criteria for judging acceleration techniques: (from Kirk and Arvo) Simplicity Applicability - All rays? - All object types? Performance Recources - Storage - Multiple processors What should we optimize • Say intersections are 80% of the computation. • Give an equation which describes the number of intersections. • What should we do? Intersection Optimizations • Reduce intersection computation time • Reduce the number of intersections • Replace individual rays with a more general entity Ray Tracing Acceleration Summary Acceleration Techniques Faster Intersections Faster Ray/Object Intersections 1. 2. Object Bounding Volumes Efficient intersectors Fewer Rays Generalized Rays Fewer Ray/Object Intersections 1. 2. 3. Bounding Volume Hierarchies Space Subdivision Directional Techniques 1. 2. Adaptive Tree Depth Control Statistical Optimizations 1. 2. 3. Beam Tracing Cone Tracing Pencil Tracing Ray Tracing Acceleration Summary Acceleration Techniques Faster Intersections Faster Ray/Object Intersections 1. 2. Object Bounding Volumes Efficient intersectors Fewer Rays Generalized Rays Fewer Ray/Object Intersections 1. 2. 3. Bounding Volume Hierarchies Space Subdivision Directional Techniques 1. 2. Adaptive Tree Depth Control Statistical Optimizations 1. 2. 3. Beam Tracing Cone Tracing Pencil Tracing Bounding Volumes • Idea: Provide a volume that completely encloses an object, but which has a simpler intersection calculation than the actual object If the ray does not intersect the bounding volume, it will not intersect the object Complex intersections are replaced by simpler ones The number of intersection calculations increases, however Want the bounding volume as near to the object as possible Still a linear time complexity in the number of objects Bounding Volume Example Bounding Sphere Bounding Volumes • Generally, either spheres or axis-aligned bounding volumes are used • Simple to intersect against • However, these may not provide close fits to the objects being bounded • Several different bounding volume types have been used • Tradoff – ease of intersection vs. object fit Types of Bounding Volumes Bounding Sphere Intersection Of Slabs Axis-aligned Bounding Box Union of Bounding Boxes Non-axis-aligned Bounding Box Intersection of Bounding Sphere and Bounding Box Ray Tracing Acceleration Summary Acceleration Techniques Faster Intersections Faster Ray/Object Intersections 1. 2. Object Bounding Volumes Efficient intersectors Fewer Rays Generalized Rays Fewer Ray/Object Intersections 1. 2. 3. Bounding Volume Hierarchies Space Subdivision Directional Techniques 1. 2. Adaptive Tree Depth Control Statistical Optimizations 1. 2. 3. Beam Tracing Cone Tracing Pencil Tracing Hierarchical Bounding Volumes • Bounding volumes by themselves try to reduce intersection time, but not the number of intersections • A bounding volume hierarchy can reduce the number of intersections • Place each object in its own bounding volume • Group the bounding volumes hierarchically • Intersection computations proceed down the hierarchy Hierarchical Bounding Volumes Around a million triangles Log_2(1M) = about 20 Example Bounding Volume Hierarchy 4b 4d 4a 4f 4e 3b 4c 3a 2a 2b 1 1 2a 3a 4c 2b 4b 4d 3b 4a 4e 4f Bounding Volume Hierarchy • Each leaf node is a single object • Each interior node consists of a bounding volume and a list of pointers to its children nodes • Process: Determine the bounding volume for each object in the scene (usually spheres or orthogonal parallelepipeds) Combine bounding volumes into a tree by selecting some of them and surrounding them with another bounding volume Repeat this process recursively until a bounding volume is generated that surrounds the entire scene Bounding Volume Hierarchy • Once the tree is built, trace rays, intersecting with the hierarchy. • If one volume in the hierarchy is missed, you don’t need to intersect the ray with any children of that bounding volume • Algorithm: Procedure BVH_Intersect(ray, node) Begin if node is a leaf then Intersect (ray, node_object) else if Intersect_P(ray, node_bounding_volume) then For each child of node BVH_Intersect(ray, child) End Building the BVH • Manually Difficult • Automatically Simple n-ary tree - Poor, since it doesn’t take the model into consideration Median-cut algorithm - Better, but still doesn’t take full advantage of scene properties Heuristic tree search - Good, if the heuristic is chosen well Ray Tracing Acceleration Summary Acceleration Techniques Faster Intersections Faster Ray/Object Intersections 1. 2. Object Bounding Volumes Efficient intersectors Fewer Rays Generalized Rays Fewer Ray/Object Intersections 1. 2. 3. Bounding Volume Hierarchies Space Subdivision Directional Techniques 1. 2. Adaptive Tree Depth Control Statistical Optimizations 1. 2. 3. Beam Tracing Cone Tracing Pencil Tracing 3D Spatial Subdivision Techniques • Start with a volume that bounds the entire environment • Successively partition the volume into smaller pieces • Objects are grouped based on volumes, rather than vice-versa • Several approaches using this idea Uniform spatial subdivision - Simple, doesn’t match objects well Non-uniform spatial subdivision - More complex, but should give a better fit to the objects Uniform Spatial Subdivision • Voxels are all the same size, organized into a 3D grid • Space subdivision is independent of the objects in the scene • The “next voxel” calculation can be done very efficiently • 3DDDA can be used (three-dimensional digital differential analyzer ) • The speedup in the 3DDDA may or may not compensate for the loss of object locality gained in non-uniform methods Uniform Spatial Subdivision • Start with a volume enclosing the entire scene • Uniformly subdivide it until each subspace contains less than n objects 434243414342434 4 3 4 2 4 3 4 1 4 3 4 2 4 3 4 2 4 5 3 1 Non-uniform Spatial Subdivision • Space is discretized into regions of varying size • Several approaches Octree BSP Tree Median Split Octrees • An octree is created that approximates the scene • The octree is subdivided as necessary based on the scene BSP Trees • Another non-uniform spatial subdivision technique is Binary Space Partitioning trees • Idea: Split space into two subspaces (not axis aligned) based on the objects in the subspaces Check each subspace. If a subspace has more than n objects, split that subspace into two smaller subspaces Each subspace maintains a list of objects in it BSP Trees 2a 2 4 5 3 1 1 3 2b BSP Trees • Divide a ray into two components – one on each side of the partitioning plane • Check the nearest sub-ray first If it intersects another plane, subdivide the ray at the plane • Intersect the nearest sub-ray against the objects in that space • If no intersections, move to the next sub-ray, splitting the ray as necessary, then compute ray/object intersections BSP Example Region 4 2a • Ray is split at the 2b plane • Region 1 is intersected against • Ray is split at plane 1 Region 3 • Region 2 is intersected against • Ray is split at plane 2a • Region 3 is intersected against • Region 4 is intersected against 2 4 5 Region 2 3 1 1 3 Region 5 ray Region 1 2b Median Split BVH Technique • An alternative method for creating a BVH is the “Median Split” technique • Simpler than the Goldsmith and Salmon technique • Not as object-centric, however • Idea: Split space into two subspaces, based on the dimensions of the space Check each subspace - If a subspace has several objects still in it, split it again Median Split 2a 2 4 4a 1 3 8a 8b 7a 7b 6a 5a 5 3 1 5b 8c 4b 6b 2b Median Split Pseudocode 1. Surround all of the objects in the scene in an axis-aligned bounding box. 2. Determine the largest magnitude extent of the bounding box. 3. Subdivide the bounding box at the middle of the box, in the coordinate direction determined by the extent from step 2. 4. If the level of subdivision is less than m (for m something like 20 or so), and the number of objects in the space is greater than n, (n being some small number like 1 or 5 or 10 or so), subdivide that sub-space by repeating steps 2 through 4 on the sub-space. 5. For each subspace in the final divided space, maintain a list of those objects associated with that sub-space. Median Split • With the bounding volume subspaces determined, ray tracing proceeds: Send out a ray Determine which subspace is first hit Compute intersections with all objects associated with that subspace If an intersection exists, report the first intersection If no intersection, proceed to the next subspace hit by the ray and repeat this process Ray Tracing Acceleration Summary Acceleration Techniques Faster Intersections Faster Ray/Object Intersections 1. 2. Object Bounding Volumes Efficient intersectors Fewer Rays Generalized Rays Fewer Ray/Object Intersections 1. 2. 3. Bounding Volume Hierarchies Space Subdivision Directional Techniques 1. 2. Adaptive Tree Depth Control Statistical Optimizations 1. 2. 3. Beam Tracing Cone Tracing Pencil Tracing Directional Techniques • Another approach at reducing the number of ray/object intersections is to exploit directional information • Move processing to a higher level i.e. rather than on a per ray basis, move computation to a group of rays • These techniques typically require large amounts of storage Direction Cube • Axis aligned cube centered at (0, 0, 0) with edges of length 2 • Cube is placed on the ray origin • A ray can now be represented by a face and a (u,v) coordinate on that face Ray Direction Cube • The direction cube faces are subdivided into smaller sub-faces Can be either uniform or non uniform • Each direction cell defines an infinite skewed pyramid with its apex at the origin and its edges through cell corners Direction Cube • Given the subdivided cube we can determine which cell is pierced by each ray Determine the dominant axis of the ray to get the intersection face Determine the (u, v) coordinate Determine which cell this (u, v) point is in Each cell keeps a list of candidate intersection objects based on direction neighborhoods • Is this practical for standard rays? The Light Buffer • Used to accelerate shadow calculations using the directional idea • Assumes point light sources • Idea: Each light source is given a uniformly subdivided direction cube. Prior to ray tracing, each object is projected onto each direction cube. Each cell contains a list of all objects that project to that cell. For shadow computations, determine which cell is intersected by the shadow ray, and only intersect objects in that cell’s list The Light Buffer • Find where ray intersects light buffer • Intersect against objects in that cell’s list Light Buffer Shadow Ray Point light source Incoming Ray Ray Tracing Acceleration Summary Acceleration Techniques Faster Intersections Faster Ray/Object Intersections 1. 2. Object Bounding Volumes Efficient intersectors Fewer Rays Generalized Rays Fewer Ray/Object Intersections 1. 2. 3. Bounding Volume Hierarchies Space Subdivision Directional Techniques 1. 2. Adaptive Tree Depth Control Statistical Optimizations 1. 2. 3. Beam Tracing Cone Tracing Pencil Tracing Beam Tracing Funkhouser et al., “A Beam Tracing method for interactive architectural acoustics” in J. of Acoust. Soc. of Am. 115(2) 2004
© Copyright 2026 Paperzz