From e11598fc9cb5b0bc5c909ee2da6d2b58976548eb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 18 Mar 2020 23:20:00 +0100 Subject: [PATCH] library: render: scene: clamp colors before sum This was a recurring bug in a previous implementation, clamping the colors before taking the sum of a series of calculations avoid adding a negative value to a positive one and getting a result which does not make sense. --- src/render/scene.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/render/scene.rs b/src/render/scene.rs index 70af479..f2fb8b6 100644 --- a/src/render/scene.rs +++ b/src/render/scene.rs @@ -84,6 +84,7 @@ impl Scene { let random_y: f32 = rng.gen(); self.pixel(x + random_x, y + random_y) }) + .map(LinearColor::clamp) .sum(); acc / self.aliasing_limit as f32 } @@ -158,6 +159,7 @@ impl Scene { self.lights .ambient_lights_iter() .map(|light| color.clone() * light.illumination(&Point::origin())) + .map(LinearColor::clamp) .sum() } @@ -183,6 +185,7 @@ impl Scene { let specular = properties.specular.clone() * reflected.dot(&direction); lum * (diffused + specular) }) + .map(LinearColor::clamp) .sum() } }