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(
|
||||
[info.material.sample(&(world_to_bsdf_space * info.retro))]
|
||||
.iter()
|
||||
.map(|direction| {
|
||||
let world_space_direction = bsdf_to_world_space * direction;
|
||||
match sampler.sample(
|
||||
&Ray::new(info.location, world_space_direction).bias(0.000_000_1),
|
||||
) {
|
||||
Some(recursive_hit) => {
|
||||
if recursion_limit > 0 {
|
||||
let photon = info.material.bsdf()(
|
||||
&(world_to_bsdf_space * info.retro),
|
||||
direction,
|
||||
&self.integrate(
|
||||
&sampler,
|
||||
&recursive_hit,
|
||||
&photon,
|
||||
recursion_limit - 1,
|
||||
),
|
||||
);
|
||||
photon.scale_intensity(
|
||||
world_space_direction.dot(&info.normal).abs(),
|
||||
)
|
||||
} else {
|
||||
photon.scale_intensity(0.0)
|
||||
}
|
||||
[info
|
||||
.material
|
||||
.sample(&(world_to_bsdf_space * info.retro), &photon)]
|
||||
.iter()
|
||||
.map(|direction| {
|
||||
let world_space_direction = bsdf_to_world_space * direction;
|
||||
match sampler
|
||||
.sample(&Ray::new(info.location, world_space_direction).bias(0.000_000_1))
|
||||
{
|
||||
Some(recursive_hit) => {
|
||||
if recursion_limit > 0 {
|
||||
let photon = info.material.bsdf()(
|
||||
&(world_to_bsdf_space * info.retro),
|
||||
direction,
|
||||
&self.integrate(
|
||||
&sampler,
|
||||
&recursive_hit,
|
||||
&photon,
|
||||
recursion_limit - 1,
|
||||
),
|
||||
);
|
||||
photon
|
||||
.scale_intensity(world_space_direction.dot(&info.normal).abs())
|
||||
} else {
|
||||
photon.scale_intensity(0.0)
|
||||
}
|
||||
None => photon.scale_intensity(0.0),
|
||||
}
|
||||
}),
|
||||
None => photon.scale_intensity(0.0),
|
||||
}
|
||||
}),
|
||||
)
|
||||
.fold(photon.clone(), |a, b| {
|
||||
let mut result = a;
|
||||
|
|
@ -115,18 +116,23 @@ impl Integrator for SimpleRandomIntegrator {
|
|||
let bsdf_to_world_space = world_to_bsdf_space
|
||||
.try_inverse()
|
||||
.expect("Expected matrix to be invertable.");
|
||||
let w_i = info.material.sample(&(world_to_bsdf_space * info.retro));
|
||||
let world_space_w_i = bsdf_to_world_space * w_i;
|
||||
let world_space_w_i = info.retro;
|
||||
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()(
|
||||
&(world_to_bsdf_space * info.retro),
|
||||
&w_i,
|
||||
&match sampler.sample(&Ray::new(info.location, world_space_w_i).bias(0.000_000_1)) {
|
||||
None => photon.set_intensity(world_space_w_i.y()),
|
||||
&w_o.normalize(),
|
||||
&w_i.normalize(),
|
||||
&match sampler.sample(&Ray::new(info.location, world_space_w_o).bias(0.000_000_1)) {
|
||||
None => photon.set_intensity(test_lighting_environment(
|
||||
&world_space_w_o,
|
||||
photon.wavelength,
|
||||
)),
|
||||
Some(recursive_hit) => {
|
||||
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 {
|
||||
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 w_o = Vec3::new(
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue