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.
This commit is contained in:
Nathan Vegdahl 2017-07-12 23:49:12 -07:00
parent 2dcba3aca4
commit 5d0e77f5db

View File

@ -212,7 +212,9 @@ where
for div in 0..(SAH_BIN_COUNT - 1) { 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 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 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 { if tot_cost < smallest_cost {
dim = d; dim = d;
div_n = sah_divs[d][div]; div_n = sah_divs[d][div];