diff --git a/crates/bevy_pbr/src/atmosphere/mod.rs b/crates/bevy_pbr/src/atmosphere/mod.rs index 908f471f39d1d..959baf682b1f0 100644 --- a/crates/bevy_pbr/src/atmosphere/mod.rs +++ b/crates/bevy_pbr/src/atmosphere/mod.rs @@ -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}, }; @@ -115,12 +114,6 @@ impl Plugin for AtmospherePlugin { UniformComponentPlugin::::default(), )) .add_systems(Update, prepare_atmosphere_probe_components); - - let world = app.world_mut(); - let earthlike_medium = world - .resource_mut::>() - .add(ScatteringMedium::earthlike(256, 256)); - world.insert_resource(EarthlikeAtmosphere(Atmosphere::earthlike(earthlike_medium))); } fn finish(&self, app: &mut App) { @@ -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)] diff --git a/crates/bevy_pbr/src/medium.rs b/crates/bevy_pbr/src/medium.rs index 0c08e00633ae5..b55fa1c134982 100644 --- a/crates/bevy_pbr/src/medium.rs +++ b/crates/bevy_pbr/src/medium.rs @@ -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. diff --git a/examples/3d/atmosphere.rs b/examples/3d/atmosphere.rs index bd27bf888d509..e264716cc3714 100644 --- a/examples/3d/atmosphere.rs +++ b/examples/3d/atmosphere.rs @@ -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::*, @@ -98,12 +98,15 @@ fn atmosphere_controls( } } -fn setup_camera_fog(mut commands: Commands, earth_atmosphere: Res) { +fn setup_camera_fog( + mut commands: Commands, + mut scattering_mediums: ResMut>, +) { 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