Add missing file that should have been in earlier commit

This commit is contained in:
Matthew Gordon 2019-11-13 17:48:34 -05:00
parent d2fb84191e
commit 98373a1935
1 changed files with 26 additions and 0 deletions

26
src/integrators.rs Normal file
View File

@ -0,0 +1,26 @@
use nalgebra::{RealField, Vector3};
use super::raycasting::IntersectionInfo;
pub trait Integrator<T: RealField> {
fn integrate(&self, info: &IntersectionInfo<T>) -> T;
}
pub struct DirectionalLight<T: RealField> {
pub direction: Vector3<T>,
pub intensity: T,
}
pub struct PhongIntegrator<T: RealField> {
pub ambient_light: T,
pub lights: Vec<DirectionalLight<T>>,
}
impl<T: RealField> Integrator<T> for PhongIntegrator<T> {
fn integrate(&self, info: &IntersectionInfo<T>) -> T {
self.lights
.iter()
.map(|light| light.intensity * light.direction.dot(&info.normal))
.fold(self.ambient_light, |a, b| a + b)
}
}