library: light: add luminance to Light trait

This commit is contained in:
Antoine Martin 2020-05-09 17:44:39 +02:00
parent 394a1ad43d
commit d86b47f111
5 changed files with 21 additions and 2 deletions

View file

@ -27,6 +27,10 @@ impl AmbientLight {
impl Light for AmbientLight {
fn illumination(&self, _: &Point) -> LinearColor {
self.luminance()
}
fn luminance(&self) -> LinearColor {
self.color.clone()
}
}

View file

@ -34,6 +34,10 @@ impl DirectionalLight {
impl Light for DirectionalLight {
fn illumination(&self, _: &Point) -> LinearColor {
self.luminance()
}
fn luminance(&self) -> LinearColor {
self.color.clone()
}
}

View file

@ -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.

View file

@ -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()
}
}

View file

@ -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 {