summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-02 17:16:52 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-02 17:16:52 +0700
commit5c1dc80be89fe8864275e45feda2fb65e2b575da (patch)
treec1ec1e633cdc12a70898c8cec37bb465d1e59c25
parent93b24b9d01f806cf69ecee86fada9e5b9bf06182 (diff)
fix recursion
-rw-r--r--src/camera.rs8
-rw-r--r--src/common.rs8
-rw-r--r--src/main.rs2
3 files changed, 11 insertions, 7 deletions
diff --git a/src/camera.rs b/src/camera.rs
index a133035..83da862 100644
--- a/src/camera.rs
+++ b/src/camera.rs
@@ -94,14 +94,10 @@ impl Camera {
let mut scattered: Ray = Ray {
origin: Vec3::random_unit(),
direction: Vec3::random_unit(),
- }/* value */;
+ };
let mut attenuation: Color = Color::new(0.0, 0.0, 0.0);
if material.scatter(ray, &rec, &mut attenuation, &mut scattered) {
- let attenuated = self.ray_color(&mut scattered, &world, depth - 1);
- attenuation.r *= attenuated.r;
- attenuation.r *= attenuated.g;
- attenuation.r *= attenuated.b;
- return attenuation;
+ return attenuation.elem_prod(&self.ray_color(&mut scattered, &world, depth - 1));
}
return Color::new(0.0, 0.0, 0.0);
}
diff --git a/src/common.rs b/src/common.rs
index a676939..918c59c 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -46,6 +46,14 @@ impl Color {
}
}
+ pub fn elem_prod(&self, other: &Self) -> Self {
+ Self {
+ r: self.r * other.r,
+ g: self.g * other.g,
+ b: self.b * other.b,
+ }
+ }
+
fn _linear_to_gamma(linear_comp: f32) -> f32 {
if linear_comp > 0.0 { linear_comp.sqrt() } else { 0.0 }
}
diff --git a/src/main.rs b/src/main.rs
index 7c6c8f1..489ef41 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -22,7 +22,7 @@ fn main() {
);
world.push(
- Sphere::new(Point3::new(0.0, 0.0, -1.0), 0.5, MaterialType::Diffuse, Color::new(0.4, 0.4, 0.4))
+ Sphere::new(Point3::new(0.0, 0.0, -1.0), 0.5, MaterialType::Diffuse, Color::new(0.7, 0.7, 0.7))
);
world.push(