Skip to main content

Light

Struct Light 

Source
pub struct Light { /* private fields */ }
Expand description

A light source contributing illumination to a shaded point.

The fields have meanings that depend on LightType:

  • For LightType::Directional, position is unused and direction is the unit vector pointing from the surface toward the light.
  • For LightType::Point, position is the world position of the light and direction is unused.
  • For LightType::Spot, both position and direction are meaningful and spot_cos carries cos(half_angle) of the spotlight cone.

Implementations§

Source§

impl Light

Implements factory constructors and shading for Light, Material, and LightingUniforms.

Source

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

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

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

impl Light

Source

pub fn get_kind(&self) -> LightType

Source

pub fn get_mut_kind(&mut self) -> &mut LightType

Source

pub fn set_kind(&mut self, val: LightType) -> &mut Self

Source

pub fn get_position(&self) -> Vector3D

Source

pub fn get_mut_position(&mut self) -> &mut Vector3D

Source

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

Source

pub fn get_direction(&self) -> Vector3D

Source

pub fn get_mut_direction(&mut self) -> &mut Vector3D

Source

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

Source

pub fn get_color(&self) -> Vector3D

Source

pub fn get_mut_color(&mut self) -> &mut Vector3D

Source

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

Source

pub fn get_intensity(&self) -> f64

Source

pub fn get_mut_intensity(&mut self) -> &mut f64

Source

pub fn set_intensity(&mut self, val: f64) -> &mut Self

Source

pub fn get_falloff(&self) -> f64

Source

pub fn get_mut_falloff(&mut self) -> &mut f64

Source

pub fn set_falloff(&mut self, val: f64) -> &mut Self

Source

pub fn get_spot_cos(&self) -> f64

Source

pub fn get_mut_spot_cos(&mut self) -> &mut f64

Source

pub fn set_spot_cos(&mut self, val: f64) -> &mut Self

Source§

impl Light

Source

pub fn new( kind: LightType, position: Vector3D, direction: Vector3D, color: Vector3D, intensity: f64, falloff: f64, spot_cos: f64, ) -> Self

Trait Implementations§

Source§

impl Clone for Light

Source§

fn clone(&self) -> Light

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 Light

Source§

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

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

impl PartialEq for Light

Source§

fn eq(&self, other: &Light) -> 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 Light

Auto Trait Implementations§

§

impl Freeze for Light

§

impl RefUnwindSafe for Light

§

impl Send for Light

§

impl Sync for Light

§

impl Unpin for Light

§

impl UnsafeUnpin for Light

§

impl UnwindSafe for Light

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