pub struct LightingUniforms {
pub ambient: Vector3D,
/* private fields */
}Expand description
Bundles of uniforms supplied to lighting and shading routines.
Fields§
§ambient: Vector3DAmbient light contribution applied to every shaded point.
The raytracing integration suites set the ambient term from outside the crate, so the setter stays public; the getter and mut-getter have no external consumer and stay crate-internal.
Implementations§
Source§impl LightingUniforms
Implements LightingUniforms builders and the shading entry points
used by the ray tracer and by any external visibility provider.
impl LightingUniforms
Implements LightingUniforms builders and the shading entry points
used by the ray tracer and by any external visibility provider.
Sourcepub fn with_eye(eye: Vector3D) -> LightingUniforms
pub fn with_eye(eye: Vector3D) -> LightingUniforms
Sourcepub fn shade(
&self,
position: Vector3D,
normal: Vector3D,
material: &Material,
occluders: &[(Vector3D, f64)],
) -> Vector3D
pub fn shade( &self, position: Vector3D, normal: Vector3D, material: &Material, occluders: &[(Vector3D, f64)], ) -> Vector3D
Shades a surface point against (center, radius) shadow bounding
spheres, the pre-existing entry point.
A compatibility shim over
LightingUniforms::shade_with_visibility that supplies a callback
backed by soft_shadow_factor, retained so existing ray-tracing
callers keep compiling unchanged. New code holding real geometry
should call LightingUniforms::shade_with_visibility directly and
get exact shadows instead of bounding-sphere ones.
Directional lights report full visibility here, unchanged from
before: a bounding sphere stores a position but no direction, so
there is no finite segment to cast along and a callback using one
would have to invent a far bound. That far bound is
[LIGHTING_DIRECTIONAL_VISIBILITY_DISTANCE] and belongs to
LightingUniforms::shade_with_visibility, where the caller
supplies its own geometry.
§Arguments
Vector3D- The world-space position of the shaded point.Vector3D- The surface normal (unit length).&Material- The material at the shaded point.&[(Vector3D, f64)]-(center, radius)occluder bounding spheres, one per occluder.
§Returns
Vector3D- The final shaded color.
Sourcepub fn shade_with_visibility<F>(
&self,
position: Vector3D,
normal: Vector3D,
material: &Material,
visibility: F,
) -> Vector3D
pub fn shade_with_visibility<F>( &self, position: Vector3D, normal: Vector3D, material: &Material, visibility: F, ) -> Vector3D
Shades a surface point, asking visibility whether each light is
unoccluded along the segment to that light.
The entry point for real shadow geometry. The callback receives the
light, the unit direction from the shaded point toward the light,
and the maximum distance to cast along that direction, and returns a
visibility factor that multiplies the light’s whole contribution.
Returning 1.0 for every light reproduces the unshadowed result
exactly.
§The callback contract
F: FnMut(&Light, surface_to_light_dir: Vector3D, max_distance: f64) -> f64surface_to_light_diris the normalized direction frompositiontoward the light. For a spot light this points into the lamp (it is the negation of the cone axis), matching the shading convention used for every other term — cast your shadow ray along this vector and it runs surface→light.max_distanceis the far bound for that ray: the true surface→light distance for point and spot lights, so the ray can never reach past the lamp, and [LIGHTING_DIRECTIONAL_VISIBILITY_DISTANCE] (1000.0, matching the ray tracer’sRAYTRACE_DEFAULT_T_MAX) for directional lights, which have no distance of their own.- The returned factor is clamped to
0.0..=1.0.
§When the callback runs
At most once per light, and only for lights that can actually
contribute. Lights are skipped before any callback work when they
carry no intensity, fall outside their spot cone, or face away from
the surface (dot(normal, light_dir) <= 0). Those tests are free,
and skipping them is the point of the ordering: back-facing and
out-of-cone lights are the common reject path. A light that is fully
occluded still costs one callback — only the callback knows the
geometry.
§Evaluation order
Per light: cone test → facing test → compute light_dir, dist,
and view_dir once → visibility callback → falloff →
MaterialKind dispatch. The Light itself is only read, never
cloned: a point or spot light’s derived direction and attenuating
intensity live in locals for the duration of the iteration, so the
diffuse, specular, and fresnel terms all read the same values.
MaterialKind selects which terms run per light:
MaterialKind::Lambert contributes diffuse only,
MaterialKind::Phong adds a Phong specular lobe that is zero
unless the surface faces the light, and MaterialKind::Pbr
scales the diffuse term by a Schlick fresnel factor and adds no
separate specular lobe.
Ambient is added once and is never shadowed; the material’s emissive term is added last and is likewise unaffected by visibility.
§Arguments
Vector3D- The world-space position of the shaded point.Vector3D- The surface normal (unit length).&Material- The material at the shaded point.F- The visibility provider, called once per contributing light.
§Returns
Vector3D- The final shaded color.