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    pub(crate) kind: LightType,
18    /// World-space position for point and spot lights; otherwise unused.
19    #[get(type(copy))]
20    pub(crate) position: Vector3D,
21    /// Unit direction for directional and spot lights; otherwise unused.
22    #[get(type(copy))]
23    pub(crate) direction: Vector3D,
24    /// RGB intensity multiplier applied to the contribution.
25    #[get(type(copy))]
26    pub(crate) color: Vector3D,
27    /// Overall intensity scalar in the range 0.0..=infinity.
28    #[get(type(copy))]
29    pub(crate) intensity: f64,
30    /// Inverse-square falloff factor for point and spot lights.
31    #[get(type(copy))]
32    pub(crate) falloff: f64,
33    /// `cos(half_angle)` for spot lights; zero for other kinds.
34    #[get(type(copy))]
35    pub(crate) spot_cos: f64,
36}
37
38/// A material describing how a surface responds to illumination.
39#[derive(Clone, Data, Debug, New, PartialEq)]
40pub struct Material {
41    /// The shading model applied during evaluation.
42    #[get(type(copy))]
43    pub(crate) kind: MaterialKind,
44    /// The base reflectance color in the range 0.0..=1.0 per channel.
45    #[get(type(copy))]
46    pub(crate) albedo: Vector3D,
47    /// Specular intensity multiplier in the range 0.0..=1.0.
48    #[get(type(copy))]
49    pub(crate) specular: f64,
50    /// Phong specular exponent; larger values produce tighter highlights.
51    #[get(type(copy))]
52    pub(crate) shininess: f64,
53    /// Self-illumination term used when a surface is also a light source
54    /// (e.g. an emissive sphere visible through ray tracing).
55    #[get(type(copy))]
56    pub(crate) emissive: Vector3D,
57}
58
59/// Bundles of uniforms supplied to lighting and shading routines.
60#[derive(Clone, Data, Debug, New, PartialEq)]
61pub struct LightingUniforms {
62    /// All lights contributing to the scene.
63    #[get(pub(crate), type(clone))]
64    pub(crate) lights: Vec<Light>,
65    /// Ambient light contribution applied to every shaded point.
66    #[get(type(copy))]
67    pub(crate) ambient: Vector3D,
68    /// View position used for specular term calculation.
69    #[get(type(copy))]
70    pub(crate) eye: Vector3D,
71}