Compare commits
5 Commits
5c2786a54d
...
95827a4a52
| Author | SHA1 | Date | |
|---|---|---|---|
| 95827a4a52 | |||
| d3dd002883 | |||
| ef737c6df9 | |||
| 2c490b7e83 | |||
| 63f8fba6a4 |
@ -75,7 +75,6 @@ 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 {
|
||||
|
||||
@ -194,13 +194,15 @@ where
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
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 },
|
||||
}
|
||||
}
|
||||
None
|
||||
@ -282,7 +284,7 @@ fn ray_triangle_intersect_moller_trumbore(r: Ray, tri: &Triangle) -> Option<RayT
|
||||
if t > EPSILON {
|
||||
return Some(RayTriangleResult {
|
||||
t,
|
||||
p: r.origin + r.direction * t,
|
||||
p: r.point_at_parameter(t),
|
||||
});
|
||||
}
|
||||
None
|
||||
|
||||
@ -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)));
|
||||
};
|
||||
|
||||
@ -410,8 +410,11 @@ fn progress(
|
||||
let ray_diff = current_stat.rays - last_stat.rays;
|
||||
let now = time::Instant::now();
|
||||
let start_diff = now - start_time;
|
||||
let percent = 100. * current_stat.pixels as f32 / pixel_total as f32;
|
||||
let eta = 100. * start_diff.as_secs_f32() / percent;
|
||||
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;
|
||||
format!(
|
||||
"{:7} / {:7}pixels ({:2.0}%) {:7}pixels/s {:7}rays/s eta {:.0}s",
|
||||
human.format(current_stat.pixels as f64),
|
||||
|
||||
@ -16,6 +16,7 @@ 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),
|
||||
@ -24,6 +25,7 @@ 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),
|
||||
@ -32,6 +34,7 @@ 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,
|
||||
@ -40,6 +43,7 @@ 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
|
||||
}
|
||||
@ -49,26 +53,32 @@ 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();
|
||||
}
|
||||
@ -111,6 +121,7 @@ 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,
|
||||
@ -123,6 +134,7 @@ 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,
|
||||
@ -135,6 +147,7 @@ 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,
|
||||
@ -147,6 +160,7 @@ 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,
|
||||
@ -159,6 +173,7 @@ 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,
|
||||
@ -170,6 +185,7 @@ 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,
|
||||
@ -183,6 +199,7 @@ 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,
|
||||
@ -195,6 +212,7 @@ impl Mul for Vec3 {
|
||||
impl Mul<Vec3> for f32 {
|
||||
type Output = Vec3;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, v: Vec3) -> Vec3 {
|
||||
Vec3 {
|
||||
x: v.x * self,
|
||||
@ -207,6 +225,7 @@ 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,
|
||||
@ -219,6 +238,7 @@ impl Mul<f32> for Vec3 {
|
||||
impl Neg for Vec3 {
|
||||
type Output = Vec3;
|
||||
|
||||
#[inline]
|
||||
fn neg(self) -> Vec3 {
|
||||
-1. * self
|
||||
}
|
||||
@ -227,6 +247,7 @@ impl Neg for Vec3 {
|
||||
impl Sub for Vec3 {
|
||||
type Output = Vec3;
|
||||
|
||||
#[inline]
|
||||
fn sub(self, r: Vec3) -> Vec3 {
|
||||
Vec3 {
|
||||
x: self.x - r.x,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user