Repository: JonahPlusPlus/bevy_atmosphere (language: rust)

Issue:
Sky sphere has wrong render order
![Examples Screenshot 2022 03 09 - 15 01 35 21](https://user-images.githubusercontent.com/16053640/157524264-d182f60f-b63f-4307-88ca-df525c19a498.png)
Sometimes the scene objects are rendered BEFORE the sky sphere, which makes them totally covered by it.
Posible solution: make the radius of sky sphere tunable.


Discussion / hints:
>  Posible solution: make the radius of sky sphere tunable.

Sounds reasonable to me. Could you send a PR for it?
Sure! Will do.

Fix patch:
diff --git a/README.MD b/README.MD
index 5a00b9f..88c6357 100644
--- a/README.MD
+++ b/README.MD
@@ -5,14 +5,17 @@
 [![Crates.io](https://img.shields.io/crates/d/bevy_atmosphere)](https://crates.io/crates/bevy_atmosphere) [![docs.rs](https://img.shields.io/docsrs/bevy_atmosphere)](https://docs.rs/bevy_atmosphere/) 
 
 ### Example
-```
+```rust
 use bevy::prelude::*;
 use bevy_atmosphere::*;
 fn main() {
     App::new()
         .insert_resource(bevy_atmosphere::AtmosphereMat::default()) // Default Earth sky
         .add_plugins(DefaultPlugins)
-        .add_plugin(bevy_atmosphere::AtmospherePlugin { dynamic: false }) // Set to false since we aren't changing the sky's appearance
+        .add_plugin(bevy_atmosphere::AtmospherePlugin {
+            dynamic: false,  // Set to false since we aren't changing the sky's appearance
+            sky_radius: 10.0,
+        })
         .add_startup_system(setup)
         .run();
 }
diff --git a/examples/cycle.rs b/examples/cycle.rs
index 52e8974..4e56c63 100644
--- a/examples/cycle.rs
+++ b/examples/cycle.rs
@@ -8,7 +8,10 @@ fn main() {
         .insert_resource(AtmosphereMat::default()) // Default AtmosphereMat, we can edit it to simulate another planet
         .add_plugins(DefaultPlugins)
         .add_plugin(PlayerPlugin) // Simple movement for this example
-        .add_plugin(AtmospherePlugin { dynamic: true }) // Dynamic is set to true so that the material is updated when the SkyMaterial resource is edited. If it was not set to true, we would have to update ourselves.
+        .add_plugin(AtmospherePlugin {
+            dynamic: true,
+            sky_radius: 10.0,
+        }) // Dynamic is set to true so that the material is updated when the SkyMaterial resource is edited. If it was not set to true, we would have to update ourselves.
         .add_startup_system(setup_environment)
         .add_system(daylight_cycle)
         .run();
diff --git a/src/lib.rs b/src/lib.rs
index 69a64d3..d00a0dd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,7 +9,10 @@
 //!     App::new()
 //!         .insert_resource(bevy_atmosphere::AtmosphereMat::default()) // Default Earth sky
 //!         .add_plugins(DefaultPlugins)
-//!         .add_plugin(bevy_atmosphere::AtmospherePlugin { dynamic: false }) // Set to false since we aren't changing the sky's appearance
+//!         .add_plugin(bevy_atmosphere::AtmospherePlugin {
+//!             dynamic: false,  // Set to false since we aren't changing the sky's appearance
+//!             sky_radius: 10.0
+//!         })
 //!         .add_startup_system(setup)
 //!         .run();
 //! }
@@ -34,7 +37,6 @@ const SKY_FRAGMENT_SHADER: &str = include_str!("shaders/sky.frag");
 /// Sets up the atmosphere and the systems that control it
 ///
 /// Follows the first camera it finds
-#[derive(Default)]
 pub struct AtmospherePlugin {
     /// If set to `true`, whenever the [`AtmosphereMat`](crate::AtmosphereMat) resource (if it exists) is changed, the sky is updated
     ///
@@ -58,8 +60,20 @@ pub struct AtmospherePlugin {
     /// }
     /// ```
     pub dynamic: bool,
+    pub sky_radius: f32,
 }
 
+impl Default for AtmospherePlugin {
+    fn default() -> Self {
+        Self {
+            dynamic: false,
+            sky_radius: 10.0,
+        }
+    }
+}
+
+pub struct SkyRadius(f32);
+
 impl Plugin for AtmospherePlugin {
     fn build(&self, app: &mut App) {
         let mut shaders = app.world.get_resource_mut::<Assets<Shader>>().unwrap();
@@ -81,6 +95,8 @@ impl Plugin for AtmospherePlugin {
         if self.dynamic {
             app.add_system(atmosphere_dynamic_sky);
         }
+
+        app.insert_resource(SkyRadius(self.sky_radius));
     }
 }
 
@@ -88,6 +104,7 @@ fn atmosphere_add_sky_sphere(
     mut commands: Commands,
     mut meshes: ResMut<Assets<Mesh>>,
     mut sky_materials: ResMut<Assets<AtmosphereMat>>,
+    sky_radius: Res<SkyRadius>,
     config: Option<Res<AtmosphereMat>>,
 ) {
     let sky_material = match config {
@@ -100,7 +117,7 @@ fn atmosphere_add_sky_sphere(
     commands
         .spawn_bundle(MaterialMeshBundle {
             mesh: meshes.add(Mesh::from(shape::Icosphere {
-                radius: -10.0,
+                radius: -sky_radius.0,
                 subdivisions: 2,
             })),
             material: sky_material,


Test patch: