diff --git a/src/material/mod.rs b/src/material/mod.rs index bbc8094..0c0c77e 100644 --- a/src/material/mod.rs +++ b/src/material/mod.rs @@ -7,6 +7,8 @@ pub trait Material: std::fmt::Debug { fn diffuse(&self, point: Point2D) -> LinearColor; /// The specular component on a texel point. fn specular(&self, point: Point2D) -> LinearColor; + /// The reflectivity coefficient on a texel point. + fn reflectivity(&self, point: Point2D) -> f32; } pub mod uniform; diff --git a/src/material/uniform.rs b/src/material/uniform.rs index 63cabef..ce1262f 100644 --- a/src/material/uniform.rs +++ b/src/material/uniform.rs @@ -7,11 +7,16 @@ use crate::Point2D; pub struct UniformMaterial { diffuse: LinearColor, specular: LinearColor, + reflectivity: f32, } impl UniformMaterial { - pub fn new(diffuse: LinearColor, specular: LinearColor) -> Self { - UniformMaterial { diffuse, specular } + pub fn new(diffuse: LinearColor, specular: LinearColor, reflectivity: f32) -> Self { + UniformMaterial { + diffuse, + specular, + reflectivity, + } } } @@ -23,6 +28,10 @@ impl Material for UniformMaterial { fn specular(&self, _: Point2D) -> LinearColor { self.specular.clone() } + + fn reflectivity(&self, _: Point2D) -> f32 { + self.reflectivity + } } #[cfg(test)] @@ -33,14 +42,23 @@ mod test { fn new_works() { let diffuse = LinearColor::new(0., 0.5, 0.); let specular = LinearColor::new(1., 1., 1.); - let mat = UniformMaterial::new(diffuse.clone(), specular.clone()); - assert_eq!(mat, UniformMaterial { diffuse, specular }) + let reflectivity = 0.5; + let mat = UniformMaterial::new(diffuse.clone(), specular.clone(), reflectivity); + assert_eq!( + mat, + UniformMaterial { + diffuse, + specular, + reflectivity + } + ) } fn simple_material() -> impl Material { UniformMaterial::new( LinearColor::new(0.5, 0.5, 0.5), LinearColor::new(1., 1., 1.), + 0.5, ) } @@ -61,4 +79,10 @@ mod test { LinearColor::new(1., 1., 1.) ) } + + #[test] + fn reflectivity_works() { + let mat = simple_material(); + assert_eq!(mat.reflectivity(Point2D::origin()), 0.5) + } } diff --git a/src/render/object.rs b/src/render/object.rs index fc6168c..36fdd0c 100644 --- a/src/render/object.rs +++ b/src/render/object.rs @@ -68,6 +68,9 @@ mod test { fn specular(&self, _: Point2D) -> LinearColor { todo!() } + fn reflectivity(&self, _: Point2D) -> f32 { + todo!() + } } #[derive(Debug)]