diff options
author | Julian T <julian@jtle.dk> | 2021-02-07 14:25:06 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-07 14:26:20 +0100 |
commit | 33e747fa1c0957546c10e4d7b490ac7fbb0fd2d2 (patch) | |
tree | 515b2b2e017329cbcada60e898fb5795fbceb5cd /src/trace | |
parent | a43ab40a75e9d4c6ee3fbdd583bc93574db19124 (diff) |
Abstracted lambertian into material
Diffstat (limited to 'src/trace')
-rw-r--r-- | src/trace/mod.rs | 6 | ||||
-rw-r--r-- | src/trace/pathtrace.rs | 9 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/trace/mod.rs b/src/trace/mod.rs index 7f02f6f..cf06246 100644 --- a/src/trace/mod.rs +++ b/src/trace/mod.rs @@ -28,9 +28,9 @@ impl NormTracer<'_> { } impl Tracer for NormTracer<'_> { - fn trace(&self, sampler: &mut dyn Sampler, ray: &Ray) -> Spectrum { - // Trace ray - if let Some(i) = self.scn.intersect(ray) { + fn trace(&self, _: &mut dyn Sampler, ray: &Ray) -> Spectrum { + // Trace ray, we dont care about material + 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 32a8e15..a3a688a 100644 --- a/src/trace/pathtrace.rs +++ b/src/trace/pathtrace.rs @@ -20,11 +20,10 @@ impl PathTracer<'_> { pub fn trace_recur(&self, sampler: &mut dyn Sampler, ray: &Ray) -> Spectrum { - if let Some(i) = self.scn.intersect(ray) { - // Get a random direction in the hemisphere a i.p - // This is Lambertian reflection - let target = i.p + i.n + sampler.get_unit_vector(); - return self.trace_recur(sampler, &Ray::new_to(i.p, target)) * 0.5; + 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; + } } // Simulates a sky |