rtiow: BVHTriangles use BVHNode::cost for readability.

This commit is contained in:
Bill Thiede 2023-02-12 13:26:45 -08:00
parent 450342c3d4
commit 0158f9ea15

View File

@ -27,6 +27,11 @@ impl BVHNode {
fn is_leaf(&self) -> bool { fn is_leaf(&self) -> bool {
self.tri_count > 0 self.tri_count > 0
} }
fn cost(&self) -> f32 {
let area = self.aabb.area();
self.tri_count as f32 * area
}
} }
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
@ -236,16 +241,14 @@ where
axis: best_axis, axis: best_axis,
} }
} }
fn subdivide(&mut self, idx: usize) {
let node = &self.bvh_nodes[idx];
let parent_area = node.aabb.area();
let parent_cost = node.tri_count as f32 * parent_area;
fn subdivide(&mut self, idx: usize) {
let (left_first, tri_count, left_count, i) = { let (left_first, tri_count, left_count, i) = {
let node = &self.bvh_nodes[idx]; let node = &self.bvh_nodes[idx];
let split = self.find_best_split_plane(&node); let split = self.find_best_split_plane(&node);
let no_split_cost = node.cost();
// Stop subdividing if it isn't getting any better. // Stop subdividing if it isn't getting any better.
if split.cost >= parent_cost { if split.cost >= no_split_cost {
return; return;
} }