From 6d7c6c3749fe4f458a03338e0f75f349e0f9bb04 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 15 Feb 2023 01:35:32 -0600 Subject: [PATCH] Clamp to 1.0 --- assignment-1b/src/scene/illumination.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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)) } }