Skip to main content

euv_engine/lighting/
struct.rs

1use super::*;
2
3/// A light source contributing illumination to a shaded point.
4///
5/// The fields have meanings that depend on [`LightType`]:
6///
7/// - For [`LightType::Directional`], `position` is unused and `direction` is
8///   the unit vector pointing from the surface toward the light.
9/// - For [`LightType::Point`], `position` is the world position of the light
10///   and `direction` is unused.
11/// - For [`LightType::Spot`], both `position` and `direction` are meaningful
12///   and `spot_cos` carries `cos(half_angle)` of the spotlight cone.
13#[derive(Clone, Data, Debug, New, PartialEq)]
14pub struct Light {
15    /// The kind of light source (directional, point, or spot).
16    #[get(type(copy))]
17    #[get_mut(pub(crate))]
18    #[set(pub(crate))]
19    pub(crate) kind: LightType,
20    /// World-space position for point and spot lights; otherwise unused.
21    #[get(type(copy))]
22    #[get_mut(pub(crate))]
23    #[set(pub(crate))]
24    pub(crate) position: Vector3D,
25    /// Unit direction for directional and spot lights; otherwise unused.
26    #[get(type(copy))]
27    #[get_mut(pub(crate))]
28    pub(crate) direction: Vector3D,
29    /// RGB intensity multiplier applied to the contribution.
30    #[get(pub(crate), type(copy))]
31    #[get_mut(pub(crate))]
32    #[set(pub(crate))]
33    pub(crate) color: Vector3D,
34    /// Overall intensity scalar in the range 0.0..=infinity.
35    #[get(type(copy))]
36    #[get_mut(pub(crate))]
37    #[set(pub(crate))]
38    pub(crate) intensity: f64,
39    /// Inverse-square falloff factor for point and spot lights.
40    #[get(type(copy))]
41    pub(crate) falloff: f64,
42    /// `cos(half_angle)` for spot lights; zero for other kinds.
43    #[get(type(copy))]
44    #[get_mut(pub(crate))]
45    #[set(pub(crate))]
46    pub(crate) spot_cos: f64,
47}
48
49/// A material describing how a surface responds to illumination.
50#[derive(Clone, Data, Debug, New, PartialEq)]
51pub struct Material {
52    /// The shading model applied during evaluation.
53    #[get(type(copy))]
54    #[get_mut(pub(crate))]
55    #[set(pub(crate))]
56    pub(crate) kind: MaterialKind,
57    /// The base reflectance color in the range 0.0..=1.0 per channel.
58    #[get(pub(crate), type(copy))]
59    #[get_mut(pub(crate))]
60    #[set(pub(crate))]
61    pub(crate) albedo: Vector3D,
62    /// Specular intensity multiplier in the range 0.0..=1.0.
63    #[get(pub(crate), type(copy))]
64    #[get_mut(pub(crate))]
65    #[set(pub(crate))]
66    pub(crate) specular: f64,
67    /// Phong specular exponent; larger values produce tighter highlights.
68    #[get(pub(crate), type(copy))]
69    #[get_mut(pub(crate))]
70    #[set(pub(crate))]
71    pub(crate) shininess: f64,
72    /// Self-illumination term used when a surface is also a light source
73    /// (e.g. an emissive sphere visible through ray tracing).
74    #[get(pub(crate), type(copy))]
75    #[get_mut(pub(crate))]
76    #[set(pub(crate))]
77    pub(crate) emissive: Vector3D,
78}
79
80/// Bundles of uniforms supplied to lighting and shading routines.
81#[derive(Clone, Data, Debug, New, PartialEq)]
82pub struct LightingUniforms {
83    /// All lights contributing to the scene.
84    #[get(pub(crate))]
85    #[get_mut(pub(crate))]
86    #[set(pub(crate))]
87    pub(crate) lights: Vec<Light>,
88    /// Ambient light contribution applied to every shaded point.
89    #[get(pub(crate), type(copy))]
90    #[get_mut(pub(crate))]
91    pub(crate) ambient: Vector3D,
92    /// View position used for specular term calculation.
93    #[get(pub(crate), type(copy))]
94    #[get_mut(pub(crate))]
95    #[set(pub(crate))]
96    pub(crate) eye: Vector3D,
97}