Changed BBox/Ray intersection code to use more simd ops.

This, of course, depends on the simd ops being there, which
currently they are not.  But in the future, hopefully this will
make things speedy.  Will need to test, of course.
This commit is contained in:
Nathan Vegdahl 2016-06-08 22:57:22 -07:00
parent 890c04c44a
commit 61e3d47f56
2 changed files with 30 additions and 6 deletions

View File

@ -44,12 +44,12 @@ impl BBox {
let t2 = (self.max.co - ray.orig.co) * ray.dir_inv.co;
// Find the far and near intersection
let hitt0 = (t1[0].min(t2[0]))
.max(t1[1].min(t2[1]))
.max(t1[2].min(t2[2]));
let hitt1 = (t1[0].max(t2[0]))
.min(t1[1].max(t2[1]))
.min(t1[2].max(t2[2])) * BBOX_MAXT_ADJUST;
let mut near_t = t1.v_min(t2);
let mut far_t = t1.v_max(t2);
near_t.set_3(std::f32::NEG_INFINITY);
far_t.set_3(std::f32::INFINITY);
let hitt0 = near_t.h_max();
let hitt1 = far_t.h_min() * BBOX_MAXT_ADJUST;
// Did we hit?
return hitt0.max(0.0) <= hitt1.min(ray.max_t);

View File

@ -64,6 +64,30 @@ impl Float4 {
self.data.get_unchecked(3).max(*other.data.get_unchecked(3)))
}
}
pub fn set_0(&mut self, n: f32) {
unsafe {
*self.data.get_unchecked_mut(0) = n;
}
}
pub fn set_1(&mut self, n: f32) {
unsafe {
*self.data.get_unchecked_mut(1) = n;
}
}
pub fn set_2(&mut self, n: f32) {
unsafe {
*self.data.get_unchecked_mut(2) = n;
}
}
pub fn set_3(&mut self, n: f32) {
unsafe {
*self.data.get_unchecked_mut(3) = n;
}
}
}