From 78ddaff5855bf8446adef9e18eb0d7b7ddcee52a Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 5 Mar 2023 21:45:56 +0000 Subject: init --- src/material/diffuse_light.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/material/diffuse_light.rs (limited to 'src/material/diffuse_light.rs') 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, +} + +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) + } +} -- cgit v1.2.3