Struct bevy::prelude::DirectionalLight
pub struct DirectionalLight {
pub color: Color,
pub illuminance: f32,
pub shadows_enabled: bool,
pub shadow_projection: OrthographicProjection,
pub shadow_depth_bias: f32,
pub shadow_normal_bias: f32,
}
Expand description
A Directional light.
Directional lights don’t exist in reality but they are a good approximation for light sources VERY far away, like the sun or the moon.
The light shines along the forward direction of the entity’s transform. With a default transform this would be along the negative-Z axis.
Valid values for illuminance
are:
Illuminance (lux) | Surfaces illuminated by |
---|---|
0.0001 | Moonless, overcast night sky (starlight) |
0.002 | Moonless clear night sky with airglow |
0.05–0.3 | Full moon on a clear night |
3.4 | Dark limit of civil twilight under a clear sky |
20–50 | Public areas with dark surroundings |
50 | Family living room lights |
80 | Office building hallway/toilet lighting |
100 | Very dark overcast day |
150 | Train station platforms |
320–500 | Office lighting |
400 | Sunrise or sunset on a clear day. |
1000 | Overcast day; typical TV studio lighting |
10,000–25,000 | Full daylight (not direct sun) |
32,000–100,000 | Direct sunlight |
Source: Wikipedia
Shadows
To enable shadows, set the shadows_enabled
property to true
.
While directional lights contribute to the illumination of meshes regardless of their (or the meshes’) positions, currently only a limited region of the scene (the shadow volume) can cast and receive shadows for any given directional light.
The shadow volume is a rectangular cuboid, with left/right/bottom/top/near/far
planes controllable via the shadow_projection
field. It is affected by the
directional light entity’s GlobalTransform
, and as such can be freely repositioned in the
scene, (or even scaled!) without affecting illumination in any other way, by simply
moving (or scaling) the entity around. The shadow volume is always oriented towards the
light entity’s forward direction.
For smaller scenes, a static directional light with a preset volume is typically sufficient. For larger scenes with movable cameras, you might want to introduce a system that dynamically repositions and scales the light entity (and therefore its shadow volume) based on the scene subject’s position (e.g. a player character) and its relative distance to the camera.
Shadows are produced via shadow mapping.
To control the resolution of the shadow maps, use the DirectionalLightShadowMap
resource:
App::new()
.insert_resource(DirectionalLightShadowMap { size: 2048 });
Note: Very large shadow map resolutions (> 4K) can have non-negligible performance and
memory impact, and not work properly under mobile or lower-end hardware. To improve the visual
fidelity of shadow maps, it’s typically advisable to first reduce the shadow_projection
left/right/top/bottom to a scene-appropriate size, before ramping up the shadow map
resolution.
Fields§
§color: Color
§illuminance: f32
Illuminance in lux
shadows_enabled: bool
§shadow_projection: OrthographicProjection
A projection that controls the volume in which shadow maps are rendered
shadow_depth_bias: f32
§shadow_normal_bias: f32
A bias applied along the direction of the fragment’s surface normal. It is scaled to the shadow map’s texel size so that it is automatically adjusted to the orthographic projection.
Implementations§
§impl DirectionalLight
impl DirectionalLight
pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.0199999996f32
pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 0.600000024f32
Trait Implementations§
§impl Clone for DirectionalLight
impl Clone for DirectionalLight
§fn clone(&self) -> DirectionalLight
fn clone(&self) -> DirectionalLight
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Component for DirectionalLightwhere
DirectionalLight: 'static + Send + Sync,
impl Component for DirectionalLightwhere
DirectionalLight: 'static + Send + Sync,
type Storage = TableStorage
§impl Debug for DirectionalLight
impl Debug for DirectionalLight
§impl Default for DirectionalLight
impl Default for DirectionalLight
§fn default() -> DirectionalLight
fn default() -> DirectionalLight
§impl GetTypeRegistration for DirectionalLight
impl GetTypeRegistration for DirectionalLight
§impl Reflect for DirectionalLight
impl Reflect for DirectionalLight
§fn get_type_info(&self) -> &'static TypeInfo
fn get_type_info(&self) -> &'static TypeInfo
§fn into_any(
self: Box<DirectionalLight, Global>
) -> Box<dyn Any + 'static, Global>
fn into_any(
self: Box<DirectionalLight, Global>
) -> Box<dyn Any + 'static, Global>
Box<dyn Any>
.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.§fn into_reflect(
self: Box<DirectionalLight, Global>
) -> Box<dyn Reflect + 'static, Global>
fn into_reflect(
self: Box<DirectionalLight, Global>
) -> Box<dyn Reflect + 'static, Global>
§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
§fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
Reflect
trait object. Read more§fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
§fn reflect_owned(self: Box<DirectionalLight, Global>) -> ReflectOwned
fn reflect_owned(self: Box<DirectionalLight, Global>) -> ReflectOwned
§fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§impl Struct for DirectionalLight
impl Struct for DirectionalLight
§fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
index
as a &mut dyn Reflect
. Read more§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.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§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist. Read more§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids(
components: &mut Components,
storages: &mut Storages,
ids: &mut impl FnMut(ComponentId)
)
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> Cwhere
F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,
fn get_components(self, func: &mut impl FnMut(OwningPtr<'_>))
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
§impl<T> GetPath for Twhere
T: Reflect,
impl<T> GetPath for Twhere
T: Reflect,
§fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
path
.§fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more