diff --git a/Cargo.toml b/Cargo.toml index 50356f3..ac7088f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ assigning_clones = "deny" build_raymarch = ["sdfu/ultraviolet", "ultraviolet"] color_grad = ["colorgrad"] # for scenes with many non-dense meshes, disable sort_mesh_aabb_hits +pbr = ["dep:pbr"] default = [ "realistic_camera", "sort_mesh_aabb_hits", @@ -55,7 +56,7 @@ num_cpus = "~1.16" ordered-float = "~4.2" parking_lot = "~0.12" paste = "~1.0" -pbr = "~1.1" +pbr = { version = "~1.1", optional = true } png = "~0.17" rand = "~0.8" rayon = "~1.10" diff --git a/src/prelude.rs b/src/prelude.rs index d36e14b..a426e2a 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -25,3 +25,36 @@ pub use math::traits::{CheckInf, CheckNAN, CheckResult, FromScalar, ToScalar}; pub use std::cmp::Ordering; pub use std::f32::consts::{PI, SQRT_2, TAU}; + +#[cfg(feature = "pbr")] +pub use pbr::ProgressBar; + +// dummy ProgressBar implementation that gets used instead of the actual one, to avoid having to put #[cfg] directives around every use and method call of ProgressBar +#[cfg(not(feature = "pbr"))] +use std::io::{Stdout, Write}; +#[cfg(not(feature = "pbr"))] +use std::marker::PhantomData; +#[cfg(not(feature = "pbr"))] +pub struct ProgressBar { + phantom: PhantomData, +} + +#[cfg(not(feature = "pbr"))] + +impl ProgressBar { + pub fn new(width: u64) -> Self { + ProgressBar { + phantom: PhantomData, + } + } +} +#[cfg(not(feature = "pbr"))] +impl ProgressBar { + pub fn on(write: T, total: u64) -> Self { + ProgressBar { + phantom: PhantomData, + } + } + pub fn add(&mut self, n: u64) {} + pub fn finish(&mut self) {} +} diff --git a/src/renderer/naive.rs b/src/renderer/naive.rs index d8ae699..f9ad36b 100644 --- a/src/renderer/naive.rs +++ b/src/renderer/naive.rs @@ -14,7 +14,6 @@ use std::time::{Duration, Instant}; use crossbeam::channel::unbounded; // use crossbeam::channel::{bounded}; -use pbr::ProgressBar; use rayon::iter::ParallelIterator; #[derive(Default)] diff --git a/src/renderer/preview.rs b/src/renderer/preview.rs index a0384e1..5328fc5 100644 --- a/src/renderer/preview.rs +++ b/src/renderer/preview.rs @@ -19,7 +19,6 @@ use std::time::{Duration, Instant}; use crossbeam::channel::unbounded; use math::spectral::BOUNDED_VISIBLE_RANGE; -use pbr::ProgressBar; #[cfg(feature = "preview")] use minifb::{Key, Scale, Window, WindowOptions}; diff --git a/src/renderer/tiled.rs b/src/renderer/tiled.rs index 990e83b..d6ae025 100644 --- a/src/renderer/tiled.rs +++ b/src/renderer/tiled.rs @@ -22,7 +22,6 @@ use std::time::{Duration, Instant}; // use crossbeam::channel::unbounded; // use crossbeam::channel::bounded; -use pbr::ProgressBar; use rayon::iter::ParallelIterator; #[derive(Default, Copy, Clone)] diff --git a/src/world/importance_map.rs b/src/world/importance_map.rs index 3f9445a..1eb7792 100644 --- a/src/world/importance_map.rs +++ b/src/world/importance_map.rs @@ -15,7 +15,6 @@ use crate::prelude::*; #[cfg(feature = "preview")] use minifb::{Scale, Window, WindowOptions}; -use pbr::ProgressBar; use rayon::iter::ParallelIterator; @@ -588,8 +587,8 @@ mod test { estimate2 += y_bar(sw.lambda * 10.0) * sw.energy / pdf_solid_angle_1 / wavelength_pdf; let (px, py) = ( - (uv.0 * width as f32) as usize, - (uv.1 * height as f32) as usize, + (uv.0 * width as f32).clamp(0.0, (width - 1) as f32) as usize, + (uv.1 * height as f32).clamp(0.0, (height - 1) as f32) as usize, ); // film.buffer[px + width * py] += XYZColor::from(sw) / (pdf.0 + 0.01) / wavelength_pdf; @@ -698,8 +697,8 @@ mod test { // sum += y_bar(sw.lambda * 10.0) * sw.energy; estimate += y_bar(sw.lambda * 10.0) * sw.energy / wavelength_pdf; let (px, py) = ( - (uv.0 * width as f32) as usize, - (uv.1 * height as f32) as usize, + (uv.0 * width as f32).clamp(0.0, (width - 1) as f32) as usize, + (uv.1 * height as f32).clamp(0.0, (height - 1) as f32) as usize, ); film.buffer[px + width * py] += XYZColor::from(sw) / wavelength_pdf / (*pdf + 0.01); }