hit check normal vec angle

This commit is contained in:
Jonathan Flueren 2022-06-01 16:49:39 +02:00
parent b82a323642
commit de16463c4e
2 changed files with 5 additions and 3 deletions

View file

@ -71,9 +71,11 @@ impl Hittable for Sphere {
let sqrtd = discriminant.sqrt(); let sqrtd = discriminant.sqrt();
let root = (-half_b - sqrtd) / a; 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; 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; return false;
} }
} }

View file

@ -26,7 +26,7 @@ fn ray_color(r: &Ray, world: &HittableList, depth: u32) -> Color {
return Color::new(0.0,0.0,0.0); 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(); 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); return 0.5 * ray_color(&Ray::new(rec.p, target - rec.p), world, depth-1);
} }