Skip to content

Commit 32db9dc

Browse files
committed
rename to EarthlikeAtmosphere
1 parent f3b9345 commit 32db9dc

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

crates/bevy_pbr/src/atmosphere/mod.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,10 @@ impl Plugin for AtmospherePlugin {
114114
.add_systems(Update, prepare_atmosphere_probe_components);
115115

116116
let world = app.world_mut();
117-
let earth_atmosphere = world
117+
let earthlike_medium = world
118118
.resource_mut::<Assets<ScatteringMedium>>()
119-
.add(ScatteringMedium::earth_atmosphere());
120-
world.insert_resource(EarthAtmosphere(Atmosphere {
121-
bottom_radius: 6_360_000.0,
122-
top_radius: 6_460_000.0,
123-
ground_albedo: Vec3::splat(0.3),
124-
medium: earth_atmosphere,
125-
}));
119+
.add(ScatteringMedium::earthlike(256, 256));
120+
world.insert_resource(EarthlikeAtmosphere(Atmosphere::earthlike(earthlike_medium)));
126121
}
127122

128123
fn finish(&self, app: &mut App) {
@@ -208,9 +203,9 @@ impl Plugin for AtmospherePlugin {
208203
}
209204

210205
#[derive(Resource)]
211-
pub struct EarthAtmosphere(Atmosphere);
206+
pub struct EarthlikeAtmosphere(Atmosphere);
212207

213-
impl EarthAtmosphere {
208+
impl EarthlikeAtmosphere {
214209
pub fn get(&self) -> Atmosphere {
215210
self.0.clone()
216211
}
@@ -242,6 +237,20 @@ pub struct Atmosphere {
242237
pub medium: Handle<ScatteringMedium>,
243238
}
244239

240+
impl Atmosphere {
241+
pub fn earthlike(medium: Handle<ScatteringMedium>) -> Self {
242+
const EARTH_BOTTOM_RADIUS: f32 = 6_360_000.0;
243+
const EARTH_TOP_RADIUS: f32 = 6_460_000.0;
244+
const EARTH_ALBEDO: Vec3 = Vec3::splat(0.3);
245+
Self {
246+
bottom_radius: EARTH_BOTTOM_RADIUS,
247+
top_radius: EARTH_TOP_RADIUS,
248+
ground_albedo: EARTH_ALBEDO,
249+
medium,
250+
}
251+
}
252+
}
253+
245254
impl ExtractComponent for Atmosphere {
246255
type QueryData = Read<Atmosphere>;
247256

crates/bevy_pbr/src/medium.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ impl ScatteringMedium {
117117
}
118118

119119
/// Returns a scattering medium representing an earthlike atmosphere.
120-
pub fn earth_atmosphere() -> Self {
120+
pub fn earthlike(falloff_resolution: u32, phase_resolution: u32) -> Self {
121121
Self::new(
122-
256,
123-
256,
122+
falloff_resolution,
123+
phase_resolution,
124124
[
125125
ScatteringTerm {
126126
absorption: Vec3::ZERO,
@@ -145,7 +145,7 @@ impl ScatteringMedium {
145145
},
146146
],
147147
)
148-
.with_label("earth_atmosphere")
148+
.with_label("earthlike_atmosphere")
149149
}
150150
}
151151

examples/3d/atmosphere.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bevy::{
66
camera::Exposure,
77
core_pipeline::tonemapping::Tonemapping,
88
light::{light_consts::lux, AtmosphereEnvironmentMapLight, CascadeShadowConfigBuilder},
9-
pbr::{AtmosphereSettings, EarthAtmosphere},
9+
pbr::{AtmosphereSettings, EarthlikeAtmosphere},
1010
post_process::bloom::Bloom,
1111
prelude::*,
1212
};
@@ -19,7 +19,7 @@ fn main() {
1919
.run();
2020
}
2121

22-
fn setup_camera_fog(mut commands: Commands, earth_atmosphere: Res<EarthAtmosphere>) {
22+
fn setup_camera_fog(mut commands: Commands, earth_atmosphere: Res<EarthlikeAtmosphere>) {
2323
commands.spawn((
2424
Camera3d::default(),
2525
Transform::from_xyz(-1.2, 0.15, 0.0).looking_at(Vec3::Y * 0.1, Vec3::Y),

0 commit comments

Comments
 (0)