Make BVH faster by doing hit test on bbox before descending.

This commit is contained in:
Bill Thiede 2018-09-22 12:06:29 -07:00
parent fedcd3792b
commit 02639e4d3f

View File

@ -221,16 +221,25 @@ impl Hit for BVHNode {
BVHNode::Branch { BVHNode::Branch {
ref left, ref left,
ref right, ref right,
.. ref bbox,
} => match (left.hit(r, t_min, t_max), right.hit(r, t_min, t_max)) { } => match bbox {
(Some(hit_left), Some(hit_right)) => if hit_left.t < hit_right.t { Some(ref bbox) => {
return Some(hit_left); if bbox.hit(r, t_min, t_max) {
} else { match (left.hit(r, t_min, t_max), right.hit(r, t_min, t_max)) {
return Some(hit_right); (Some(hit_left), Some(hit_right)) => if hit_left.t < hit_right.t {
}, return Some(hit_left);
(Some(hit_left), None) => Some(hit_left), } else {
(None, Some(hit_right)) => Some(hit_right), return Some(hit_right);
(None, None) => None, },
(Some(hit_left), None) => return Some(hit_left),
(None, Some(hit_right)) => return Some(hit_right),
(None, None) => return None,
};
} else {
return None;
}
}
None => None,
}, },
} }
} }
@ -252,7 +261,7 @@ impl BVH {
let count = l.len(); let count = l.len();
let start = Instant::now(); let start = Instant::now();
let bvh = BVH { let bvh = BVH {
root: BVHNode::new_sah(l, t_min, t_max), root: BVHNode::new_dumb(l, t_min, t_max),
}; };
let runtime = start.elapsed(); let runtime = start.elapsed();
info!( info!(