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.
This commit is contained in:
Bruno BELANYI 2020-03-18 23:20:00 +01:00
parent 08d6d7c262
commit e11598fc9c

View file

@ -84,6 +84,7 @@ impl Scene {
let random_y: f32 = rng.gen(); let random_y: f32 = rng.gen();
self.pixel(x + random_x, y + random_y) self.pixel(x + random_x, y + random_y)
}) })
.map(LinearColor::clamp)
.sum(); .sum();
acc / self.aliasing_limit as f32 acc / self.aliasing_limit as f32
} }
@ -158,6 +159,7 @@ impl Scene {
self.lights self.lights
.ambient_lights_iter() .ambient_lights_iter()
.map(|light| color.clone() * light.illumination(&Point::origin())) .map(|light| color.clone() * light.illumination(&Point::origin()))
.map(LinearColor::clamp)
.sum() .sum()
} }
@ -183,6 +185,7 @@ impl Scene {
let specular = properties.specular.clone() * reflected.dot(&direction); let specular = properties.specular.clone() * reflected.dot(&direction);
lum * (diffused + specular) lum * (diffused + specular)
}) })
.map(LinearColor::clamp)
.sum() .sum()
} }
} }