Parallel BVH Construction using k-means Clustering · Parallel BVH Construction using k-means...
Transcript of Parallel BVH Construction using k-means Clustering · Parallel BVH Construction using k-means...
Parallel BVH Construction using k-meansClustering
Daniel Meister and Jirı Bittner
Department of Computer Graphics and InteractionFaculty of Electrical Engineering
Czech Technical University in Prague
Motivation: Interactive Ray Tracing
t = tbuild + ttrace + tshadingTrade-off between BVH quality (ttrace) and BVH build (tbuild)
Goal minimize tbuild + ttrace
camera
image plane
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 2/19
Bounding Volume Hierarchy
Ray tracing, collision detection, and visibility cullingRooted tree of arbitrary branching factor
Geometric primitives in leavesBounding volumes in interior nodes
Branching factor 2, axis aligned bounding boxes
A
B
AB
[Clark 1976]
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 3/19
Surface Area Heuristic(2n − 3)!!1 valid binary bounding volume hierarchies
c(N) =⎧⎪⎪⎨⎪⎪⎩
kT + P (NL∣N)c(NL) + P (NR∣N)c(NR) if N is interior node
kI ∣N ∣ otherwise
P (NL∣N) =SA(NL)SA(N) P (NR∣N) =
SA(NR)SA(N)
NNL NR
[MacDonald and Booth 1990]1double factorial defined as k!! = k(k − 2)(k − 4) . . .1 for odd k
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 4/19
BVH Construction Methods
Top-down
Surface Area Heuristic [Hunt et al. 2007, ...]
Binning [Wald 2007, ...]
k-means clustering
Bottom-up
Agglomerative clustering [Walter et al. 2008, Gu et al. 2013]
Insertion
Heuristic greedy search [Goldsmith and Salmon 1987]
Online construction [Bittner et al. 2015]
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 5/19
BVH Construction Methods
Top-down
Surface Area Heuristic [Hunt et al. 2007, ...]
Binning [Wald 2007, ...]
k-means clustering
Bottom-up
Agglomerative clustering [Walter et al. 2008, Gu et al. 2013]
Insertion
Heuristic greedy search [Goldsmith and Salmon 1987]
Online construction [Bittner et al. 2015]
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 5/19
k-means Clustering
pass n
pass 2
pass 1
....
... ......
...
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 6/19
k-means Clustering
Lloyd’s algorithm [Lloyd 1982]
Initialize k representatives
k-means loop
Assignment stepUpdate step
Initialization of k representatives r1, . . . , rk
Randomly draw r1To select ri
Randomly draw p candidatesSelect one maximizing distance to the nearest already selected representative
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 7/19
BVH Construction via k-means Clustering
Distance d between bounding boxes b1 and b2
d(b1,b2) = ∣∣bmin1 − bmin
2 ∣∣2 + ∣∣bmax1 − bmax
2 ∣∣2
Positions of representatives
rt+1i = 1
∣Cti ∣( ∑bj∈Cti
bminj , ∑
bj∈Ctibmaxj )
bmin1
bmin2
bmax1
bmax2
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 8/19
Agglomerative Clustering
All treelets processed in parallel
Naıve algorithm without additional data structures O(n3)Surface area of merged cluster as a distance between clusters [Walter et al. 2008]
pass n+1
... ......
...
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 9/19
k-means Visualization
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 10/19
Results
9 scenes, 66k - 12M tris, 3 representatives views, resolution 1024 × 768Path tracing with Russian roulette (GPU ray tracing kernel [Aila and Laine 2009])
Low quality rendering (total time LQ): 8 samples per pixel, 2 shadow samplesHigh quality rendering (total time HQ): 128 samples per pixel, 2 shadow samples
Intel Core I7-3770 3.4 GHz CPU (4 cores), 16 GB RAM
CUDA: NVIDIA GeForce GTX TITAN Black, 6 GB RAM
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 11/19
Tested Methods
parameters
k ... the number of clusters
p ... the number of candidates in initialization procedure
i ... the number of iterations
reference methods
Full sweep SAH (idealized with zero build time)
LBVH [Karras 2012]: 60-bit Morton codes
HLBVH [Garanzha et al. 2011]: 60-bit Morton codes, 15 bits for SAH splits
ATRBVH [Domingues and Pedrini 2015]: 2 iterations, treelet size 9
Max. 8 triangles per leaf for all methods, SAH cost constants kT = 3, kI = 2
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 12/19
Sponza
66k tris, k = 32, p = 20, i = 10
0.8
0.85
0.9
0.95
1
1.05
1.1
1.15
1.2
1.25
trace speed SAH cost total time LQ total time HQ
k-meansLBVHHLBVHATRBVH
Normalized with the respect to idelized full sweep SAH builder
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 13/19
Conference
331k tris, k = 8, p = 5, i = 2
0.7
0.8
0.9
1
1.1
1.2
1.3
1.4
trace speed SAH cost total time LQ total time HQ
k-meansLBVHHLBVHATRBVH
Normalized with the respect to idelized full sweep SAH builder
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 14/19
Power Plant
12759k tris, k = 16, p = 5, i = 5
0.5
1
1.5
2
2.5
3
3.5
trace speed SAH cost total time LQ total time HQ
k-meansLBVHHLBVHATRBVH
Normalized with the respect to idelized full sweep SAH builder
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 15/19
Power Plant
Kernel times of BVH construction
Q1: k = 8, p = 5, i = 0
Q2: k = 8, p = 5, i = 2
Q3: k = 16, p = 5, i = 5
Q4: k = 32, p = 20, i = 10
Q5: k = 64, p = 30, i = 15
0
500
1000
1500
2000
2500
3000
3500
4000
Q1 Q2 Q3 Q4 Q5
tim
e [m
s]
k-means initializationk-means loopcluster size computationtriangle indices reorderingbounding boxes computationagglomerative clusteringother computation
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 16/19
Power Plant
SAH cost stabilization rate (kT = 3, kI = 2)
k = 8, p = 5
k = 16, p = 5
k = 32, p = 20
k = 64, p = 30
85
90
95
100
105
110
115
0 2 4 6 8 10
SA
H c
ost [
-]
iteration [-]
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 17/19
Conclusion and Future Work
BVH construction
k-means and agglomerative clustering
Viable alternative to Morton ordering
Implementation in CUDA
Future work
k-ary BVH
Evaluation for larger k
Other distance functions (e.g. k-medians)
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 18/19
Thank you for your attention!
Daniel Meister and Jirı Bittner
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 19/19
Euclidean Distance
minr
n
∑i=1∣∣xi − r∣∣22
d
dr(
n
∑i=1∣∣xi − r∣∣22) = −2
n
∑i=1(xi − r)
0 = −2n
∑i=1(xi − r) =
n
∑i=1(xi − r) =
n
∑i=1
xi − nr
r = 1
n
n
∑i=1
xi (mean)
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 20/19
Manhattan Distance
minr
n
∑i=1∣∣xi − r∣∣1
d
dr(
n
∑i=1∣∣xi − r∣∣1) =
n
∑i=1
d
dr∣∣xi − r∣∣1 =
n
∑i=1
d
∑j=1
d
drj∣xj
i − rj ∣ = 0
d
drj∣xj
i − rj ∣ =⎧⎪⎪⎨⎪⎪⎩
−1 xji > rj
1 xji < rj
rj =⎧⎪⎪⎪⎨⎪⎪⎪⎩
xj
(n+12) n odd
12(x
j
(n2) + x
j
(n2+1)) n even
(component-wise median)
Daniel Meister and Jirı Bittner Parallel BVH Construction using k-means Clustering 21/19