pub struct DirectionalLight {
    pub intensity: f32,
    pub color: Srgba,
    pub direction: Vec3,
    /* private fields */
}
Expand description

A light which shines in the given direction. The light will cast shadows if you generate a shadow map.

Fields§

§intensity: f32

The intensity of the light. This allows for higher intensity than 1 which can be used to simulate high intensity light sources like the sun.

§color: Srgba

The base color of the light.

§direction: Vec3

The direction the light shines.

Implementations§

source§

impl DirectionalLight

source

pub fn new( context: &Context, intensity: f32, color: Srgba, direction: &Vec3 ) -> DirectionalLight

Creates a new directional light.

source

pub fn clear_shadow_map(&mut self)

Clear the shadow map, effectively disable the shadow. Only necessary if you want to disable the shadow, if you want to update the shadow, just use DirectionalLight::generate_shadow_map.

source

pub fn generate_shadow_map( &mut self, texture_size: u32, geometries: impl IntoIterator<Item = impl Geometry> + Clone )

Generate a shadow map which is used to simulate shadows from the directional light onto the geometries given as input. It is recomended that the texture size is power of 2. If the shadows are too low resolution (the edges between shadow and non-shadow are pixelated) try to increase the texture size and/or split the scene by creating another light source with same parameters and let the two light sources shines on different parts of the scene.

source

pub fn shadow_map(&self) -> Option<&DepthTexture2D>

Returns a reference to the shadow map if it has been generated.

Trait Implementations§

source§

impl Light for DirectionalLight

source§

fn shader_source(&self, i: u32) -> String

The fragment shader source for calculating this lights contribution to the color in a fragment. It should contain a function with this signature vec3 calculate_lighting{}(vec3 surface_color, vec3 position, vec3 normal, vec3 view_direction, float metallic, float roughness, float occlusion) Where {} is replaced with the number i given as input. This function should return the color contribution for this light on the surface with the given surface parameters.
source§

fn use_uniforms(&self, program: &Program, i: u32)

Should bind the uniforms that is needed for calculating this lights contribution to the color in Light::shader_source.
source§

fn id(&self) -> u8

Returns a unique ID for each variation of the shader source returned from Light::shader_source. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.