Clamp to 1.0

This commit is contained in:
Michael Zhang 2023-02-15 01:35:32 -06:00
parent 0000034060
commit 000003500b

View file

@ -3,7 +3,7 @@ use ordered_float::NotNan;
use crate::image::Color;
use super::{Scene, data::LightKind};
use super::{data::LightKind, Scene};
/// Information about an intersection
#[derive(Derivative)]
@ -81,10 +81,14 @@ impl Scene {
.max(0.0)
.powf(material.exponent);
diffuse_component + specular_component
let diffuse_and_specular = diffuse_component + specular_component;
light.color.component_mul(&diffuse_and_specular)
})
.sum();
ambient_component + diffuse_and_specular
let result = ambient_component + diffuse_and_specular;
// Need to clamp the result so none of the components goes over 1
result.map(|v| v.min(1.0))
}
}