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`]. Directions point
6/// **toward the light source** except for the spot cone axis, which points
7/// outward along the beam; see [`LightType`] for the full convention.
8///
9/// - For [`LightType::Directional`], `position` is unused and `direction` is
10/// the unit vector from the surface toward the light.
11/// - For [`LightType::Point`], `position` is the world position of the light
12/// and `direction` is unused.
13/// - For [`LightType::Spot`], `position` is the lamp position, `direction`
14/// is the cone axis pointing outward along the beam, and `spot_cos`
15/// carries `cos(half_angle)` of the cone.
16///
17/// A light is never mutated during shading:
18/// [`LightingUniforms::shade_with_visibility`] reads it and derives
19/// per-point quantities into locals.
20#[derive(Clone, Data, Debug, New, PartialEq)]
21pub struct Light {
22 /// The kind of light source (directional, point, or spot).
23 #[get(type(copy))]
24 #[get_mut(pub(crate))]
25 #[set(pub(crate))]
26 pub kind: LightType,
27 /// The world position of the light.
28 #[get(type(copy))]
29 #[get_mut(pub(crate))]
30 #[set(pub(crate))]
31 pub position: Vector3D,
32 /// Unit direction. Toward the light for [`LightType::Directional`];
33 /// the outward cone axis for [`LightType::Spot`]; unused for
34 /// [`LightType::Point`].
35 #[get(type(copy))]
36 #[get_mut(pub(crate))]
37 #[set(pub(crate))]
38 pub direction: Vector3D,
39 /// RGB intensity multiplier applied to the contribution.
40 #[get(pub(crate), type(copy))]
41 #[get_mut(pub(crate))]
42 #[set(pub(crate))]
43 pub(crate) color: Vector3D,
44 /// Overall intensity scalar in the range 0.0..=infinity.
45 #[get(type(copy))]
46 #[get_mut(pub(crate))]
47 #[set(pub(crate))]
48 pub intensity: f64,
49 /// Inverse-square falloff factor for point and spot lights.
50 ///
51 /// `pub` rather than `pub(crate)`: the getter is an out-of-crate
52 /// consumer's entry point (`tests/`, and the ray tracer's data stage),
53 /// and a narrowed field behind a public getter would silently
54 /// re-expose it.
55 #[get(type(copy))]
56 pub falloff: f64,
57 /// `cos(half_angle)` for spot lights; zero for other kinds.
58 #[get(type(copy))]
59 #[get_mut(pub(crate))]
60 #[set(pub(crate))]
61 pub spot_cos: f64,
62}
63
64/// A material describing how a surface responds to illumination.
65#[derive(Clone, Data, Debug, New, PartialEq)]
66pub struct Material {
67 /// The shading model applied during evaluation.
68 #[get(pub(crate), type(copy))]
69 #[get_mut(pub(crate))]
70 #[set(pub(crate))]
71 pub(crate) kind: MaterialKind,
72 /// The base reflectance color in the range 0.0..=1.0 per channel.
73 #[get(pub(crate), type(copy))]
74 #[get_mut(pub(crate))]
75 #[set(pub(crate))]
76 pub(crate) albedo: Vector3D,
77 /// Specular intensity multiplier in the range 0.0..=1.0.
78 #[get(pub(crate), type(copy))]
79 #[get_mut(pub(crate))]
80 #[set(pub(crate))]
81 pub(crate) specular: f64,
82 /// Phong specular exponent; larger values produce tighter highlights.
83 #[get(pub(crate), type(copy))]
84 #[get_mut(pub(crate))]
85 #[set(pub(crate))]
86 pub(crate) shininess: f64,
87 /// Self-illumination term used when a surface is also a light source
88 /// (e.g. an emissive sphere visible through ray tracing).
89 #[get(pub(crate), type(copy))]
90 #[get_mut(pub(crate))]
91 #[set(pub(crate))]
92 pub(crate) emissive: Vector3D,
93}
94
95/// Bundles of uniforms supplied to lighting and shading routines.
96#[derive(Clone, Data, Debug, New, PartialEq)]
97pub struct LightingUniforms {
98 /// All lights contributing to the scene.
99 #[get(pub(crate))]
100 #[get_mut(pub(crate))]
101 #[set(pub(crate))]
102 pub(crate) lights: Vec<Light>,
103 /// Ambient light contribution applied to every shaded point.
104 ///
105 /// The raytracing integration suites set the ambient term from outside
106 /// the crate, so the setter stays public; the getter and mut-getter have
107 /// no external consumer and stay crate-internal.
108 #[get(pub(crate), type(copy))]
109 #[get_mut(pub(crate))]
110 pub ambient: Vector3D,
111 /// View position used for specular term calculation.
112 #[get(pub(crate), type(copy))]
113 #[get_mut(pub(crate))]
114 #[set(pub(crate))]
115 pub(crate) eye: Vector3D,
116}