Skip to content

Commit

Permalink
refactor pbr behind feature flag so that its messages don't pollute s…
Browse files Browse the repository at this point in the history
…tdout
  • Loading branch information
gillett-hernandez committed May 29, 2024
1 parent 6308507 commit e98dd00
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
33 changes: 33 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Write + Send + Sync> {
phantom: PhantomData<T>,
}

#[cfg(not(feature = "pbr"))]

impl ProgressBar<Stdout> {
pub fn new(width: u64) -> Self {
ProgressBar {
phantom: PhantomData,
}
}
}
#[cfg(not(feature = "pbr"))]
impl<T: Write + Send + Sync> ProgressBar<T> {
pub fn on(write: T, total: u64) -> Self {
ProgressBar {
phantom: PhantomData,
}
}
pub fn add(&mut self, n: u64) {}
pub fn finish(&mut self) {}
}
1 change: 0 additions & 1 deletion src/renderer/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion src/renderer/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 0 additions & 1 deletion src/renderer/tiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
9 changes: 4 additions & 5 deletions src/world/importance_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::prelude::*;

#[cfg(feature = "preview")]
use minifb::{Scale, Window, WindowOptions};
use pbr::ProgressBar;

use rayon::iter::ParallelIterator;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e98dd00

Please sign in to comment.