library: light: add luminance to Light trait
This commit is contained in:
parent
394a1ad43d
commit
d86b47f111
|
@ -27,6 +27,10 @@ impl AmbientLight {
|
|||
|
||||
impl Light for AmbientLight {
|
||||
fn illumination(&self, _: &Point) -> LinearColor {
|
||||
self.luminance()
|
||||
}
|
||||
|
||||
fn luminance(&self) -> LinearColor {
|
||||
self.color.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,10 @@ impl DirectionalLight {
|
|||
|
||||
impl Light for DirectionalLight {
|
||||
fn illumination(&self, _: &Point) -> LinearColor {
|
||||
self.luminance()
|
||||
}
|
||||
|
||||
fn luminance(&self) -> LinearColor {
|
||||
self.color.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue