cs180 lecture 13 - ucsb · cs180, spring 2019 lingqi yan, uc santa barbara • recall: a box (3d) =...
TRANSCRIPT
![Page 1: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/1.jpg)
CS180: Introduction to Computer GraphicsSpring 2019, Lingqi Yan, UC Santa Barbara
Ray Tracing 2 (Acceleration) Lecture 13:
http://www.cs.ucsb.edu/~lingqi/teaching/cs180.html
![Page 2: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/2.jpg)
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Last Lecture• Shadow mapping for rasterizers
• Introduction to ray tracing
• Ray generation
• Ray object intersection- Ray sphere intersection
- Ray implicit surface intersection
- Ray triangle intersection = Ray plane intersection + inside test
!2
![Page 3: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/3.jpg)
Accelerating Ray-Surface Intersection
![Page 4: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/4.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Ray Tracing – Performance Challenges
Simple ray-scene intersection
• Exhaustively test ray-intersection with every triangle
• Find the closest hit (with minimum t)
Problem:
• Naive algorithm = #pixels ⨉ # traingles (⨉ #bounces)
• Very slow!
For generality, we use the term objects instead of triangles later (but doesn’t necessarily mean entire objects)
!4
![Page 5: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/5.jpg)
Ray Tracing – Performance Challenges
San Miguel Scene, 10.7M triangles
Jun Yan, Tracy Renderer
![Page 6: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/6.jpg)
Ray Tracing – Performance Challenges
Plant Ecosystem, 20M triangles
Deussen et al; Pharr & Humphreys, PBRT
![Page 7: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/7.jpg)
Bounding Volumes
![Page 8: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/8.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Bounding Volumes
Quick way to avoid intersections: bound complex object with a simple volume
• Object is fully contained in the volume
• If it doesn’t hit the volume, it doesn’t hit the object
• So test bvol first, then test object if it hits
!8
![Page 9: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/9.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Ray-Intersection With Box
Could intersect with 6 faces individually Better way: box is the intersection of 3 pairs of slabs
!9
![Page 10: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/10.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Ray Intersection with Axis-Aligned Box2D example; 3D is the same! Compute intersections with slabs and take intersection of tmin/tmax intervals
!10
o,do,d
x0 � x1 � y0 � y1x0 � x1 � y0 � y1
x0 � x1 � y0 � y1
x0 � x1 � y0 � y1
tmin
tmax
o,do,d
x0 � x1 � y0 � y1x0 � x1 � y0 � y1
x0 � x1 � y0 � y1
x0 � x1 � y0 � y1
tmin
tmax
Note: tmin < 0
Intersections with y planes Intersections with x planes
o,do,d
x0 � x1 � y0 � y1x0 � x1 � y0 � y1
x0 � x1 � y0 � y1
x0 � x1 � y0 � y1
tmin
tmax
Final intersection resultHow do we know when the ray misses the box?
![Page 11: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/11.jpg)
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
• Recall: a box (3D) = three pairs of infinitely large slabs
• Key ideas
- The ray enters the box only when it enters all pairs of slabs
- The ray exits the box as long as it exits any pair of slabs
• For each pair, calculate the tmin and tmax (negative is fine)
• For the 3D box, tenter = max{tmin}, texit = min{tmax}
• If tenter < texit, we know the ray stays a while in the box(so they must intersect!) (not done yet, see the next slide)
!11
Ray Intersection with Axis-Aligned Box
![Page 12: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/12.jpg)
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
• However, ray is not a line
- Time t should always be positive for physical correctness!
• What if texit < 0?
- The box is “behind” the ray — no intersection!
• What if tenter < 0?
- The ray’s origin is inside the box — still intersection!
!12
Ray Intersection with Axis-Aligned Box
![Page 13: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/13.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Optimize Ray-Plane Intersection For Axis-Aligned Planes?
!13
r(t) = o+ td, 0 t < 1p : (p� p0) ·N = 0
ax+ by + cz + d = 0
Set p = r(t) and solve for t
(p� p0) ·N = (o+ td� p0) ·N = 0
t =p0 � o) ·N
d ·N
r(t) = o+ td, 0 t < 1p : (p� p0) ·N = 0
ax+ by + cz + d = 0
Set p = r(t) and solve for t
(p� p0) ·N = (o+ td� p0) ·N = 0
t =(p0 � o) ·N
d ·N
3 subtractions, 6 multiplies, 1 division
t =(p0 � o) ·N
d ·N =) t =p0
x � ox
dx
r(t) = o+ td, 0 t < 1p : (p� p0) ·N = 0
ax+ by + cz + d = 0
Set p = r(t) and solve for t
(p� p0) ·N = (o+ td� p0) ·N = 0
t =p0 � o) ·N
d ·N1 subtraction, 1 division
General
Perpendicularto x-axis
![Page 14: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/14.jpg)
Uniform Spatial Partitions (Grids)
![Page 15: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/15.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Preprocess – Build Acceleration Grid
!15
1. Find bounding box
![Page 16: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/16.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Preprocess – Build Acceleration Grid
!16
1. Find bounding box 2. Create grid
![Page 17: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/17.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Preprocess – Build Acceleration Grid
!17
1. Find bounding box 2. Create grid 3. Store each object
in overlapping cells
![Page 18: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/18.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Ray-Scene Intersection
!18
Step through grid in ray traversal order
For each grid cell Test intersection with all objects stored at that cell
![Page 19: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/19.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Grid Resolution?
One cell
• No speedup
!19
![Page 20: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/20.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Grid Resolution?
Too many cells
• Inefficiency due to extraneous grid traversal
!20
![Page 21: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/21.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Grid Resolution?
Heuristic:
• #cells = C * #objs
• C ≈ 27 in 3D
!21
![Page 22: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/22.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Uniform Grids – When They Work Well
!22
Deussen et al; Pharr & Humphreys, PBRT
Grids work well on large collections of objectsthat are distributed evenly in size and space
![Page 23: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/23.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Jun Yan, Tracy Renderer
Uniform Grids – When They Fail
!23
“Teapot in a stadium” problem
![Page 24: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/24.jpg)
Spatial Partitions
![Page 25: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/25.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Spatial Hierarchies
!25
A
A
![Page 26: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/26.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
B
A
Spatial Hierarchies
!26
A
B
![Page 27: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/27.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
4 5
D 3
2 C
Spatial Hierarchies
!27
A
BC
D
1
2
34
5
1 B
A
![Page 28: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/28.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Spatial Partitioning Examples
!28
BSP-TreeKD-Tree
Note: you could have these in both 2D and 3D. In lecture we will illustrate principles in 2D.
Oct-Tree
![Page 29: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/29.jpg)
Object Partitions &
Bounding Volume Hierarchy (BVH)
![Page 30: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/30.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Spatial vs Object Partitions
Spatial partition (e.g.KD-tree) • Partition space into
non-overlapping regions • Objects can be contained in
multiple regions
Object partition (e.g. BVH) • Partition set of objects into
disjoint subsets • Bounding boxes for each
set may overlap in space
!30
![Page 31: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/31.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Bounding Volume Hierarchy (BVH)
!31
Root
![Page 32: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/32.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Bounding Volume Hierarchy (BVH)
!32
![Page 33: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/33.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Bounding Volume Hierarchy (BVH)
!33
![Page 34: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/34.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
C D
B
Bounding Volume Hierarchy (BVH)
!34
A
AB
C
D
![Page 35: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/35.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
Bounding Volume Hierarchy (BVH)
Internal nodes store
• Bounding box
• Children: reference to child nodes Leaf nodes store
• Bounding box
• List of objects Nodes represent subset of primitives in scene
• All objects in subtree
!35
![Page 36: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/36.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
BVH Pre-Processing
• Find bounding box
• Recursively split set of objects in two subsets
• Recompute the bounding box of the subsets
• Stop when there are just a few objects in each set
• Store obj reference(s) in each leaf node
!36
![Page 37: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/37.jpg)
Ren NgCS184/284A
BVH Pre-Processing
Choosing the set partition
• Choose a dimension to split
• Heuristic #1: Always choose the longest axis in node
• Heuristic #2: Split node at location of median object
Termination criteria?
• Heuristic: stop when node contains few elements (e.g. 5)
![Page 38: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/38.jpg)
Slide courtesy of Prof. Ren Ng, UC Berkeley
CS180, Spring 2019 Lingqi Yan, UC Santa Barbara
BVH Recursive Traversal
Intersect(Ray ray, BVH node) {
if (ray misses node.bbox) return;
if (node is a leaf node)
test intersection with all objs;
return closest intersection;
hit1 = Intersect(ray, node.child1);
hit2 = Intersect(ray, node.child2);
return the closer of hit1, hit2;
}
!38
node
child1 child2
![Page 39: CS180 Lecture 13 - UCSB · CS180, Spring 2019 Lingqi Yan, UC Santa Barbara • Recall: a box (3D) = three pairs of infinitely large slabs • Key ideas-The ray enters the box only](https://reader030.vdocuments.site/reader030/viewer/2022041100/5ed834970fa3e705ec0e07f8/html5/thumbnails/39.jpg)
Thank you!