pub struct Light {
pub kind: LightType,
pub position: Vector3D,
pub direction: Vector3D,
pub intensity: f64,
pub falloff: f64,
pub spot_cos: f64,
/* private fields */
}Expand description
A light source contributing illumination to a shaded point.
The fields have meanings that depend on LightType. Directions point
toward the light source except for the spot cone axis, which points
outward along the beam; see LightType for the full convention.
- For
LightType::Directional,positionis unused anddirectionis the unit vector from the surface toward the light. - For
LightType::Point,positionis the world position of the light anddirectionis unused. - For
LightType::Spot,positionis the lamp position,directionis the cone axis pointing outward along the beam, andspot_coscarriescos(half_angle)of the cone.
A light is never mutated during shading:
LightingUniforms::shade_with_visibility reads it and derives
per-point quantities into locals.
Fields§
§kind: LightTypeThe kind of light source (directional, point, or spot).
position: Vector3DThe world position of the light.
direction: Vector3DUnit direction. Toward the light for LightType::Directional;
the outward cone axis for LightType::Spot; unused for
LightType::Point.
intensity: f64Overall intensity scalar in the range 0.0..=infinity.
falloff: f64Inverse-square falloff factor for point and spot lights.
pub rather than pub(crate): the getter is an out-of-crate
consumer’s entry point (tests/, and the ray tracer’s data stage),
and a narrowed field behind a public getter would silently
re-expose it.
spot_cos: f64cos(half_angle) for spot lights; zero for other kinds.
Implementations§
Source§impl Light
Implements factory constructors and shading for Light, Material,
and LightingUniforms.
impl Light
Implements factory constructors and shading for Light, Material,
and LightingUniforms.
Sourcepub fn new_directional(direction: Vector3D, color: Vector3D) -> Light
pub fn new_directional(direction: Vector3D, color: Vector3D) -> Light
Creates a new directional light pointing in direction with color.
The direction is normalized internally; intensity defaults to 1.0.
Falloff and spot half-angle are unused for directional lights.
§Arguments
Vector3D- The unit direction toward the light source.Vector3D- The RGB intensity multiplier.
§Returns
Light- The new directional light.
Sourcepub fn new_point(position: Vector3D, color: Vector3D, intensity: f64) -> Light
pub fn new_point(position: Vector3D, color: Vector3D, intensity: f64) -> Light
Creates a new point light at position with color and intensity.
Falloff defaults to 1.0 (inverse-square). The direction field is
unused for point lights and is set to the zero vector.
§Arguments
Vector3D- The world-space position of the light.Vector3D- The RGB intensity multiplier.f64- The intensity scalar.
§Returns
Light- The new point light.
Sourcepub fn new_spot(
position: Vector3D,
direction: Vector3D,
color: Vector3D,
intensity: f64,
half_angle_rad: f64,
) -> Light
pub fn new_spot( position: Vector3D, direction: Vector3D, color: Vector3D, intensity: f64, half_angle_rad: f64, ) -> Light
Creates a new spotlight at position shining in direction.
The cone is defined by half_angle_rad; the cosine of that angle
is stored for fast cone-test comparisons during shading.
§Arguments
Vector3D- The world-space position of the light.Vector3D- The unit direction the cone opens along.Vector3D- The RGB intensity multiplier.f64- The intensity scalar.f64- The half-angle of the cone in radians.
§Returns
Light- The new spotlight.