use glam::Vec3;
#[allow(unused_imports)]
pub use glam::{Mat3, Mat4, Quat, Vec2, Vec4};
#[derive(Clone, Copy, Debug)]
pub struct Ray {
pub origin: Vec3,
pub dir: Vec3,
}
impl Ray {
#[inline]
pub fn new(origin: Vec3, dir: Vec3) -> Self {
Self { origin, dir: dir.normalize() }
}
#[inline]
pub fn at(&self, t: f32) -> Vec3 {
self.origin + self.dir * t
}
}
#[derive(Clone, Copy, Debug)]
pub struct Hit {
pub t: f32,
pub point: Vec3,
pub normal: Vec3,
pub material: usize,
}
#[inline]
pub fn reflect(v: Vec3, n: Vec3) -> Vec3 {
v - 2.0 * v.dot(n) * n
}
#[inline]
pub fn saturate(x: f32) -> f32 {
x.clamp(0.0, 1.0)
}
#[inline]
pub fn halton(mut i: u32, b: u32) -> f32 {
let mut f = 1.0_f32;
let mut r = 0.0_f32;
while i > 0 {
f /= b as f32;
r += f * (i % b) as f32;
i /= b;
}
r
}