Skip to content

Commit 4af3378

Browse files
committed
Use centroids for SAH partition
Signed-off-by: Mustafa Haiderbhai <[email protected]>
1 parent f5857bc commit 4af3378

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

warp/native/bvh.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,20 @@ float TopDownBVHBuilder::partition_sah_indices(const vec3* lowers, const vec3* u
392392
assert(end - start >= 2);
393393

394394
int n = end - start;
395-
vec3 edges = range_bounds.edges();
396-
397-
bounds3 b = calc_bounds(lowers, uppers, indices, start, end);
398395

396+
bounds3 centroid_bounds;
397+
for (int i = start; i < end; ++i)
398+
{
399+
vec3 item_center = 0.5f * (lowers[indices[i]] + uppers[indices[i]]);
400+
centroid_bounds.add_point(item_center);
401+
}
402+
vec3 edges = centroid_bounds.edges();
403+
399404
split_axis = longest_axis(edges);
400405

401406
// compute each bucket
402-
float range_start = b.lower[split_axis];
403-
float range_end = b.upper[split_axis];
407+
float range_start = centroid_bounds.lower[split_axis];
408+
float range_end = centroid_bounds.upper[split_axis];
404409

405410
// Guard against zero extent along the split axis to avoid division-by-zero
406411
if (range_end <= range_start)

0 commit comments

Comments
 (0)