diff options
author | Julian T <julian@jtle.dk> | 2021-02-07 17:52:30 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-07 17:52:46 +0100 |
commit | c24d1e52b3f173ba5f4cc04f5a6a449a011a60c7 (patch) | |
tree | ff39abb0473a78aa15fbd2ab4c7f5c82660fe3ab /src/trace | |
parent | 33e747fa1c0957546c10e4d7b490ac7fbb0fd2d2 (diff) |
Add reflecting material
Diffstat (limited to 'src/trace')
-rw-r--r-- | src/trace/pathtrace.rs | 12 |
1 files changed, 9 insertions, 3 deletions
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) } } |