From d86b47f11190dac26ee779edacc51753cdda8c7c Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 9 May 2020 17:44:39 +0200 Subject: [PATCH] library: light: add luminance to Light trait --- pathtracer/src/light/ambient_light.rs | 4 ++++ pathtracer/src/light/directional_light.rs | 4 ++++ pathtracer/src/light/mod.rs | 3 +++ pathtracer/src/light/point_light.rs | 6 +++++- pathtracer/src/light/spot_light.rs | 6 +++++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pathtracer/src/light/ambient_light.rs b/pathtracer/src/light/ambient_light.rs index 6e8a75f..708dd92 100644 --- a/pathtracer/src/light/ambient_light.rs +++ b/pathtracer/src/light/ambient_light.rs @@ -27,6 +27,10 @@ impl AmbientLight { impl Light for AmbientLight { fn illumination(&self, _: &Point) -> LinearColor { + self.luminance() + } + + fn luminance(&self) -> LinearColor { self.color.clone() } } diff --git a/pathtracer/src/light/directional_light.rs b/pathtracer/src/light/directional_light.rs index b40d153..512c2d1 100644 --- a/pathtracer/src/light/directional_light.rs +++ b/pathtracer/src/light/directional_light.rs @@ -34,6 +34,10 @@ impl DirectionalLight { impl Light for DirectionalLight { fn illumination(&self, _: &Point) -> LinearColor { + self.luminance() + } + + fn luminance(&self) -> LinearColor { self.color.clone() } } diff --git a/pathtracer/src/light/mod.rs b/pathtracer/src/light/mod.rs index e7e68a5..2aa3607 100644 --- a/pathtracer/src/light/mod.rs +++ b/pathtracer/src/light/mod.rs @@ -9,6 +9,9 @@ use nalgebra::Unit; pub trait Light: std::fmt::Debug { /// Get the illumination of that light on that point. fn illumination(&self, point: &Point) -> LinearColor; + + /// Get the raw luminance of that light + fn luminance(&self) -> LinearColor; } /// Represent a light which has an abstract position in the scene being rendered. diff --git a/pathtracer/src/light/point_light.rs b/pathtracer/src/light/point_light.rs index a26863b..1dd2ced 100644 --- a/pathtracer/src/light/point_light.rs +++ b/pathtracer/src/light/point_light.rs @@ -36,7 +36,11 @@ impl PointLight { impl Light for PointLight { fn illumination(&self, point: &Point) -> LinearColor { let dist = (self.position - point).norm(); - self.color.clone() / dist + self.luminance() / dist + } + + fn luminance(&self) -> LinearColor { + self.color.clone() } } diff --git a/pathtracer/src/light/spot_light.rs b/pathtracer/src/light/spot_light.rs index 1526071..faa2c97 100644 --- a/pathtracer/src/light/spot_light.rs +++ b/pathtracer/src/light/spot_light.rs @@ -54,11 +54,15 @@ impl Light for SpotLight { let delt = point - self.position; let cos = self.direction.dot(&delt.normalize()); if cos >= self.cosine_value { - self.color.clone() / delt.norm_squared() + self.luminance() / delt.norm_squared() } else { LinearColor::black() } } + + fn luminance(&self) -> LinearColor { + self.color.clone() + } } impl SpatialLight for SpotLight {