From 3ef8f4d918406eec6bdc29e0ebd883fabfac9b2e Mon Sep 17 00:00:00 2001 From: Julian T Date: Thu, 5 Aug 2021 15:44:40 +0200 Subject: Add picture for c5505ab84820248c6dba35fc06aef9e0ced183de --- src/trace/mod.rs | 41 ---------------------------------- src/trace/pathtrace.rs | 60 -------------------------------------------------- 2 files changed, 101 deletions(-) delete mode 100644 src/trace/mod.rs delete mode 100644 src/trace/pathtrace.rs (limited to 'src/trace') diff --git a/src/trace/mod.rs b/src/trace/mod.rs deleted file mode 100644 index d45fb23..0000000 --- a/src/trace/mod.rs +++ /dev/null @@ -1,41 +0,0 @@ -use crate::world::{Hittable, Scene}; -use crate::core::{Spectrum, Ray, Vector3f}; -use crate::sample::Sampler; - -mod pathtrace; -pub use pathtrace::PathTracer; - -/// Simple surface normal tracer -/// -/// This ray tracer bases color values on the hit surface normals -pub struct NormTracer<'a> { - scn: &'a Scene, -} - -/// Alias for chosen trace implementation. -/// -/// This is swiched at compile time to save alot of time. -pub type DefaultTracer<'a> = PathTracer<'a>; - -pub trait Tracer { - fn trace(&self, sampler: &mut dyn Sampler, ray: &Ray) -> Spectrum; -} - -impl NormTracer<'_> { - pub fn new(scn: &Scene) -> NormTracer { - NormTracer {scn} - } -} - -impl Tracer for NormTracer<'_> { - 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); - } - - Spectrum::new_rgb(0.0, 0.0, 0.0) - } -} diff --git a/src/trace/pathtrace.rs b/src/trace/pathtrace.rs deleted file mode 100644 index f53e433..0000000 --- a/src/trace/pathtrace.rs +++ /dev/null @@ -1,60 +0,0 @@ -use crate::world::{Hittable, Scene}; -use crate::core::{Ray, Spectrum}; -use crate::material::Material; -use crate::sample::Sampler; -use super::Tracer; - -pub struct PathTracer<'a> { - depth: i32, - scn: &'a Scene, - background: Option>, -} - -impl PathTracer<'_> { - pub fn new(scn: &Scene, depth: Option, background: Option>) -> PathTracer { - let depth = depth.unwrap_or(-1); - - PathTracer { - depth, - scn, - background, - } - } - - pub fn trace_recur(&self, sampler: &mut dyn Sampler, ray: &Ray, depth: i32) -> Spectrum { - - if depth == 0 { - return Spectrum::ZERO; - } - - if let Some(i) = self.scn.intersect(ray) { - // Extract material or default - if let Some(mat) = i.m { - let mut col = Spectrum::ZERO; - - if let Some((scalar, nray)) = mat.scatter(ray, &i, sampler) { - col += &(self.trace_recur(sampler, &nray, depth-1) * scalar); - } - - if let Some(c) = mat.emitted(ray) { - col += &c; - } - - return col; - } - } - - // If no color return background - if let Some(back) = &self.background { - back.emitted(ray).unwrap_or(Spectrum::ZERO) - } else { - Spectrum::ZERO - } - } -} - -impl Tracer for PathTracer<'_> { - fn trace(&self, sampler: &mut dyn Sampler, ray: &Ray) -> Spectrum { - self.trace_recur(sampler, ray, self.depth) - } -} -- cgit v1.2.3