From 61e3d47f568e091e08120730694377f6d372e1c0 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Wed, 8 Jun 2016 22:57:22 -0700 Subject: [PATCH] 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. --- src/bbox.rs | 12 ++++++------ src/float4.rs | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/bbox.rs b/src/bbox.rs index 39bf9d8..88c3b6a 100644 --- a/src/bbox.rs +++ b/src/bbox.rs @@ -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); diff --git a/src/float4.rs b/src/float4.rs index 953d37b..61acc8e 100644 --- a/src/float4.rs +++ b/src/float4.rs @@ -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; + } + } }