pub struct DirectionalLight {
pub intensity: f32,
pub color: Color,
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: f32The 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: ColorThe base color of the light.
direction: Vec3The direction the light shines.
Implementations
sourceimpl DirectionalLight
impl DirectionalLight
sourcepub fn new(
context: &Context,
intensity: f32,
color: Color,
direction: &Vec3
) -> ThreeDResult<DirectionalLight>
pub fn new(
context: &Context,
intensity: f32,
color: Color,
direction: &Vec3
) -> ThreeDResult<DirectionalLight>
Creates a new directional light.
pub fn set_color(&mut self, color: Color)
pub fn color(&self) -> Color
pub fn set_intensity(&mut self, intensity: f32)
pub fn intensity(&self) -> f32
pub fn set_direction(&mut self, direction: &Vec3)
pub fn direction(&self) -> Vec3
sourcepub fn clear_shadow_map(&mut self)
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.
sourcepub fn generate_shadow_map(
&mut self,
texture_size: u32,
geometries: &[&dyn Geometry]
) -> ThreeDResult<()>
pub fn generate_shadow_map(
&mut self,
texture_size: u32,
geometries: &[&dyn Geometry]
) -> ThreeDResult<()>
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.
sourcepub fn shadow_map(&self) -> Option<&DepthTargetTexture2D>
pub fn shadow_map(&self) -> Option<&DepthTargetTexture2D>
Returns a reference to the shadow map if it has been generated.
Trait Implementations
sourceimpl Light for DirectionalLight
impl Light for DirectionalLight
sourcefn shader_source(&self, i: u32) -> String
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. Read more
sourcefn use_uniforms(&self, program: &Program, i: u32) -> ThreeDResult<()>
fn use_uniforms(&self, program: &Program, i: u32) -> ThreeDResult<()>
Should bind the uniforms that is needed for calculating this lights contribution to the color in Light::shader_source.
Auto Trait Implementations
impl !RefUnwindSafe for DirectionalLight
impl !Send for DirectionalLight
impl !Sync for DirectionalLight
impl Unpin for DirectionalLight
impl !UnwindSafe for DirectionalLight
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more