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
18 changes: 1 addition & 17 deletions crates/bevy_pbr/src/atmosphere/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ mod node;
pub mod resources;

use bevy_app::{App, Plugin, Update};
use bevy_asset::{embedded_asset, AssetId, Assets, Handle};
use bevy_asset::{embedded_asset, AssetId, Handle};
use bevy_camera::Camera3d;
use bevy_core_pipeline::core_3d::graph::Node3d;
use bevy_ecs::{
component::Component,
query::{Changed, QueryItem, With},
resource::Resource,
schedule::IntoScheduleConfigs,
system::{lifetimeless::Read, Query},
};
Expand Down Expand Up @@ -115,12 +114,6 @@ impl Plugin for AtmospherePlugin {
UniformComponentPlugin::<GpuAtmosphereSettings>::default(),
))
.add_systems(Update, prepare_atmosphere_probe_components);

let world = app.world_mut();
let earthlike_medium = world
.resource_mut::<Assets<ScatteringMedium>>()
.add(ScatteringMedium::earthlike(256, 256));
world.insert_resource(EarthlikeAtmosphere(Atmosphere::earthlike(earthlike_medium)));
}

fn finish(&self, app: &mut App) {
Expand Down Expand Up @@ -211,15 +204,6 @@ impl Plugin for AtmospherePlugin {
}
}

#[derive(Resource)]
pub struct EarthlikeAtmosphere(Atmosphere);

impl EarthlikeAtmosphere {
pub fn get(&self) -> Atmosphere {
self.0.clone()
}
}

/// Enables atmospheric scattering for an HDR camera.
#[derive(Clone, Component)]
#[require(AtmosphereSettings, Hdr)]
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_pbr/src/medium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ pub struct ScatteringMedium {
pub terms: SmallVec<[ScatteringTerm; 1]>,
}

impl Default for ScatteringMedium {
fn default() -> Self {
ScatteringMedium::earthlike(256, 256)
}
}

impl ScatteringMedium {
// Returns a scattering medium with a default label and the
// specified scattering terms.
Expand Down
13 changes: 8 additions & 5 deletions examples/3d/atmosphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use bevy::{
VolumetricFog, VolumetricLight,
},
pbr::{
AtmosphereMode, AtmosphereSettings, DefaultOpaqueRendererMethod, EarthlikeAtmosphere,
ExtendedMaterial, MaterialExtension, ScreenSpaceReflections,
Atmosphere, AtmosphereMode, AtmosphereSettings, DefaultOpaqueRendererMethod,
ExtendedMaterial, MaterialExtension, ScatteringMedium, ScreenSpaceReflections,
},
post_process::bloom::Bloom,
prelude::*,
Expand Down Expand Up @@ -98,12 +98,15 @@ fn atmosphere_controls(
}
}

fn setup_camera_fog(mut commands: Commands, earth_atmosphere: Res<EarthlikeAtmosphere>) {
fn setup_camera_fog(
mut commands: Commands,
mut scattering_mediums: ResMut<Assets<ScatteringMedium>>,
) {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.4, 0.04, 0.0).looking_at(Vec3::Y * 0.1, Vec3::Y),
// get the default `Atmosphere` component
earth_atmosphere.get(),
// Earthlike atmosphere
Atmosphere::earthlike(scattering_mediums.add(ScatteringMedium::default())),
// Can be adjusted to change the scene scale and rendering quality
AtmosphereSettings::default(),
// The directional light illuminance used in this scene
Expand Down