From 82dee9fde542283d5c6ef245a9f10c2b0871d8c1 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 7 Apr 2020 23:21:31 +0200 Subject: [PATCH] library: render: progress: fix refresh for pathtracing --- pathtracer/src/render/pathtrace/pathtracer.rs | 2 +- pathtracer/src/render/progress.rs | 26 +++++++++++++++---- pathtracer/src/render/raytrace/raytracer.rs | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pathtracer/src/render/pathtrace/pathtracer.rs b/pathtracer/src/render/pathtrace/pathtracer.rs index dec5700..e69184f 100644 --- a/pathtracer/src/render/pathtrace/pathtracer.rs +++ b/pathtracer/src/render/pathtrace/pathtracer.rs @@ -38,7 +38,7 @@ impl Pathtracer { ); let total = width * height; - let p = super::super::progress::get_progressbar(self.scene.shot_rays as u64); + let p = super::super::progress::get_passes_progressbar(self.scene.shot_rays); // Ensure at least one round of shots let img_buf = (0..self.scene.shot_rays.max(1)) diff --git a/pathtracer/src/render/progress.rs b/pathtracer/src/render/progress.rs index 4d2c398..83927fd 100644 --- a/pathtracer/src/render/progress.rs +++ b/pathtracer/src/render/progress.rs @@ -1,10 +1,26 @@ -use indicatif::ProgressBar; +use indicatif::{ProgressBar, ProgressStyle}; -pub fn get_progressbar(total: u64) -> ProgressBar { +pub fn get_progressbar(total: u64, style: &str) -> ProgressBar { let pb = ProgressBar::new(total); pb.set_draw_delta((total / 10000).max(1)); - pb.set_style(indicatif::ProgressStyle::default_bar().template( - "{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {percent:>3}%: {pos}/{len} pixels (ETA: {eta})", - )); + pb.set_style(ProgressStyle::default_bar().template(style)); + pb +} + +pub fn get_pixels_progressbar(total: u64) -> ProgressBar { + get_progressbar( + total, + "{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {percent:>3}%: {pos}/{len} pixels (ETA: {eta})", + ) +} + +pub fn get_passes_progressbar(total: u32) -> ProgressBar { + let pb = get_progressbar( + total as u64, + "{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {percent:>3}%: {pos}/{len} passes (ETA: {eta})", + ); + + pb.enable_steady_tick(1000); + pb } diff --git a/pathtracer/src/render/raytrace/raytracer.rs b/pathtracer/src/render/raytrace/raytracer.rs index 8aceb29..aa9ab6f 100644 --- a/pathtracer/src/render/raytrace/raytracer.rs +++ b/pathtracer/src/render/raytrace/raytracer.rs @@ -40,7 +40,7 @@ impl Raytracer { ); let total = (image.width() * image.height()) as u64; - let pb = super::super::progress::get_progressbar(total); + let pb = super::super::progress::get_pixels_progressbar(total); let pixel_func = if self.scene.shot_rays > 0 { Self::anti_alias_pixel