Make default material sampling cosine-weighted instead of uniform
This commit is contained in:
parent
b0c704f79a
commit
1f84cde760
|
|
@ -1,10 +1,8 @@
|
|||
use crate::math::Vec3;
|
||||
|
||||
use super::colour::Photon;
|
||||
use super::random_distributions::{CosineWeightedHemisphere, RandomDistribution};
|
||||
|
||||
use rand::distributions::{Open01, OpenClosed01};
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::f64::consts::PI;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub mod lambertian_material;
|
||||
|
|
@ -28,22 +26,9 @@ pub trait Material: Debug + Sync + Send {
|
|||
fn bsdf<'a>(&'a self) -> Box<dyn Fn(&Vec3, &Vec3, &Photon) -> Photon + 'a>;
|
||||
|
||||
fn sample(&self, _w_i: &Vec3, _photon: &Photon) -> MaterialSampleResult {
|
||||
let mut rng = thread_rng();
|
||||
let mut w_o = Vec3::new(
|
||||
2.0 * rng.sample::<f64, _>(Open01) - 1.0,
|
||||
2.0 * rng.sample::<f64, _>(Open01) - 1.0,
|
||||
rng.sample::<f64, _>(OpenClosed01),
|
||||
);
|
||||
while w_o.norm_squared() > 1.0 {
|
||||
w_o = Vec3::new(
|
||||
2.0 * rng.sample::<f64, _>(Open01) - 1.0,
|
||||
2.0 * rng.sample::<f64, _>(Open01) - 1.0,
|
||||
rng.sample::<f64, _>(OpenClosed01),
|
||||
);
|
||||
}
|
||||
MaterialSampleResult {
|
||||
direction: w_o.normalize(),
|
||||
pdf: 1.0 / (2.0 * PI),
|
||||
}
|
||||
let distribution = CosineWeightedHemisphere::new();
|
||||
let direction = distribution.value();
|
||||
let pdf = distribution.pdf(direction);
|
||||
MaterialSampleResult { direction, pdf }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue