Make BVH faster by doing hit test on bbox before descending.
This commit is contained in:
parent
fedcd3792b
commit
02639e4d3f
@ -221,16 +221,25 @@ impl Hit for BVHNode {
|
||||
BVHNode::Branch {
|
||||
ref left,
|
||||
ref right,
|
||||
..
|
||||
} => match (left.hit(r, t_min, t_max), right.hit(r, t_min, t_max)) {
|
||||
(Some(hit_left), Some(hit_right)) => if hit_left.t < hit_right.t {
|
||||
return Some(hit_left);
|
||||
} else {
|
||||
return Some(hit_right);
|
||||
},
|
||||
(Some(hit_left), None) => Some(hit_left),
|
||||
(None, Some(hit_right)) => Some(hit_right),
|
||||
(None, None) => None,
|
||||
ref bbox,
|
||||
} => match bbox {
|
||||
Some(ref bbox) => {
|
||||
if bbox.hit(r, t_min, t_max) {
|
||||
match (left.hit(r, t_min, t_max), right.hit(r, t_min, t_max)) {
|
||||
(Some(hit_left), Some(hit_right)) => if hit_left.t < hit_right.t {
|
||||
return Some(hit_left);
|
||||
} else {
|
||||
return Some(hit_right);
|
||||
},
|
||||
(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 start = Instant::now();
|
||||
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();
|
||||
info!(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user