From c24d1e52b3f173ba5f4cc04f5a6a449a011a60c7 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 7 Feb 2021 17:52:30 +0100 Subject: Add reflecting material --- src/trace/pathtrace.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/trace/pathtrace.rs') diff --git a/src/trace/pathtrace.rs b/src/trace/pathtrace.rs index a3a688a..811b653 100644 --- a/src/trace/pathtrace.rs +++ b/src/trace/pathtrace.rs @@ -18,11 +18,17 @@ impl PathTracer<'_> { } } - pub fn trace_recur(&self, sampler: &mut dyn Sampler, ray: &Ray) -> Spectrum { + pub fn trace_recur(&self, sampler: &mut dyn Sampler, ray: &Ray, depth: i32) -> Spectrum { + + if depth == 0 { + return Spectrum::ZERO; + } if let Some((mat, i)) = self.scn.intersect(ray) { if let Some((scalar, nray)) = mat.scatter(ray, &i, sampler) { - return self.trace_recur(sampler, &nray) * scalar; + return self.trace_recur(sampler, &nray, depth-1) * scalar; + } else { + return Spectrum::ZERO; } } @@ -35,6 +41,6 @@ impl PathTracer<'_> { impl Tracer for PathTracer<'_> { fn trace(&self, sampler: &mut dyn Sampler, ray: &Ray) -> Spectrum { - self.trace_recur(sampler, ray) + self.trace_recur(sampler, ray, self.depth) } } -- cgit v1.2.3