diff options
author | lamp | 2023-03-05 21:45:56 +0000 |
---|---|---|
committer | lamp | 2023-03-05 21:45:56 +0000 |
commit | 78ddaff5855bf8446adef9e18eb0d7b7ddcee52a (patch) | |
tree | 0d0e93cfa28751a2f96518eeb231cf715958e1fa /src/material/diffuse_light.rs |
init
Diffstat (limited to 'src/material/diffuse_light.rs')
-rw-r--r-- | src/material/diffuse_light.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/material/diffuse_light.rs b/src/material/diffuse_light.rs new file mode 100644 index 0000000..fecbcff --- /dev/null +++ b/src/material/diffuse_light.rs @@ -0,0 +1,29 @@ +use std::sync::Arc; + +use super::Material; +use crate::{hittable::HitRecord, texture::Texture, vec3::Point3}; +use crate::vec3::Color; +use crate::texture::SolidColor; +use crate::ray::Ray; + +pub struct DiffuseLight { + emit: Arc<dyn Texture>, +} + +impl DiffuseLight { + pub fn from_color(color: Color) -> Self { + Self { + emit: Arc::new(SolidColor::from_color(color)), + } + } +} + +impl Material for DiffuseLight { + fn scatter(&self, _: &Ray, _: &HitRecord, _: &mut Color, _: &mut Ray) -> bool { + false + } + + fn emitted(&self, u: f64, v: f64, point: &Point3) -> Color { + self.emit.value(u, v, point) + } +} |