Skip to content

Commit

Permalink
make features better
Browse files Browse the repository at this point in the history
  • Loading branch information
float3 committed Apr 5, 2024
1 parent fab7462 commit 69c8257
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 22 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["small_rng", "oidn"]
default = ["oidn"]
small_rng = ["rand/small_rng"]
thread_rng = []
oidn = [
"dep:oidn",
"dep:flate2",
Expand Down
Binary file modified renders/checkered_floor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/cornell_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/mirror_ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/red_ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/scene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions src/material/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ fn random_unit_vector(rand_state: &mut RNGType) -> (Vec3<FloatSize>, FloatSize)
fn pdf() -> FloatSize {
1.0 / (4.0 * PI as FloatSize)
}
let theta: FloatSize = rand_state.gen_range(0.0..(2.0 * PI as FloatSize));
let phi_cos: FloatSize = rand_state.gen_range(-1.0..=1.0);
let phi_sin: FloatSize = (1.0 - phi_cos * phi_cos).sqrt();
let theta: FloatSize = rand_state.gen_range(0.0..(PI as FloatSize));
let phi: FloatSize = rand_state.gen_range(0.0..(2.0 * PI as FloatSize));
(
Vec3::new([phi_sin * theta.cos(), phi_cos, phi_sin * theta.sin()]),
Vec3::new([
theta.sin() * phi.cos(),
theta.sin() * phi.sin(),
theta.cos(),
]),
pdf(),
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/pathtracer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl PathTracer {

let sample_type = if debug {
if is_left {
SamplingFunctions::CosineWeightedSample1
SamplingFunctions::RandomUnitVector
} else {
SamplingFunctions::CosineWeightedSample2
}
Expand Down Expand Up @@ -95,8 +95,8 @@ fn denoise_image(width: usize, height: usize, buffer: &mut Vec<Vec3<FloatSize>>)
}

pub fn get_rng() -> RNGType {
#[cfg(feature = "thread_rng")]
#[cfg(not(feature = "small_rng"))]
return rand::thread_rng();
#[cfg(all(feature = "small_rng", not(feature = "thread_rng")))]
#[cfg(feature = "small_rng")]
return <rand::rngs::SmallRng as rand::SeedableRng>::from_entropy();
}
15 changes: 2 additions & 13 deletions src/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@ use crate::{
utils::vector::{Vec2, Vec3},
};

// #[cfg(all(feature = "small_rng", feature = "thread_rng"))]
// compile_error!(
// "feature \"small_rng\" and feature \"thread_rng\" cannot be enabled at the same time"
// );
// #[cfg(feature = "small_rng")]
// pub type RNGType = rand::rngs::SmallRng;
// #[cfg(feature = "thread_rng")]
// pub type RNGType = rand::rngs::ThreadRng;

pub type FloatSize = f64;
pub const PI: FloatSize = std::f64::consts::PI as FloatSize;

cfg_if! {
if #[cfg(feature="thread_rng")]{
pub type RNGType = rand::rngs::ThreadRng;
} else if #[cfg(feature="small_rng")] {
if #[cfg(feature="small_rng")] {
pub type RNGType = rand::rngs::SmallRng;
} else {
compile_error!("Either feature \"small_rng\" or feature \"thread_rng\" must be enabled");
pub type RNGType = rand::rngs::ThreadRng;
}
}

Expand Down
Binary file modified tests/sample_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 69c8257

Please sign in to comment.