Clamp to 1.0
This commit is contained in:
parent
0000034060
commit
000003500b
1 changed files with 7 additions and 3 deletions
|
@ -3,7 +3,7 @@ use ordered_float::NotNan;
|
||||||
|
|
||||||
use crate::image::Color;
|
use crate::image::Color;
|
||||||
|
|
||||||
use super::{Scene, data::LightKind};
|
use super::{data::LightKind, Scene};
|
||||||
|
|
||||||
/// Information about an intersection
|
/// Information about an intersection
|
||||||
#[derive(Derivative)]
|
#[derive(Derivative)]
|
||||||
|
@ -81,10 +81,14 @@ impl Scene {
|
||||||
.max(0.0)
|
.max(0.0)
|
||||||
.powf(material.exponent);
|
.powf(material.exponent);
|
||||||
|
|
||||||
diffuse_component + specular_component
|
let diffuse_and_specular = diffuse_component + specular_component;
|
||||||
|
light.color.component_mul(&diffuse_and_specular)
|
||||||
})
|
})
|
||||||
.sum();
|
.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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue