Feat: Fuzzy metal material

... but something is wrong. The colors. They're not right..
This commit is contained in:
2023-06-04 18:29:18 -05:00
parent 16762906a7
commit 46640d39a1

View File

@@ -12,7 +12,7 @@ use rand::distributions::Uniform;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum Material{ pub enum Material{
Lambertian{ albedo: Vec3 }, Lambertian{ albedo: Vec3 },
Metal{ albedo:Vec3 }, Metal{ albedo:Vec3, fuzz: f32 },
} }
impl Material { impl Material {
@@ -46,19 +46,18 @@ impl Material {
*attenuation = *albedo; // deref on both sides? Wacky *attenuation = *albedo; // deref on both sides? Wacky
return true; return true;
}, },
Material::Metal { albedo } => { Material::Metal { albedo, fuzz } => {
let reflected = Vec3::reflect( let reflected = Vec3::reflect(
Vec3::as_unit(&ray_in.dir), Vec3::as_unit(&ray_in.dir),
rec.normal rec.normal
); );
*scattered = Ray{ *scattered = Ray{
orig: rec.p, orig: rec.p,
dir: reflected, dir: reflected + Vec3::rand_in_unit_sphere(srng, distrib) * *fuzz,
}; };
*attenuation = *albedo; *attenuation = *albedo;
return Vec3::dot(scattered.dir, rec.normal) > 0.0; return Vec3::dot(scattered.dir, rec.normal) > 0.0;
}, },
_ => return false,
} }
} }
} }