diff --git a/rtiow/src/bin/tracer.rs b/rtiow/src/bin/tracer.rs index b745dcf..f9f1ec8 100644 --- a/rtiow/src/bin/tracer.rs +++ b/rtiow/src/bin/tracer.rs @@ -32,7 +32,7 @@ fn main() -> Result<(), std::io::Error> { .start(pprof_path.to_str().unwrap().as_bytes()) .unwrap(); } - let res = render(scene, &opt.output); + let res = render(scene, &opt.output, opt.store_intermediate); if let Some(pprof_path) = opt.pprof { info!("Saving pprof to {}", pprof_path.to_string_lossy()); PROFILER.lock().unwrap().stop().unwrap(); diff --git a/rtiow/src/renderer.rs b/rtiow/src/renderer.rs index f2de053..c603b92 100644 --- a/rtiow/src/renderer.rs +++ b/rtiow/src/renderer.rs @@ -1,5 +1,7 @@ use std; use std::fmt; +use std::io; +use std::io::Write; use std::path::Path; use std::path::PathBuf; use std::str; @@ -97,6 +99,9 @@ pub struct Opt { /// Use acceleration data structure, may be BVH or kd-tree depending on scene. #[structopt(long = "use_accel")] pub use_accel: bool, + /// Store intermediate images when -s > 1 + #[structopt(long = "store_intermediate")] + pub store_intermediate: bool, /// Output directory #[structopt(parse(from_os_str), default_value = "/tmp/tracer")] @@ -165,10 +170,14 @@ fn render_worker( } output_chan.send((subsample, pixel_data)); } - info!("Shutting down worker {}", tid); + trace!(target: "renderer", "Shutting down worker {}", tid); } -pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::io::Error> { +pub fn render( + scene: Scene, + output_dir: &Path, + store_intermediate: bool, +) -> std::result::Result<(), std::io::Error> { let (seq_tx, seq_rx) = channel::unbounded(); let (pixel_data_tx, pixel_data_rx) = channel::unbounded(); @@ -193,8 +202,9 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i acc.push(Default::default()); } + println!("Rendering with {} subsamples", scene.subsamples); let mut img = RgbImage::new(scene.width as u32, scene.height as u32); - for (_subsample, pixel_data) in pixel_data_rx { + for (subsample, pixel_data) in pixel_data_rx { acc_count += 1; pixel_data.iter().enumerate().for_each(|(idx, p)| { let x = idx % scene.width; @@ -216,10 +226,18 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i ]), ); }); - let path = output_dir.join(format!("iteration{:05}.png", acc_count)); - trace!(target: "renderer", "Saving {}", path.to_string_lossy()); - img.save(&path) - .unwrap_or_else(|_| panic!("Failed save {}", path.to_string_lossy())); + if subsample % 10 == 0 { + print!("{}", subsample); + } else { + print!("."); + } + io::stdout().flush().unwrap(); + if store_intermediate { + let path = output_dir.join(format!("iteration{:05}.png", acc_count)); + trace!(target: "renderer", "Saving {}", path.to_string_lossy()); + img.save(&path) + .unwrap_or_else(|_| panic!("Failed save {}", path.to_string_lossy())); + } } let path = output_dir.join("final.png"); // Write the contents of this image to the Writer in PNG format.