-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched from in-tree float4 lib to glam.
- Loading branch information
Showing
21 changed files
with
297 additions
and
2,029 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,33 +9,33 @@ use crate::{ | |
math::{Point, Vector}, | ||
}; | ||
|
||
use float4::{Bool4, Float4}; | ||
use glam::{Vec4, Vec4Mask}; | ||
|
||
const BBOX_MAXT_ADJUST: f32 = 1.00000024; | ||
|
||
/// A SIMD set of 4 3D axis-aligned bounding boxes. | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct BBox4 { | ||
pub x: (Float4, Float4), // (min, max) | ||
pub y: (Float4, Float4), // (min, max) | ||
pub z: (Float4, Float4), // (min, max) | ||
pub x: (Vec4, Vec4), // (min, max) | ||
pub y: (Vec4, Vec4), // (min, max) | ||
pub z: (Vec4, Vec4), // (min, max) | ||
} | ||
|
||
impl BBox4 { | ||
/// Creates a degenerate BBox with +infinity min and -infinity max. | ||
pub fn new() -> BBox4 { | ||
BBox4 { | ||
x: ( | ||
Float4::splat(std::f32::INFINITY), | ||
Float4::splat(std::f32::NEG_INFINITY), | ||
Vec4::splat(std::f32::INFINITY), | ||
Vec4::splat(std::f32::NEG_INFINITY), | ||
), | ||
y: ( | ||
Float4::splat(std::f32::INFINITY), | ||
Float4::splat(std::f32::NEG_INFINITY), | ||
Vec4::splat(std::f32::INFINITY), | ||
Vec4::splat(std::f32::NEG_INFINITY), | ||
), | ||
z: ( | ||
Float4::splat(std::f32::INFINITY), | ||
Float4::splat(std::f32::NEG_INFINITY), | ||
Vec4::splat(std::f32::INFINITY), | ||
Vec4::splat(std::f32::NEG_INFINITY), | ||
), | ||
} | ||
} | ||
|
@@ -45,30 +45,30 @@ impl BBox4 { | |
pub fn from_bboxes(b1: BBox, b2: BBox, b3: BBox, b4: BBox) -> BBox4 { | ||
BBox4 { | ||
x: ( | ||
Float4::new(b1.min.x(), b2.min.x(), b3.min.x(), b4.min.x()), | ||
Float4::new(b1.max.x(), b2.max.x(), b3.max.x(), b4.max.x()), | ||
Vec4::new(b1.min.x(), b2.min.x(), b3.min.x(), b4.min.x()), | ||
Vec4::new(b1.max.x(), b2.max.x(), b3.max.x(), b4.max.x()), | ||
), | ||
y: ( | ||
Float4::new(b1.min.y(), b2.min.y(), b3.min.y(), b4.min.y()), | ||
Float4::new(b1.max.y(), b2.max.y(), b3.max.y(), b4.max.y()), | ||
Vec4::new(b1.min.y(), b2.min.y(), b3.min.y(), b4.min.y()), | ||
Vec4::new(b1.max.y(), b2.max.y(), b3.max.y(), b4.max.y()), | ||
), | ||
z: ( | ||
Float4::new(b1.min.z(), b2.min.z(), b3.min.z(), b4.min.z()), | ||
Float4::new(b1.max.z(), b2.max.z(), b3.max.z(), b4.max.z()), | ||
Vec4::new(b1.min.z(), b2.min.z(), b3.min.z(), b4.min.z()), | ||
Vec4::new(b1.max.z(), b2.max.z(), b3.max.z(), b4.max.z()), | ||
), | ||
} | ||
} | ||
|
||
// Returns whether the given ray intersects with the bboxes. | ||
pub fn intersect_ray(&self, orig: Point, dir_inv: Vector, max_t: f32) -> Bool4 { | ||
pub fn intersect_ray(&self, orig: Point, dir_inv: Vector, max_t: f32) -> Vec4Mask { | ||
// Get the ray data into SIMD format. | ||
let ro_x = orig.co.all_0(); | ||
let ro_y = orig.co.all_1(); | ||
let ro_z = orig.co.all_2(); | ||
let rdi_x = dir_inv.co.all_0(); | ||
let rdi_y = dir_inv.co.all_1(); | ||
let rdi_z = dir_inv.co.all_2(); | ||
let max_t = Float4::splat(max_t); | ||
let ro_x = Vec4::splat(orig.co.x()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cessen
Author
Owner
|
||
let ro_y = Vec4::splat(orig.co.y()); | ||
let ro_z = Vec4::splat(orig.co.z()); | ||
let rdi_x = Vec4::splat(dir_inv.co.x()); | ||
let rdi_y = Vec4::splat(dir_inv.co.y()); | ||
let rdi_z = Vec4::splat(dir_inv.co.z()); | ||
let max_t = Vec4::splat(max_t); | ||
|
||
// Slab tests | ||
let t1_x = (self.x.0 - ro_x) * rdi_x; | ||
|
@@ -79,24 +79,21 @@ impl BBox4 { | |
let t2_z = (self.z.1 - ro_z) * rdi_z; | ||
|
||
// Get the far and near t hits for each axis. | ||
let t_far_x = t1_x.v_max(t2_x); | ||
let t_far_y = t1_y.v_max(t2_y); | ||
let t_far_z = t1_z.v_max(t2_z); | ||
let t_near_x = t1_x.v_min(t2_x); | ||
let t_near_y = t1_y.v_min(t2_y); | ||
let t_near_z = t1_z.v_min(t2_z); | ||
let t_far_x = t1_x.max(t2_x); | ||
let t_far_y = t1_y.max(t2_y); | ||
let t_far_z = t1_z.max(t2_z); | ||
let t_near_x = t1_x.min(t2_x); | ||
let t_near_y = t1_y.min(t2_y); | ||
let t_near_z = t1_z.min(t2_z); | ||
|
||
// Calculate over-all far t hit. | ||
let far_t = | ||
(t_far_x.v_min(t_far_y.v_min(t_far_z)) * Float4::splat(BBOX_MAXT_ADJUST)).v_min(max_t); | ||
let far_t = (t_far_x.min(t_far_y.min(t_far_z)) * Vec4::splat(BBOX_MAXT_ADJUST)).min(max_t); | ||
|
||
// Calculate over-all near t hit. | ||
let near_t = t_near_x | ||
.v_max(t_near_y) | ||
.v_max(t_near_z.v_max(Float4::splat(0.0))); | ||
let near_t = t_near_x.max(t_near_y).max(t_near_z.max(Vec4::splat(0.0))); | ||
|
||
// Hit results | ||
near_t.lt(far_t) | ||
near_t.cmplt(far_t) | ||
} | ||
} | ||
|
||
|
@@ -106,9 +103,9 @@ impl BitOr for BBox4 { | |
|
||
fn bitor(self, rhs: BBox4) -> BBox4 { | ||
BBox4 { | ||
x: (self.x.0.v_min(rhs.x.0), self.x.1.v_max(rhs.x.1)), | ||
y: (self.y.0.v_min(rhs.y.0), self.y.1.v_max(rhs.y.1)), | ||
z: (self.z.0.v_min(rhs.z.0), self.z.1.v_max(rhs.z.1)), | ||
x: (self.x.0.min(rhs.x.0), self.x.1.max(rhs.x.1)), | ||
y: (self.y.0.min(rhs.y.0), self.y.1.max(rhs.y.1)), | ||
z: (self.z.0.min(rhs.z.0), self.z.1.max(rhs.z.1)), | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
I hope you don't mind me commenting, you're one of the first people to use glam so I'm interested in how you are using it. I do have
dup_x
etc methods for doing what yourall_0
method did but I haven't made them public because while glam uses them internally I wasn't sure how useful they would be to other users. Anyway, it looks like they would be useful so I'm make them public. I was also wanting to write a shuffle macro which could also do this, but that would be more verbose and this operation seems common enough that it warrants it's own method. I made an issue so I don't forget here bitshifter/glam-rs#14.