diff options
author | lamp | 2023-03-05 21:45:56 +0000 |
---|---|---|
committer | lamp | 2023-03-05 21:45:56 +0000 |
commit | 78ddaff5855bf8446adef9e18eb0d7b7ddcee52a (patch) | |
tree | 0d0e93cfa28751a2f96518eeb231cf715958e1fa /src/material/metal.rs |
init
Diffstat (limited to 'src/material/metal.rs')
-rw-r--r-- | src/material/metal.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/material/metal.rs b/src/material/metal.rs new file mode 100644 index 0000000..2865a2f --- /dev/null +++ b/src/material/metal.rs @@ -0,0 +1,18 @@ +use super::Material; +use crate::{hittable::HitRecord, vec3::Vec3}; +use crate::vec3::Color; +use crate::ray::Ray; + +pub struct Metal { + pub albedo: Color, + pub fuzz: f64, // TODO: This should have value 0.0 - 1.0; this is not enforced +} + +impl Material for Metal { + fn scatter(&self, ray_in: &Ray, hit_record: &HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool { + let reflected = ray_in.direction.unit_vector().reflect(&hit_record.normal); + *scattered = Ray { origin: hit_record.p.clone(), direction: reflected + self.fuzz * Vec3::random_in_unit_sphere(), time: ray_in.time }; + *attenuation = self.albedo.clone(); + scattered.direction.dot(&hit_record.normal) > 0.0 + } +} |