diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 21:50:40 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 21:50:40 +0700 |
commit | 7301f5af4fc7cb7bc13a9d559183f2f095de47d0 (patch) | |
tree | 05c54e4ce19b925f2fffacc8158041728e23bbec /src/material.rs | |
parent | ece36a7364c3c5e7edd157c389cd8079e21c3423 (diff) |
upd metal fuzz
Diffstat (limited to 'src/material.rs')
-rw-r--r-- | src/material.rs | 12 |
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; |