From 98373a1935fba5bfec2958ce36f37dd18739c495 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Wed, 13 Nov 2019 17:48:34 -0500 Subject: [PATCH] Add missing file that should have been in earlier commit --- src/integrators.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/integrators.rs 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) + } +}