diff --git a/src/integrators.rs b/src/integrators.rs new file mode 100644 index 0000000..34781c3 --- /dev/null +++ b/src/integrators.rs @@ -0,0 +1,26 @@ +use nalgebra::{RealField, Vector3}; + +use super::raycasting::IntersectionInfo; + +pub trait Integrator { + fn integrate(&self, info: &IntersectionInfo) -> T; +} + +pub struct DirectionalLight { + pub direction: Vector3, + pub intensity: T, +} + +pub struct PhongIntegrator { + pub ambient_light: T, + pub lights: Vec>, +} + +impl Integrator for PhongIntegrator { + fn integrate(&self, info: &IntersectionInfo) -> T { + self.lights + .iter() + .map(|light| light.intensity * light.direction.dot(&info.normal)) + .fold(self.ambient_light, |a, b| a + b) + } +}