From da1c3949a449f3fafe579c62ff6b14ffd993a197 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 21 Feb 2021 18:01:56 +0100 Subject: Add 3d bounding box and merged SceneIntersection and Intersection --- src/trace/mod.rs | 6 +++--- src/trace/pathtrace.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/trace') diff --git a/src/trace/mod.rs b/src/trace/mod.rs index b7de476..d45fb23 100644 --- a/src/trace/mod.rs +++ b/src/trace/mod.rs @@ -1,4 +1,4 @@ -use crate::world::Scene; +use crate::world::{Hittable, Scene}; use crate::core::{Spectrum, Ray, Vector3f}; use crate::sample::Sampler; @@ -30,8 +30,8 @@ impl NormTracer<'_> { impl Tracer for NormTracer<'_> { fn trace(&self, _: &mut dyn Sampler, ray: &Ray) -> Spectrum { // Trace ray, we dont care about material - if let Some(si) = self.scn.intersect(ray) { - let norm = si.i.n * 0.5 + Vector3f::new(0.5); + if let Some(i) = self.scn.intersect(ray) { + let norm = i.n * 0.5 + Vector3f::new(0.5); return Spectrum::new_rgb(norm.x, norm.y, norm.z); } diff --git a/src/trace/pathtrace.rs b/src/trace/pathtrace.rs index 47c6835..2d15976 100644 --- a/src/trace/pathtrace.rs +++ b/src/trace/pathtrace.rs @@ -1,11 +1,13 @@ -use crate::world::Scene; +use crate::world::{Hittable, Scene}; use crate::core::{Ray, Spectrum}; use crate::sample::Sampler; +use crate::material::{Lambertian, Material}; use super::Tracer; pub struct PathTracer<'a> { depth: i32, scn: &'a Scene, + default_mat: Box, } impl PathTracer<'_> { @@ -15,6 +17,7 @@ impl PathTracer<'_> { PathTracer { depth, scn, + default_mat: Box::new(Lambertian::new(Spectrum::ZERO)), } } @@ -24,8 +27,8 @@ impl PathTracer<'_> { return Spectrum::ZERO; } - if let Some(si) = self.scn.intersect(ray) { - if let Some((scalar, nray)) = si.mat.scatter(ray, &si.i, sampler) { + if let Some(i) = self.scn.intersect(ray) { + if let Some((scalar, nray)) = i.m.unwrap_or(self.default_mat.as_ref()).scatter(ray, &i, sampler) { return self.trace_recur(sampler, &nray, depth-1) * scalar; } else { return Spectrum::ZERO; -- cgit v1.2.3