From dad5113724cf7273c68bdae66b5fd625bba7007c Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 28 Apr 2020 12:19:28 +0200 Subject: [PATCH] scene: store number of intermediate steps --- pathtracer/examples/cornell-box.yaml | 4 ++++ pathtracer/src/render/pathtrace/pathtracer.rs | 3 +-- pathtracer/src/scene/mod.rs | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pathtracer/examples/cornell-box.yaml b/pathtracer/examples/cornell-box.yaml index 209a344..bbd44a4 100644 --- a/pathtracer/examples/cornell-box.yaml +++ b/pathtracer/examples/cornell-box.yaml @@ -23,3 +23,7 @@ meshes: - obj_file: "pathtracer/examples/objs/cornell-box.obj" translation: [0.0, 0.0, 2.8] rotation: [0, 180, 0] + +steps: + - 10 + - 25 diff --git a/pathtracer/src/render/pathtrace/pathtracer.rs b/pathtracer/src/render/pathtrace/pathtracer.rs index 088fe2f..538d0fc 100644 --- a/pathtracer/src/render/pathtrace/pathtracer.rs +++ b/pathtracer/src/render/pathtrace/pathtracer.rs @@ -33,7 +33,6 @@ impl Pathtracer { /// /// [`Scene`]: ../scene/scene/struct.Scene.html pub fn render(&self) -> RgbImage { - let steps = vec![1, 5, 50]; let (width, height) = ( self.scene.camera.film().width(), self.scene.camera.film().height(), @@ -73,7 +72,7 @@ impl Pathtracer { } let count = count + 1; // Because count is 0-indexed - if steps.contains(&count) { + if self.scene.steps.contains(&count) { let image = buffer_to_image(&acc, count as u32, width, height); image .save(format!("{}_passes.png", count)) diff --git a/pathtracer/src/scene/mod.rs b/pathtracer/src/scene/mod.rs index 7d4e0af..c8a3b01 100644 --- a/pathtracer/src/scene/mod.rs +++ b/pathtracer/src/scene/mod.rs @@ -26,9 +26,11 @@ pub struct Scene { pub(crate) shot_rays: u32, pub(crate) reflection_limit: u32, pub(crate) diffraction_index: f32, + pub(crate) steps: Vec, } impl Scene { + #[allow(clippy::too_many_arguments)] /// Creates a new `Scene`. /// /// # Examples @@ -62,6 +64,7 @@ impl Scene { /// 5, // amount of rays shot per pixel /// 3, // reflection recursion limit /// 0.0, // diffraction index + /// Vec::new(), // steps /// ); /// ``` pub fn new( @@ -72,6 +75,7 @@ impl Scene { shot_rays: u32, reflection_limit: u32, diffraction_index: f32, + steps: Vec, ) -> Self { let bvh = BVH::build(&mut objects); Scene { @@ -83,6 +87,7 @@ impl Scene { shot_rays, reflection_limit, diffraction_index, + steps, } } } @@ -105,6 +110,8 @@ struct SerializedScene { reflection_limit: u32, #[serde(default = "crate::serialize::default_identity")] starting_diffraction: f32, + #[serde(default)] + steps: Vec, } impl From for Scene { @@ -125,6 +132,7 @@ impl From for Scene { scene.shot_rays, scene.reflection_limit, scene.starting_diffraction, + scene.steps, ) } } @@ -153,6 +161,7 @@ mod test { 5, // aliasing limit 3, // reflection recursion limit 0.0, // diffraction index + Vec::new(), // steps ); } }