aboutsummaryrefslogtreecommitdiff
path: root/src/material/diffuse_light.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/material/diffuse_light.rs')
-rw-r--r--src/material/diffuse_light.rs29
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)
+ }
+}