Skip to main content

pbrt_r3/core/light/
light.rs

1use super::area_light::AreaLight;
2use super::visibility_tester::VisibilityTester;
3use crate::core::base::*;
4use crate::core::geometry::*;
5use crate::core::interaction::*;
6use crate::core::scene::*;
7use crate::core::spectrum::*;
8
9pub enum LightFlags {
10    DeltaPosition = 1,
11    DeltaDirection = 2,
12    Area = 4,
13    Infinite = 8,
14}
15/*
16pub type LightFlags = u32;
17pub const LIGHT_DELTA_POSITION:LightFlags = 1;
18pub const LIGHT_DELTA_DIRECTION:LightFlags = 2;
19pub const LIGHT_AREA:LightFlags = 4;
20pub const LIGHT_INFINITE:LightFlags = 8;
21*/
22
23pub trait Light: Sync + Send {
24    fn sample_li(
25        &self,
26        inter: &Interaction,
27        u: &Point2f,
28    ) -> Option<(Spectrum, Vector3f, Float, VisibilityTester)>;
29    fn power(&self) -> Spectrum {
30        return Spectrum::zero();
31    }
32    fn preprocess(&self, _scene: &Scene) {}
33    fn le(&self, _r: &RayDifferential) -> Spectrum {
34        return Spectrum::zero();
35    }
36    fn sample_le(
37        &self,
38        _u1: &Point2f,
39        _u2: &Point2f,
40        _time: Float,
41    ) -> Option<(Spectrum, Ray, Normal3f, Float, Float)> {
42        return None;
43    }
44    fn pdf_li(&self, _inter: &Interaction, _wi: &Vector3f) -> Float {
45        return 0.0;
46    }
47    fn pdf_le(&self, _ray: &Ray, _n_light: &Normal3f) -> Option<(Float, Float)> {
48        return None;
49    }
50
51    fn is_infinite(&self) -> bool {
52        let flags = self.get_light_flags();
53        return (flags & LightFlags::Infinite as u32) != 0;
54    }
55    //---------------------------------
56    fn is_delta(&self) -> bool {
57        let flags = self.get_light_flags();
58        return ((flags & LightFlags::DeltaPosition as u32) != 0)
59            || ((flags & LightFlags::DeltaDirection as u32) != 0);
60    }
61
62    fn is_delta_direction(&self) -> bool {
63        let flags = self.get_light_flags();
64        return (flags & LightFlags::DeltaDirection as u32) != 0;
65    }
66
67    fn is_area(&self) -> bool {
68        let flags = self.get_light_flags();
69        return (flags & LightFlags::Area as u32) != 0;
70    }
71
72    fn get_light_flags(&self) -> u32 {
73        return 0;
74    }
75
76    fn get_sample_count(&self) -> u32 {
77        return 1;
78    }
79
80    fn as_area_light(&self) -> Option<&dyn AreaLight> {
81        return None;
82    }
83}