Add initial MIS implementation
This commit is contained in:
parent
ba2d853319
commit
d43d60bb85
10 changed files with 161 additions and 3 deletions
|
|
@ -83,11 +83,18 @@ impl<A: AccelerationStructure<u32>, R: Rng> Scene<R> for AccelerationStructureSc
|
|||
|
||||
let material = &self.materials[i as usize];
|
||||
|
||||
let light_pdf = if let Some(l) = &material.light {
|
||||
0.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
Some(Intersection::new(
|
||||
t,
|
||||
n,
|
||||
material.material.as_deref(),
|
||||
material.light.as_deref(),
|
||||
light_pdf,
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ impl<R: Rng> Scene<R> for BasicScene {
|
|||
((ray.start() + d * ray.dir()) - c).normalize(),
|
||||
Some(&DefaultMaterial {}),
|
||||
None,
|
||||
0.0,
|
||||
);
|
||||
if d >= min && d <= max {
|
||||
if let Some(i) = intersection.as_ref() {
|
||||
|
|
|
|||
|
|
@ -329,13 +329,16 @@ impl<R: Rng> Scene<R> for TriangleBVH<R> {
|
|||
let triangle = self.triangles[i as usize];
|
||||
let material = &self.materials[triangle.material as usize];
|
||||
|
||||
let n = triangle_normal(self.get_vertices_from_index(i)).normalize();
|
||||
let n = triangle_normal(self.get_vertices_from_index(i));
|
||||
|
||||
let area = n.length() * 0.5;
|
||||
|
||||
Some(Intersection::new(
|
||||
t,
|
||||
n,
|
||||
n.normalize(),
|
||||
material.material.as_deref(),
|
||||
material.light.as_deref(),
|
||||
1.0 / ((self.lights.len() as Float) * area),
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue