Compare commits

..

No commits in common. "95827a4a52bcc96f28f6d3e04c87476ce8365dd2" and "5c2786a54dce57b0cc907f833f36528a547cf84b" have entirely different histories.

5 changed files with 13 additions and 38 deletions

View File

@ -75,6 +75,7 @@ impl AABB {
pub fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> bool {
self.hit_simd(r, t_min, t_max)
//self.hit_naive(r, t_min, t_max)
}
pub fn hit_naive(&self, r: Ray, t_min: f32, t_max: f32) -> bool {

View File

@ -194,15 +194,13 @@ where
}
}
} else {
let r1 = self.intersect_bvh(r, node.left_child, t_min, t_max);
let r2 = self.intersect_bvh(r, node.left_child + 1, t_min, t_max);
// Merge results, if both hit, take the one closest to the ray origin (smallest t
// value).
match (&r1, &r2) {
(Some(_), None) => return r1,
(None, Some(_)) => return r2,
(None, None) => (),
(Some(rp1), Some(rp2)) => return if rp1.t < rp2.t { r1 } else { r2 },
let hr = self.intersect_bvh(r, node.left_child, t_min, t_max);
if hr.is_some() {
return hr;
}
let hr = self.intersect_bvh(r, node.left_child + 1, t_min, t_max);
if hr.is_some() {
return hr;
}
}
None
@ -284,7 +282,7 @@ fn ray_triangle_intersect_moller_trumbore(r: Ray, tri: &Triangle) -> Option<RayT
if t > EPSILON {
return Some(RayTriangleResult {
t,
p: r.point_at_parameter(t),
p: r.origin + r.direction * t,
});
}
None

View File

@ -104,8 +104,8 @@ impl KDTree {
}),
_ => panic!("Unreachable"),
};
//info!("left_half {:?}", left_half);
//info!("right_half {:?}", right_half);
info!("left_half {:?}", left_half);
info!("right_half {:?}", right_half);
if left_half.is_empty() {
return KDTree::Leaf(Box::new(HitableList::new(right_half)));
};

View File

@ -410,11 +410,8 @@ fn progress(
let ray_diff = current_stat.rays - last_stat.rays;
let now = time::Instant::now();
let start_diff = now - start_time;
let ratio = current_stat.pixels as f32 / pixel_total as f32;
let percent = ratio * 100.;
let elapsed = start_diff.as_secs_f32();
let total = elapsed * (1. / ratio);
let eta = total - elapsed;
let percent = 100. * current_stat.pixels as f32 / pixel_total as f32;
let eta = 100. * start_diff.as_secs_f32() / percent;
format!(
"{:7} / {:7}pixels ({:2.0}%) {:7}pixels/s {:7}rays/s eta {:.0}s",
human.format(current_stat.pixels as f64),

View File

@ -16,7 +16,6 @@ pub struct Vec3 {
}
// Return a `Vec3` with the lowest of each component in v1 or v2.
#[inline]
pub fn min(v1: Vec3, v2: Vec3) -> Vec3 {
Vec3 {
x: v1.x.min(v2.x),
@ -25,7 +24,6 @@ pub fn min(v1: Vec3, v2: Vec3) -> Vec3 {
}
}
// Return a `Vec3` with the greatest of each component in v1 or v2.
#[inline]
pub fn max(v1: Vec3, v2: Vec3) -> Vec3 {
Vec3 {
x: v1.x.max(v2.x),
@ -34,7 +32,6 @@ pub fn max(v1: Vec3, v2: Vec3) -> Vec3 {
}
}
#[inline]
pub fn cross(v1: Vec3, v2: Vec3) -> Vec3 {
Vec3 {
x: v1.y * v2.z - v1.z * v2.y,
@ -43,7 +40,6 @@ pub fn cross(v1: Vec3, v2: Vec3) -> Vec3 {
}
}
#[inline]
pub fn dot(v1: Vec3, v2: Vec3) -> f32 {
v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
}
@ -53,32 +49,26 @@ impl Vec3 {
Vec3 { x, y, z }
}
#[inline]
pub fn min(self) -> f32 {
self.x.min(self.y).min(self.z)
}
#[inline]
pub fn max(self) -> f32 {
self.x.max(self.y).max(self.z)
}
#[inline]
pub fn length(self) -> f32 {
self.squared_length().sqrt()
}
#[inline]
pub fn squared_length(self) -> f32 {
self.x * self.x + self.y * self.y + self.z * self.z
}
#[inline]
pub fn unit_vector(self) -> Vec3 {
self / self.length()
}
#[inline]
pub fn make_unit_vector(&mut self) {
*self = self.unit_vector();
}
@ -121,7 +111,6 @@ impl str::FromStr for Vec3 {
impl Add<f32> for Vec3 {
type Output = Vec3;
#[inline]
fn add(self, r: f32) -> Vec3 {
Vec3 {
x: self.x + r,
@ -134,7 +123,6 @@ impl Add<f32> for Vec3 {
impl Add for Vec3 {
type Output = Vec3;
#[inline]
fn add(self, r: Vec3) -> Vec3 {
Vec3 {
x: self.x + r.x,
@ -147,7 +135,6 @@ impl Add for Vec3 {
impl Div<Vec3> for Vec3 {
type Output = Vec3;
#[inline]
fn div(self, r: Vec3) -> Vec3 {
Vec3 {
x: self.x / r.x,
@ -160,7 +147,6 @@ impl Div<Vec3> for Vec3 {
impl Div<Vec3> for f32 {
type Output = Vec3;
#[inline]
fn div(self, r: Vec3) -> Vec3 {
Vec3 {
x: self / r.x,
@ -173,7 +159,6 @@ impl Div<Vec3> for f32 {
impl Div<f32> for Vec3 {
type Output = Vec3;
#[inline]
fn div(self, r: f32) -> Vec3 {
Vec3 {
x: self.x / r,
@ -185,7 +170,6 @@ impl Div<f32> for Vec3 {
impl Index<usize> for Vec3 {
type Output = f32;
#[inline]
fn index(&self, idx: usize) -> &f32 {
match idx {
0 => &self.x,
@ -199,7 +183,6 @@ impl Index<usize> for Vec3 {
impl Mul for Vec3 {
type Output = Vec3;
#[inline]
fn mul(self, r: Vec3) -> Vec3 {
Vec3 {
x: self.x * r.x,
@ -212,7 +195,6 @@ impl Mul for Vec3 {
impl Mul<Vec3> for f32 {
type Output = Vec3;
#[inline]
fn mul(self, v: Vec3) -> Vec3 {
Vec3 {
x: v.x * self,
@ -225,7 +207,6 @@ impl Mul<Vec3> for f32 {
impl Mul<f32> for Vec3 {
type Output = Vec3;
#[inline]
fn mul(self, r: f32) -> Vec3 {
Vec3 {
x: self.x * r,
@ -238,7 +219,6 @@ impl Mul<f32> for Vec3 {
impl Neg for Vec3 {
type Output = Vec3;
#[inline]
fn neg(self) -> Vec3 {
-1. * self
}
@ -247,7 +227,6 @@ impl Neg for Vec3 {
impl Sub for Vec3 {
type Output = Vec3;
#[inline]
fn sub(self, r: Vec3) -> Vec3 {
Vec3 {
x: self.x - r.x,