From de16463c4ed8244f18201f77529ff38cfd4c73f5 Mon Sep 17 00:00:00 2001 From: JonOfUs Date: Wed, 1 Jun 2022 16:49:39 +0200 Subject: [PATCH] hit check normal vec angle --- src/hittable.rs | 6 ++++-- src/main.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hittable.rs b/src/hittable.rs index 8c9c728..f77a8de 100644 --- a/src/hittable.rs +++ b/src/hittable.rs @@ -71,9 +71,11 @@ impl Hittable for Sphere { let sqrtd = discriminant.sqrt(); let root = (-half_b - sqrtd) / a; - if root < t_min || t_max < root { + let normal = (r.at(root) - self.center) / self.radius; + if root < t_min || t_max < root || Vec3::dot(normal, r.direction()) > 0.0 { let root2 = (-half_b + sqrtd) / a; - if root2 < t_min || t_max < root { + let normal = (r.at(root2) - self.center) / self.radius; + if root2 < t_min || t_max < root || Vec3::dot(normal, r.direction()) > 0.0 { return false; } } diff --git a/src/main.rs b/src/main.rs index 5533084..1a9bbc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ fn ray_color(r: &Ray, world: &HittableList, depth: u32) -> Color { return Color::new(0.0,0.0,0.0); } - if world.hit(r, 0.001, f64::INFINITY, &mut rec) { + if world.hit(r, 0.0, f64::INFINITY, &mut rec) { let target = rec.p + rec.normal + Vec3::random_in_unit_sphere(); return 0.5 * ray_color(&Ray::new(rec.p, target - rec.p), world, depth-1); }