From 5d0e77f5dbe1166e6d326fbab918654d77c6873e Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Wed, 12 Jul 2017 23:49:12 -0700 Subject: [PATCH] Improved SAH split code for light tree. The SAH split would happily repeatedly split on the same axis as long as the surface area was reduced as much as splitting on the other axes. This resulted in sliver-like bounding boxes for some scenes, which is terrible for the light tree. The SAH splitting code now accounts for the diagonal of the bounding box, favoring smaller ones. This seems to work well, fixing the issue without introducing any apparent performance regressions. --- src/accel/objects_split.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/accel/objects_split.rs b/src/accel/objects_split.rs index 62ac8c6..94f5d48 100644 --- a/src/accel/objects_split.rs +++ b/src/accel/objects_split.rs @@ -212,7 +212,9 @@ where for div in 0..(SAH_BIN_COUNT - 1) { let left_cost = sah_bins[d][div].0.surface_area() * sah_bins[d][div].2 as f32; let right_cost = sah_bins[d][div].1.surface_area() * sah_bins[d][div].3 as f32; - let tot_cost = left_cost + right_cost; + let left_diag = sah_bins[d][div].0.diagonal(); + let right_diag = sah_bins[d][div].1.diagonal(); + let tot_cost = (left_cost * left_diag) + (right_cost * right_diag); if tot_cost < smallest_cost { dim = d; div_n = sah_divs[d][div];