DirectionalLight

DirectionalLight

  • color : bevy_color::color::Color
  • illuminance : f32
  • shadows_enabled : bool
  • shadow_depth_bias : f32
  • shadow_normal_bias : f32

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.0001Moonless, overcast night sky (starlight)
0.002Moonless clear night sky with airglow
0.05–0.3Full moon on a clear night
3.4Dark limit of civil twilight under a clear sky
20–50Public areas with dark surroundings
50Family living room lights
80Office building hallway/toilet lighting
100Very dark overcast day
150Train station platforms
320–500Office lighting
400Sunrise or sunset on a clear day.
1000Overcast day; typical TV studio lighting
10,000–25,000Full daylight (not direct sun)
32,000–100,000Direct sunlight

Source: Wikipedia

Shadows

To enable shadows, set the shadows_enabled property to true.

Shadows are produced via cascaded shadow maps.

To modify the cascade setup, such as the number of cascades or the maximum shadow distance, change the [CascadeShadowConfig] component of the entity with the [DirectionalLight].

To control the resolution of the shadow maps, use the [DirectionalLightShadowMap] resource:

# use bevy_app::prelude::*;
# use bevy_pbr::DirectionalLightShadowMap;
App::new()
    .insert_resource(DirectionalLightShadowMap { size: 2048 });

Functions