From 93b24b9d01f806cf69ecee86fada9e5b9bf06182 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Sun, 2 Mar 2025 16:56:59 +0700 Subject: material --- src/object.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/object.rs') diff --git a/src/object.rs b/src/object.rs index c1bce61..d9e2cc4 100644 --- a/src/object.rs +++ b/src/object.rs @@ -1,5 +1,7 @@ use crate::calculus::calculus::{Point3, Ray, Vec3}; +use crate::common::Color; use crate::interval::Interval; +use crate::material::MaterialType; #[derive(Clone)] pub struct HitRecord { @@ -7,6 +9,8 @@ pub struct HitRecord { pub normal: Vec3, pub t: f32, pub front_face: bool, + pub material: MaterialType, + pub color: Color, } impl Default for HitRecord { @@ -16,6 +20,8 @@ impl Default for HitRecord { normal: Vec3 {x:0.0, y:0.0, z:0.0}, t: 0.0, front_face: false, + material: MaterialType::Diffuse, + color:Color::new(0.0, 0.0, 0.0), } } } @@ -34,12 +40,14 @@ pub trait Hittable { pub struct Sphere { center: Point3, radius: f32, + material: MaterialType, + color: Color } impl Sphere { - pub fn new(center: Vec3, radius: f32) -> Self { + pub fn new(center: Vec3, radius: f32, material: MaterialType, color: Color) -> Self { let radius = f32::max(0.0, radius); - Self { center, radius } + Self { center, radius, material, color } } } @@ -70,6 +78,8 @@ impl Hittable for Sphere { .sub(&self.center) .scalar_mul(1.0 / self.radius); rec.set_face_normal(r, outward_normal); + rec.material = self.material.clone(); + rec.color = self.color.clone(); true } -- cgit v1.2.3-70-g09d2