Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Tracing Acceleration Structures Solomon Boulos 4/16/2004.

Similar presentations


Presentation on theme: "Ray Tracing Acceleration Structures Solomon Boulos 4/16/2004."— Presentation transcript:

1 Ray Tracing Acceleration Structures Solomon Boulos 4/16/2004

2 How does ray tracing work? Rays shoot from eyes into scene Find first thing ray hits Shade Becomes a search problem

3 Why acceleration structures? Trying to find first intersection Linear search is too slow O(n) 95 % of time is spent here Interactive ray tracing Large data sets

4 Talk Overview Types of Structures Discussion of Three Major Structures –Definition –Construction –Usage –Performance Analysis Which to use Current Problems Current work Future Work

5 Two Basic Types Divide in space Divide in geometry SpatialObject Empty Space

6 What are our options? Three Main Types –Uniform Grid ( UG ) –Binary Space Partition ( BSP ) –Bounding Volume Hierarchy ( BVH ) Others Not Discussed –Octree ( Glassner, 1984 ) –5D Tree ( Arvo, 1987 ) –List –Variants –Dynamic

7 What’s a UG? 3D Grid that divides space uniformly Each cell is a Bounding Volume (BV) A BV contains all the surfaces inside it Traversal is iterative through grid

8 How do we build one? 1.Find the surrounding bounding box. 2.Subdivide box into grid of boxes. 3.Add primitives to grid cells.

9 How do we use it? 1.Test Overall BV for intersection. 2.Find first grid intersection. 3.Iteratively update position. 4.Stop when we hit a primitive. 5.Return false if we exit the grid.

10 Simple Example

11 for(;;) cell = grid[i][j][k]; if (tx_next <= ty_next && tx_next < tz_next) { r.tmin = t_current; r.tmax = tx_next; if (cell != NULL && cell->hit(r, time, rec)) return true; t_current = tx_next; tx_next += dtx; i += i_step; if (i == i_stop) return false; } // similar cases UG Traversal Code

12 UG Analysis Build is O(n) Traversal is O(n^( 1/3 )) Great for Dense objects Naïve memory layout is bad Data tiling improves things

13 What’s a BSP? Space Subdivision Binary Tree Ordered traversal KD-TreeBSP Tree

14 How do we build one? 1.Choose splitting plane. 2.Pick pivot that divides plane. 3.Place primitives onto each side. 4.Stop if termination conditions met.

15 How do we use it? Test intersections based on 4 cases Case 1 Case 2 Case 3 Case 4 Splitting Plane

16 Ray Direction Code Ray::Ray(const Vector3& origin,const Vector3& direction) { tmin = 0.0001; tmax = DBL_MAX; data[0] = origin; data[1] = direction; posneg[X] = (data[1].x() >= 0 ? 0 : 1); posneg[Y] = (data[1].y() >= 0 ? 0 : 1); posneg[Z] = (data[1].z() >= 0 ? 0 : 1); }

17 BSP Traversal Code bool BSP::hit(Ray& r, HitRecord& rec) const { float point = r.origin()[axis] + r.direction()[axis]*r.tmin; float t = (pivot - point)/(r.direction()[axis]); if (point < pivot) // cases 1 and 2 { if ( r.posneg[axis] || t > r.tmax) // ray is negative i.e. posneg = 1 return (child[0] != NULL ) && (child[0]->hit(r, time, rec)); if ( child[0] != NULL && child[0]->hit(r, time, rec) ) return true; return (child[1] != NULL && child[1]->hit(r, time, rec)); } else // symmetric for cases 3 and 4... }

18 BSP Analysis Build time O(nlogn) or higher usually Objects overlap regions. Traversal time O(logn) expected Build is most important Memory layout can help.

19 What’s a BVH? Divides objects not space. Hierarchy ( Binary Tree is easy ) Each Node is a Bounding Volume (BV)

20 How do we build one? Find an all-encompassing BV Split this BV in two by any method Put shapes into each child Recurse

21 How do we test for intersections? 1.Test root for intersection. 2.If ray hits root, check children; otherwise false. 3.Return closest hit. t = 1.5 2.1 1.1 2.0 3.4 4.1

22 bool BVH::hit(Ray& r, HitRecord& rec) const { // test BV for intersection if (!(bbox.rayIntersect(r, r.tmin, r.tmax))) return false; // else call hit on both branches bool isahit1 = false; bool isahit2 = false; isahit1 = child[r.posneg[axis]]->hit(r, rec); isahit2 = child[r.posneg[axis]^1]->hit(r,rec); // did we hit either child? return (isahit1 || isahit2); } BVH Traversal Code

23 BVH Analysis Build time varies like BSP. O(nlogn) and higher in practice. Bounding boxes overlap instead. Traversal is similar O(logn) Code is clean and simple

24 What affects performance? Build Strategy Scene Geometry View dependence Memory Layout

25 Which is best? Lots of opinions Not much evidence Typical Scenes Type of Applications

26 The case for the BSP Tree Ordered Traversal Lots of papers about them “algorithms for building BVHs that are well-suited for fast traversal are less well investigated than similar algorithms for BSP trees.” -- Ingo Wald, Ph.D Thesis ( 2004 )

27 The case for the UG Iterative traversal Handled huge data Steve Parker’s UG Excellent for dense objects

28 The case for the BVH Simple No copied geometry Comparable speed Ignores empty space

29 What’s the problem? Test Data ( SPD Scenes ) Reproduction of Results -- Gordon Mueller

30 Current Work Build strategy investigation Trying all major types Lots of papers to read Implementation tuning Building test scenes Documenting results

31 Future Work Dynamic structures Storing structures with models Hybrid structures Rigorous analysis

32 Any questions?


Download ppt "Ray Tracing Acceleration Structures Solomon Boulos 4/16/2004."

Similar presentations


Ads by Google