From 7301f5af4fc7cb7bc13a9d559183f2f095de47d0 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Sun, 2 Mar 2025 21:50:40 +0700 Subject: upd metal fuzz --- src/material.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/material.rs') 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; -- cgit v1.2.3-70-g09d2