diff --git a/assignment-1b/src/scene/illumination.rs b/assignment-1b/src/scene/illumination.rs index 5223839..8f1786c 100644 --- a/assignment-1b/src/scene/illumination.rs +++ b/assignment-1b/src/scene/illumination.rs @@ -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)) } }