From 13e018067631a7401df5b232f95f3d1f7a0cd75c Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 1 Aug 2021 23:24:44 +0200 Subject: Readd reflective material --- src/material/dielectric.rs | 5 +---- src/material/mod.rs | 2 ++ src/material/reflectant.rs | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/material') diff --git a/src/material/dielectric.rs b/src/material/dielectric.rs index 41f47c2..c8dc279 100644 --- a/src/material/dielectric.rs +++ b/src/material/dielectric.rs @@ -3,15 +3,12 @@ use crate::core::{min, Vector3f, Spectrum, Ray}; use crate::world::Intersection; use crate::sample::Sampler; use crate::Float; +use crate::material::reflectant::reflect; pub struct Dielectric { ratio: Float, } -fn reflect(v: Vector3f, n: Vector3f) -> Vector3f { - v - n * (2.0 * v.dot(&n)) -} - // Implementation from RTIOW fn refract(v: Vector3f, n: Vector3f, r_ratio: Float, cos_theta: Float) -> Vector3f { let r_perp = (v + n * cos_theta) * r_ratio; diff --git a/src/material/mod.rs b/src/material/mod.rs index d3c3154..6732598 100644 --- a/src/material/mod.rs +++ b/src/material/mod.rs @@ -6,11 +6,13 @@ mod lambertian; mod diffuse_light; mod sky_light; mod dielectric; +pub mod reflectant; pub use lambertian::Lambertian; pub use diffuse_light::DiffuseLight; pub use sky_light::SkyLight; pub use dielectric::Dielectric; +pub use reflectant::Reflectant; pub trait Material: Sync + Send { fn scatter(&self, _: &Ray, _: &Intersection, _: &mut dyn Sampler) -> Option<(Spectrum, Ray)> { diff --git a/src/material/reflectant.rs b/src/material/reflectant.rs index dea7aca..b5ec0ae 100644 --- a/src/material/reflectant.rs +++ b/src/material/reflectant.rs @@ -18,14 +18,14 @@ impl Reflectant { } } -fn reflect(v: &Vector3f, n: &Vector3f) -> Vector3f { - *v - *n * (2.0 * v.dot(n)) +pub fn reflect(v: Vector3f, n: Vector3f) -> Vector3f { + v - n * (2.0 * v.dot(&n)) } impl Material for Reflectant { fn scatter(&self, ray: &Ray, i: &Intersection, sampler: &mut dyn Sampler) -> Option<(Spectrum, Ray)> { // Find reflectance vector - let mut reflected = reflect(&ray.direction, &i.n); + let mut reflected = reflect(ray.direction, i.n); if let Some(fuzz) = self.fuzz { reflected += &(sampler.get_unit_vector() * fuzz); } -- cgit v1.2.3