Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/ambient_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy::prelude::*;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// used to build a ScalarGradient, bsed upon SkyTimeSettings
/// used to build a ScalarGradient, based upon SkyTimeSettings
/// places the color we want based upon the timing of SkyTimeSettings
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Reflect)]
Expand Down
8 changes: 6 additions & 2 deletions src/aurora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct AuroraCameraTag;

#[derive(Resource, Reflect, Clone)]
pub struct AuroraSettings {
/// controlls size of the render target of the aurora material
/// controls size of the render target of the aurora material
/// a value of 1.0: use 100% of the windows screen size. aka full quality.
/// a value of 0.5: will render the aurora 50% of the screen and be upscaled 200%
pub render_texture_percent: f32,
Expand Down Expand Up @@ -90,13 +90,17 @@ fn aurora_follow_camera(
fn resize_aurora_on_window_change(
mut resize_events: MessageReader<WindowResized>,
mut images: ResMut<Assets<Image>>,
aurora_material_optional: Option<Res<Assets<AuroraMaterial>>>,
aurora_handles: Res<AuroraTextureHandle>,
aurora_settings: Res<AuroraSettings>,
primary_windows: Query<&Window, With<PrimaryWindow>>,
mut repeated_calls: Local<i32>,
) {
if aurora_material_optional.is_none() {
return;
};
let mut update_aurora = aurora_settings.is_changed();

for event in resize_events.read() {
let is_primary = primary_windows.get(event.window).is_ok();
update_aurora |= is_primary;
Expand Down
2 changes: 1 addition & 1 deletion src/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy::prelude::*;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;

/// All the current colors that controlls the sky gradient
/// All the current colors that controls the sky gradient
/// a sky gradient has 4 colors, and we animate it based upon the "sky time"
/// gradient stops 0.0 -> 0.5 = DAY time colors
/// gradient stops 0.5 -> 1.0 = NIGHT time colors
Expand Down
12 changes: 7 additions & 5 deletions src/gradient_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use bevy::{
};

use crate::{
cycle::{SkyTime, SkyTimeSettings},
gradient::{Gradient, SkyGradientBuilder, SkyGradients},
gradient_material::FullGradientMaterial,
plugin::GradientTextureHandle,
aurora_material::AuroraMaterial, cycle::{SkyTime, SkyTimeSettings}, gradient::{Gradient, SkyGradientBuilder, SkyGradients}, gradient_material::FullGradientMaterial, plugin::GradientTextureHandle,
};

/// animates the sky gradients, REQUIRES CyclePlugin.
Expand All @@ -21,7 +18,7 @@ impl Plugin for GradientDriverPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, drive_gradients);

// initial sky color values will be wrong, until SkyTimeSettings can be fetched in update_sky_colors_builer
// initial sky color values will be wrong, until SkyTimeSettings can be fetched in update_sky_colors_builder
app.insert_resource(self.sky_colors_builder.build(&SkyTimeSettings::default()));
app.add_systems(
Update,
Expand Down Expand Up @@ -75,10 +72,15 @@ fn drive_gradients(
fn resize_gradient_on_window_change(
mut resize_events: MessageReader<WindowResized>,
mut images: ResMut<Assets<Image>>,
aurora_material_optional: Option<Res<Assets<AuroraMaterial>>>,
aurora_handles: Res<GradientTextureHandle>,
primary_windows: Query<&Window, With<PrimaryWindow>>,
mut repeated_calls: Local<i32>,
) {
if aurora_material_optional.is_none() {
return;
};

let mut update_texture = false;
for event in resize_events.read() {
let is_primary = primary_windows.get(event.window).is_ok();
Expand Down
2 changes: 1 addition & 1 deletion src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn make_noise_sampler() -> ImageSampler {
})
}

/// will wait until a noisetextureasset is loaded, then override the texture data
/// will wait until a NoiseTextureAsset is loaded, then override the texture data
#[cfg(feature = "serde")]
#[derive(Resource)]
pub struct PendingNoiseTextureAsset(Handle<NoiseTextureAsset>);
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl Default for SkySettings {
}
}

/// controlls what features you want.
/// controls what features you want.
/// you might not want to use the default Cycle/SunDriver/GradientDriver/Aurora for example
/// then you can skip that plugin and implement your own.
pub struct SkyPluginBuilder {
pub settings: SkySettings,
/// if enabled, the full sky is rendered to a texture
/// usefull if you need to sample the sky for a fog effect for example
/// useful if you need to sample the sky for a fog effect for example
pub render_sky_to_texture: bool,
pub use_preset_plugin: bool,
pub noise: NoisePlugin,
Expand Down
56 changes: 31 additions & 25 deletions src/presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub const DEFAULT_SKY_COLORS_BUILDER: SkyGradientBuilder = SkyGradientBuilder {
},
};

/// data that controlls the look of a sky
/// (not aurora upsampling size, nor noise 3dTexture, performance and "look" should be seperate)
/// data that controls the look of a sky
/// (not aurora upsampling size, nor noise 3dTexture, performance and "look" should be separate)
/// (None) values will not override current sky settings.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Default)]
Expand Down Expand Up @@ -77,9 +77,9 @@ pub fn handle_apply_preset_events(
skyboxes: Query<&mut MeshMaterial3d<FullSkyMaterial>>,
auroras: Query<&mut MeshMaterial3d<AuroraMaterial>>,
gradient_handles: Query<&mut MeshMaterial3d<FullGradientMaterial>>,
mut sky_materials: ResMut<Assets<FullSkyMaterial>>,
mut auroras_materials: ResMut<Assets<AuroraMaterial>>,
mut gradient_materials: ResMut<Assets<FullGradientMaterial>>,
mut sky_materials_optional: Option<ResMut<Assets<FullSkyMaterial>>>,
mut auroras_materials_optional: Option<ResMut<Assets<AuroraMaterial>>>,
mut gradient_materials_optional: Option<ResMut<Assets<FullGradientMaterial>>>,
mut sky_colors_builder_optional: Option<ResMut<SkyGradientBuilder>>,
mut sun_settings_optional: Option<ResMut<SunSettings>>,
) {
Expand All @@ -96,31 +96,37 @@ pub fn handle_apply_preset_events(
}

if let Some(star_settings) = &event.sky_preset.stars {
let skybox_material_handle = skyboxes
.single()
.expect("1 entity with SkyGradientMaterial");
let mut skybox_material = sky_materials
.get_mut(skybox_material_handle)
.expect("SkyBoxMaterial");
skybox_material.stars = star_settings.clone();
if let Some(sky_materials) = sky_materials_optional.as_mut() {
let skybox_material_handle = skyboxes
.single()
.expect("1 entity with SkyGradientMaterial");
let mut skybox_material = sky_materials
.get_mut(skybox_material_handle)
.expect("SkyBoxMaterial");
skybox_material.stars = star_settings.clone();
}
}

if let Some(aurora_bind_group) = &event.sky_preset.aurora_settings {
let aurora_material_handle =
auroras.single().expect("1 entity with SkyGradientMaterial");
let mut aurora_material = auroras_materials
.get_mut(aurora_material_handle)
.expect("auroraMaterial");
aurora_material.aurora_settings = aurora_bind_group.clone();
if let Some(auroras_materials) = auroras_materials_optional.as_mut() {
let aurora_material_handle =
auroras.single().expect("1 entity with SkyGradientMaterial");
let mut aurora_material = auroras_materials
.get_mut(aurora_material_handle)
.expect("auroraMaterial");
aurora_material.aurora_settings = aurora_bind_group.clone();
}
}
if let Some(gradient_bind_group) = &event.sky_preset.gradient_bind_group {
let gradient_material_handle = gradient_handles
.single()
.expect("1 entity with FullGradientMaterial");
let mut gradient_material = gradient_materials
.get_mut(gradient_material_handle)
.expect("gradientMaterial");
gradient_material.gradient_bind_group = gradient_bind_group.clone();
if let Some(gradient_materials) = gradient_materials_optional.as_mut() {
let gradient_material_handle = gradient_handles
.single()
.expect("1 entity with FullGradientMaterial");
let mut gradient_material = gradient_materials
.get_mut(gradient_material_handle)
.expect("gradientMaterial");
gradient_material.gradient_bind_group = gradient_bind_group.clone();
}
}
}
}