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 e37934b
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: render
run: |
export LD_LIBRARY_PATH=./oidn/oidn/lib:$LD_LIBRARY_PATH
cargo run --release -F thread_rng -F oidn --no-default-features -- --multiplier=4 --all
cargo test --release -F thread_rng -F oidn --no-default-features --all-targets --all
cargo run --release -F oidn -- --multiplier=4 --all
cargo test --release -F oidn --all-targets --all
- name: commit
run: |
Expand Down
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 e37934b

Please sign in to comment.