Skip to content

Commit e37934b

Browse files
committed
make features better
1 parent fab7462 commit e37934b

File tree

11 files changed

+15
-24
lines changed

11 files changed

+15
-24
lines changed

.github/workflows/CI.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
- name: render
3030
run: |
3131
export LD_LIBRARY_PATH=./oidn/oidn/lib:$LD_LIBRARY_PATH
32-
cargo run --release -F thread_rng -F oidn --no-default-features -- --multiplier=4 --all
33-
cargo test --release -F thread_rng -F oidn --no-default-features --all-targets --all
32+
cargo run --release -F oidn -- --multiplier=4 --all
33+
cargo test --release -F oidn --all-targets --all
3434
3535
- name: commit
3636
run: |

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
default = ["small_rng", "oidn"]
7+
default = ["oidn"]
88
small_rng = ["rand/small_rng"]
9-
thread_rng = []
109
oidn = [
1110
"dep:oidn",
1211
"dep:flate2",

renders/checkered_floor.png

-45 KB
Loading

renders/cornell_box.png

40.9 KB
Loading

renders/mirror_ball.png

10.2 KB
Loading

renders/red_ball.png

432 KB
Loading

renders/scene.png

175 KB
Loading

src/material/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ fn random_unit_vector(rand_state: &mut RNGType) -> (Vec3<FloatSize>, FloatSize)
3535
fn pdf() -> FloatSize {
3636
1.0 / (4.0 * PI as FloatSize)
3737
}
38-
let theta: FloatSize = rand_state.gen_range(0.0..(2.0 * PI as FloatSize));
39-
let phi_cos: FloatSize = rand_state.gen_range(-1.0..=1.0);
40-
let phi_sin: FloatSize = (1.0 - phi_cos * phi_cos).sqrt();
38+
let theta: FloatSize = rand_state.gen_range(0.0..(PI as FloatSize));
39+
let phi: FloatSize = rand_state.gen_range(0.0..(2.0 * PI as FloatSize));
4140
(
42-
Vec3::new([phi_sin * theta.cos(), phi_cos, phi_sin * theta.sin()]),
41+
Vec3::new([
42+
theta.sin() * phi.cos(),
43+
theta.sin() * phi.sin(),
44+
theta.cos(),
45+
]),
4346
pdf(),
4447
)
4548
}

src/pathtracer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl PathTracer {
4444

4545
let sample_type = if debug {
4646
if is_left {
47-
SamplingFunctions::CosineWeightedSample1
47+
SamplingFunctions::RandomUnitVector
4848
} else {
4949
SamplingFunctions::CosineWeightedSample2
5050
}
@@ -95,8 +95,8 @@ fn denoise_image(width: usize, height: usize, buffer: &mut Vec<Vec3<FloatSize>>)
9595
}
9696

9797
pub fn get_rng() -> RNGType {
98-
#[cfg(feature = "thread_rng")]
98+
#[cfg(not(feature = "small_rng"))]
9999
return rand::thread_rng();
100-
#[cfg(all(feature = "small_rng", not(feature = "thread_rng")))]
100+
#[cfg(feature = "small_rng")]
101101
return <rand::rngs::SmallRng as rand::SeedableRng>::from_entropy();
102102
}

src/scene/mod.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,14 @@ use crate::{
1212
utils::vector::{Vec2, Vec3},
1313
};
1414

15-
// #[cfg(all(feature = "small_rng", feature = "thread_rng"))]
16-
// compile_error!(
17-
// "feature \"small_rng\" and feature \"thread_rng\" cannot be enabled at the same time"
18-
// );
19-
// #[cfg(feature = "small_rng")]
20-
// pub type RNGType = rand::rngs::SmallRng;
21-
// #[cfg(feature = "thread_rng")]
22-
// pub type RNGType = rand::rngs::ThreadRng;
23-
2415
pub type FloatSize = f64;
2516
pub const PI: FloatSize = std::f64::consts::PI as FloatSize;
2617

2718
cfg_if! {
28-
if #[cfg(feature="thread_rng")]{
29-
pub type RNGType = rand::rngs::ThreadRng;
30-
} else if #[cfg(feature="small_rng")] {
19+
if #[cfg(feature="small_rng")] {
3120
pub type RNGType = rand::rngs::SmallRng;
3221
} else {
33-
compile_error!("Either feature \"small_rng\" or feature \"thread_rng\" must be enabled");
22+
pub type RNGType = rand::rngs::ThreadRng;
3423
}
3524
}
3625

tests/sample_test.png

98.9 KB
Loading

0 commit comments

Comments
 (0)