Add photon parameter to Material::sample(), other changes to integrate()
This commit is contained in:
parent
438d8c64ee
commit
87f62eedb0
|
|
@ -55,35 +55,36 @@ impl Integrator for WhittedIntegrator {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.chain(
|
.chain(
|
||||||
[info.material.sample(&(world_to_bsdf_space * info.retro))]
|
[info
|
||||||
.iter()
|
.material
|
||||||
.map(|direction| {
|
.sample(&(world_to_bsdf_space * info.retro), &photon)]
|
||||||
let world_space_direction = bsdf_to_world_space * direction;
|
.iter()
|
||||||
match sampler.sample(
|
.map(|direction| {
|
||||||
&Ray::new(info.location, world_space_direction).bias(0.000_000_1),
|
let world_space_direction = bsdf_to_world_space * direction;
|
||||||
) {
|
match sampler
|
||||||
Some(recursive_hit) => {
|
.sample(&Ray::new(info.location, world_space_direction).bias(0.000_000_1))
|
||||||
if recursion_limit > 0 {
|
{
|
||||||
let photon = info.material.bsdf()(
|
Some(recursive_hit) => {
|
||||||
&(world_to_bsdf_space * info.retro),
|
if recursion_limit > 0 {
|
||||||
direction,
|
let photon = info.material.bsdf()(
|
||||||
&self.integrate(
|
&(world_to_bsdf_space * info.retro),
|
||||||
&sampler,
|
direction,
|
||||||
&recursive_hit,
|
&self.integrate(
|
||||||
&photon,
|
&sampler,
|
||||||
recursion_limit - 1,
|
&recursive_hit,
|
||||||
),
|
&photon,
|
||||||
);
|
recursion_limit - 1,
|
||||||
photon.scale_intensity(
|
),
|
||||||
world_space_direction.dot(&info.normal).abs(),
|
);
|
||||||
)
|
photon
|
||||||
} else {
|
.scale_intensity(world_space_direction.dot(&info.normal).abs())
|
||||||
photon.scale_intensity(0.0)
|
} else {
|
||||||
}
|
photon.scale_intensity(0.0)
|
||||||
}
|
}
|
||||||
None => photon.scale_intensity(0.0),
|
|
||||||
}
|
}
|
||||||
}),
|
None => photon.scale_intensity(0.0),
|
||||||
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.fold(photon.clone(), |a, b| {
|
.fold(photon.clone(), |a, b| {
|
||||||
let mut result = a;
|
let mut result = a;
|
||||||
|
|
@ -115,18 +116,23 @@ impl Integrator for SimpleRandomIntegrator {
|
||||||
let bsdf_to_world_space = world_to_bsdf_space
|
let bsdf_to_world_space = world_to_bsdf_space
|
||||||
.try_inverse()
|
.try_inverse()
|
||||||
.expect("Expected matrix to be invertable.");
|
.expect("Expected matrix to be invertable.");
|
||||||
let w_i = info.material.sample(&(world_to_bsdf_space * info.retro));
|
let world_space_w_i = info.retro;
|
||||||
let world_space_w_i = bsdf_to_world_space * w_i;
|
let w_i = world_to_bsdf_space * world_space_w_i;
|
||||||
|
let w_o = info.material.sample(&w_i, &photon);
|
||||||
|
let world_space_w_o = bsdf_to_world_space * w_o;
|
||||||
info.material.bsdf()(
|
info.material.bsdf()(
|
||||||
&(world_to_bsdf_space * info.retro),
|
&w_o.normalize(),
|
||||||
&w_i,
|
&w_i.normalize(),
|
||||||
&match sampler.sample(&Ray::new(info.location, world_space_w_i).bias(0.000_000_1)) {
|
&match sampler.sample(&Ray::new(info.location, world_space_w_o).bias(0.000_000_1)) {
|
||||||
None => photon.set_intensity(world_space_w_i.y()),
|
None => photon.set_intensity(test_lighting_environment(
|
||||||
|
&world_space_w_o,
|
||||||
|
photon.wavelength,
|
||||||
|
)),
|
||||||
Some(recursive_hit) => {
|
Some(recursive_hit) => {
|
||||||
self.integrate(&sampler, &recursive_hit, &photon, recursion_limit - 1)
|
self.integrate(&sampler, &recursive_hit, &photon, recursion_limit - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.scale_intensity(world_space_w_i.dot(&info.normal).abs()),
|
.scale_intensity(world_space_w_o.dot(&info.normal).abs()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ pub use reflective_material::ReflectiveMaterial;
|
||||||
pub trait Material: Debug + Sync + Send {
|
pub trait Material: Debug + Sync + Send {
|
||||||
fn bsdf<'a>(&'a self) -> Box<dyn Fn(&Vec3, &Vec3, &Photon) -> Photon + 'a>;
|
fn bsdf<'a>(&'a self) -> Box<dyn Fn(&Vec3, &Vec3, &Photon) -> Photon + 'a>;
|
||||||
|
|
||||||
fn sample(&self, _w_i: &Vec3) -> Vec3 {
|
fn sample(&self, _w_i: &Vec3, _photon: &Photon) -> Vec3 {
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
let mut w_o = Vec3::new(
|
let mut w_o = Vec3::new(
|
||||||
2.0 * rng.sample::<f64, _>(Open01) - 1.0,
|
2.0 * rng.sample::<f64, _>(Open01) - 1.0,
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ impl Material for ReflectiveMaterial {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sample(&self, w_o: &Vec3) -> Vec3 {
|
fn sample(&self, w_o: &Vec3, _photon: &Photon) -> Vec3 {
|
||||||
Vec3::new(-w_o.x(), -w_o.y(), w_o.z())
|
Vec3::new(-w_o.x(), -w_o.y(), w_o.z())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue