diff --git a/src/materials.rs b/src/materials.rs index d50ef96..a7b554a 100644 --- a/src/materials.rs +++ b/src/materials.rs @@ -4,10 +4,11 @@ use super::colour::{ColourRgbF, NamedColour}; use std::fmt::Debug; +type Bsdf<'a, T> = + Box, Vector3, ColourRgbF) -> ColourRgbF + 'a>; + pub trait Material: Debug { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a>; + fn bsdf<'a>(&'a self) -> Bsdf<'a, T>; fn sample(&self, _w_o: &Vector3) -> Vec> { vec![] @@ -30,9 +31,7 @@ impl LambertianMaterial { } impl Material for LambertianMaterial { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a> { + fn bsdf<'a>(&'a self) -> Bsdf<'a, T> { Box::new( move |_w_o: Vector3, _w_i: Vector3, colour_in: ColourRgbF| { self.colour * colour_in * self.diffuse_strength @@ -50,9 +49,7 @@ pub struct PhongMaterial { } impl Material for PhongMaterial { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a> { + fn bsdf<'a>(&'a self) -> Bsdf<'a, T> { Box::new( move |w_o: Vector3, w_i: Vector3, colour_in: ColourRgbF| { if w_i.z < T::zero() || w_o.z < T::zero() { @@ -77,9 +74,7 @@ pub struct ReflectiveMaterial { } impl Material for ReflectiveMaterial { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a> { + fn bsdf<'a>(&'a self) -> Bsdf<'a, T> { Box::new( move |w_o: Vector3, w_i: Vector3, colour_in: ColourRgbF| { if w_i.z < T::zero() || w_o.z < T::zero() {