aboutsummaryrefslogtreecommitdiff
path: root/src/trace
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-07 17:52:30 +0100
committerJulian T <julian@jtle.dk>2021-02-07 17:52:46 +0100
commitc24d1e52b3f173ba5f4cc04f5a6a449a011a60c7 (patch)
treeff39abb0473a78aa15fbd2ab4c7f5c82660fe3ab /src/trace
parent33e747fa1c0957546c10e4d7b490ac7fbb0fd2d2 (diff)
Add reflecting material
Diffstat (limited to 'src/trace')
-rw-r--r--src/trace/pathtrace.rs12
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)
}
}