Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/bevy_light/src/directional_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ pub fn update_directional_light_frusta(
/// Requires a `bevy::pbr::Atmosphere` component on a [`Camera3d`](bevy_camera::Camera3d) to have any effect.
///
/// By default, the atmosphere is rendered with [`SunDisk::EARTH`], which approximates the
/// apparent size and brightness of the Sun as seen from Earth. You can also disable the sun
/// disk entirely with [`SunDisk::OFF`].
/// apparent size and brightness of the Sun as seen from Earth. Use [`SunDisk::MARS`] for the
/// smaller apparent sun size from Mars. You can also disable the sun disk entirely
/// with [`SunDisk::OFF`].
///
/// In order to cause the sun to "glow" and light up the surrounding sky, enable bloom
/// in your post-processing pipeline by adding a `Bloom` component to your camera.
Expand All @@ -284,6 +285,15 @@ impl SunDisk {
intensity: 1.0,
};

/// Mars-like parameters for the sun disk.
///
/// Uses the mean apparent size (~21 arcminutes) of the Sun from Mars
/// at ~1.52 AU distance with default intensity.
pub const MARS: SunDisk = SunDisk {
angular_size: 0.00615,
intensity: 1.0,
};

/// No visible sun disk.
///
/// Keeps scattering and directional light illumination, but hides the disk itself.
Expand Down
14 changes: 11 additions & 3 deletions examples/3d/atmosphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy::{
input::keyboard::KeyCode,
light::{
atmosphere::ScatteringMedium, light_consts::lux, Atmosphere, AtmosphereEnvironmentMapLight,
FogVolume, VolumetricFog, VolumetricLight,
FogVolume, SunDisk, VolumetricFog, VolumetricLight,
},
pbr::{
AtmosphereMode, AtmosphereSettings, DefaultOpaqueRendererMethod, ExtendedMaterial,
Expand Down Expand Up @@ -72,6 +72,7 @@ fn atmosphere_controls(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut planet_atmosphere: Query<(&mut Atmosphere, &mut GlobalTransform)>,
mut camera_settings: Query<&mut AtmosphereSettings, With<Camera3d>>,
mut sun_disks: Query<&mut SunDisk, With<DirectionalLight>>,
atmosphere_presets: Res<AtmospherePresets>,
mut game_state: ResMut<GameState>,
mut camera_exposure: Query<&mut Exposure, With<Camera3d>>,
Expand All @@ -81,16 +82,22 @@ fn atmosphere_controls(
for (mut atmosphere, mut transform) in &mut planet_atmosphere {
*atmosphere = Atmosphere::earth(atmosphere_presets.earth.clone());
*transform = GlobalTransform::from_translation(-Vec3::Y * atmosphere.inner_radius);
println!("Switched to Earth atmosphere");
}
for mut sun_disk in &mut sun_disks {
sun_disk.angular_size = SunDisk::EARTH.angular_size;
}
println!("Switched to Earth atmosphere");
}

if keyboard_input.just_pressed(KeyCode::Digit4) {
for (mut atmosphere, mut transform) in &mut planet_atmosphere {
*atmosphere = Atmosphere::mars(atmosphere_presets.mars.clone());
*transform = GlobalTransform::from_translation(-Vec3::Y * atmosphere.inner_radius);
println!("Switched to Mars atmosphere");
}
for mut sun_disk in &mut sun_disks {
sun_disk.angular_size = SunDisk::MARS.angular_size;
}
println!("Switched to Mars atmosphere");
}

if keyboard_input.just_pressed(KeyCode::Digit1) {
Expand Down Expand Up @@ -229,6 +236,7 @@ fn setup_terrain_scene(
},
Transform::from_xyz(1.0, 0.4, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
VolumetricLight,
SunDisk::EARTH,
));

// spawn the fog volume
Expand Down