rtiow: BVHTriangles use a fixed 100 divisions for split planes.

This commit is contained in:
Bill Thiede 2023-02-12 13:47:29 -08:00
parent 0158f9ea15
commit ac555beafc

View File

@ -219,27 +219,31 @@ where
} }
fn find_best_split_plane(&self, node: &BVHNode) -> SplitCost { fn find_best_split_plane(&self, node: &BVHNode) -> SplitCost {
let mut best_axis = usize::MAX; let mut best = SplitCost {
let mut best_pos = 0.; pos: 0.,
let mut best_cost = f32::MAX; cost: f32::MAX,
axis: usize::MAX,
};
for axis in 0..3 { for axis in 0..3 {
for i in 0..node.tri_count { let bounds_min = node.aabb.min()[axis];
let triangle = &self.triangles[self.triangle_index[(node.left_first + i) as usize]]; let bounds_max = node.aabb.max()[axis];
let candidate_pos = triangle.centroid[axis]; if bounds_min == bounds_max {
continue;
}
let scale = (bounds_max - bounds_min) / 100.;
for i in 0..100 {
let candidate_pos = bounds_min + (i as f32) * scale;
let cost = self.evaluate_sah(node, axis, candidate_pos); let cost = self.evaluate_sah(node, axis, candidate_pos);
if cost <= best_cost { if cost <= best.cost {
best_pos = candidate_pos; best.pos = candidate_pos;
best_axis = axis; best.axis = axis;
best_cost = cost; best.cost = cost;
} }
} }
} }
SplitCost { best
pos: best_pos,
cost: best_cost,
axis: best_axis,
}
} }
fn subdivide(&mut self, idx: usize) { fn subdivide(&mut self, idx: usize) {