summaryrefslogtreecommitdiff
path: root/src/material.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/material.rs')
-rw-r--r--src/material.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/material.rs b/src/material.rs
index 2b3deae..731eb0c 100644
--- a/src/material.rs
+++ b/src/material.rs
@@ -10,12 +10,14 @@ pub enum MaterialType {
pub struct Material {
pub material_type: MaterialType,
- pub albedo: Color
+ pub albedo: Color,
+ pub fuzz: f32,
}
impl Material {
- pub fn new(albedo: Color, material_type: MaterialType) -> Self {
- Self { albedo, material_type }
+ pub fn new(albedo: Color, material_type: MaterialType, fuzz: f32) -> Self {
+ let fuzz = if fuzz < 1.0 { fuzz } else { 1.0 };
+ Self { albedo, material_type, fuzz }
}
pub fn scatter(&self, r_in: &Ray, rec: &HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool {
@@ -29,7 +31,9 @@ impl Material {
}
}
MaterialType::Metal => {
- r_in.reflect(&rec.normal)
+ let mut reflected = r_in.reflect(&rec.normal);
+ reflected.unit().add(&Vec3::random_unit().scalar_mul(self.fuzz))
+
}
};
scattered.origin = rec.position;