hit check normal vec angle
This commit is contained in:
		
							parent
							
								
									b82a323642
								
							
						
					
					
						commit
						de16463c4e
					
				
					 2 changed files with 5 additions and 3 deletions
				
			
		| 
						 | 
					@ -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;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue