Replies: 2 comments
-
rust code: #[derive(Clone, Copy)]
pub struct Metallic {
pub albedo: Rgb,
pub blur: f64,
}
impl Metallic {
pub fn new(albedo: Rgb, blur: f64) -> Self {
Self {
albedo,
blur: blur.min(1.0),
}
}
}
impl Material for Metallic {
fn scatter(&self, r: &Ray, rec: &HitRecord<'_>, rng: &mut ThreadRng) -> Option<Scatter> {
let reflected = r.direction.unit().reflect(rec.normal);
let scattered = Ray::new(
rec.p,
reflected + self.blur * Vec3::random_in_unit_sphere(rng),
);
if scattered.direction.dot(rec.normal) > 0.0 {
Some(Scatter::new(scattered, self.albedo))
} else {
None
}
}
} reflect method for pub fn reflect(self, normal: Self) -> Self {
self - 2.0 * self.dot(normal) * normal
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm on 9.5 in the 1 weekend book, for some reason the reflection of the center sphere on the left sphere is different than the reflection on the right sphere - I've made left and right the same color to make it easier to see. Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions