pbrt_r3/core/light/
visibility_tester.rs1use crate::core::interaction::*;
2use crate::core::sampler::*;
3use crate::core::scene::*;
4use crate::core::spectrum::*;
5
6#[derive(Clone)]
7pub struct VisibilityTester {
8 pub p0: Interaction,
9 pub p1: Interaction,
10}
11
12impl VisibilityTester {
13 pub fn new() -> Self {
14 VisibilityTester {
15 p0: Interaction::default(),
16 p1: Interaction::default(),
17 }
18 }
19
20 pub fn unoccluded(&self, scene: &Scene) -> bool {
21 return !scene.intersect_p(&self.p0.spawn_ray_to(&self.p1));
22 }
23
24 pub fn tr(&self, scene: &Scene, sampler: &mut dyn Sampler) -> Spectrum {
25 let mut ray = self.p0.spawn_ray_to(&self.p1);
26 let mut tr = Spectrum::one();
33 loop {
34 if let Some(isect) = scene.intersect(&ray) {
36 if let Some(primitive) = isect.get_primitive() {
37 if primitive.get_material().is_some() {
38 return Spectrum::zero();
42 }
44 }
45
46 if let Some(medium) = ray.medium.as_ref() {
47 tr *= medium.as_ref().tr(&ray, sampler);
48 }
49
50 let tisect = Interaction::from(isect);
51 ray = tisect.spawn_ray_to(&self.p1);
52 } else {
53 if let Some(medium) = ray.medium.as_ref() {
54 tr *= medium.as_ref().tr(&ray, sampler);
55 }
56 break;
57 }
58 }
59 return tr;
60 }
61}
62
63impl From<(&Interaction, &Interaction)> for VisibilityTester {
64 fn from(value: (&Interaction, &Interaction)) -> Self {
65 VisibilityTester {
66 p0: value.0.clone(),
67 p1: value.1.clone(),
68 }
69 }
70}
71
72impl From<(Interaction, Interaction)> for VisibilityTester {
73 fn from(value: (Interaction, Interaction)) -> Self {
74 VisibilityTester {
75 p0: value.0,
76 p1: value.1,
77 }
78 }
79}