Skip to main content

LightingUniforms

Struct LightingUniforms 

Source
pub struct LightingUniforms {
    pub ambient: Vector3D,
    /* private fields */
}
Expand description

Bundles of uniforms supplied to lighting and shading routines.

Fields§

§ambient: Vector3D

Ambient 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.

Source

pub fn with_eye(eye: Vector3D) -> LightingUniforms

Creates a uniform set with an empty light list, default ambient, and the supplied eye position.

§Arguments
  • Vector3D - The view position used for specular calculations.
§Returns
  • LightingUniforms - The new uniform set.
Source

pub fn add_light(&mut self, light: Light)

Adds a light to the uniform set.

§Arguments
  • Light - The light to append.
Source

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.
Source

pub fn shade_with_visibility<F>( &self, position: Vector3D, normal: Vector3D, material: &Material, visibility: F, ) -> Vector3D
where F: FnMut(&Light, Vector3D, f64) -> f64,

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) -> f64
  • surface_to_light_dir is the normalized direction from position toward 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_distance is 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’s RAYTRACE_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.
Source§

impl LightingUniforms

Source

pub fn set_ambient(&mut self, val: Vector3D) -> &mut Self

Source§

impl LightingUniforms

Source

pub fn new(lights: Vec<Light>, ambient: Vector3D, eye: Vector3D) -> Self

Trait Implementations§

Source§

impl Clone for LightingUniforms

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LightingUniforms

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for LightingUniforms

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LightingUniforms

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more