diff --git a/.idea/runConfigurations/Cleanup.xml b/.idea/runConfigurations/Cleanup.xml
new file mode 100644
index 0000000..c8727ff
--- /dev/null
+++ b/.idea/runConfigurations/Cleanup.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/rustfmt.xml b/.idea/runConfigurations/rustfmt.xml
index 3030f39..21a9c83 100644
--- a/.idea/runConfigurations/rustfmt.xml
+++ b/.idea/runConfigurations/rustfmt.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/rs/assets/shaders/skybox.wgsl b/rs/assets/shaders/skybox.wgsl
index ba43d32..b39a17b 100644
--- a/rs/assets/shaders/skybox.wgsl
+++ b/rs/assets/shaders/skybox.wgsl
@@ -6,6 +6,10 @@ struct SkyCube {
face_width: f32,
face_rotation: mat3x3,
rotation: mat3x3,
+ time_of_day: f32,
+ daylight: f32,
+ sun_position: vec3,
+ moon_position: vec3,
}
@group(0) @binding(0) var cube: SkyCube;
@@ -48,8 +52,7 @@ fn vertex(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
fn fragment(in: VertexOutput) -> @location(0) vec4 {
let ray_dir = ray_dir(in.position.xy);
let sample_dir = cube.rotation * ray_dir;
- let daytime = (sin(globals.time * 0.01) + 1.0) * 0.707;
- let sample_color = vec4(normalize((sample_dir + vec3(1.0))) * (daytime * daytime), 1.0);
+ let sample_color = vec4(normalize((sample_dir + vec3(1.0))) * (cube.daylight), 1.0);
return sample_color;
}
diff --git a/rs/src/lib.rs b/rs/src/lib.rs
index ab23c39..3fd5341 100644
--- a/rs/src/lib.rs
+++ b/rs/src/lib.rs
@@ -71,7 +71,7 @@ pub fn run() {
player::plugin.plugfn(),
pickups::plugin.plugfn(),
settings::plugin.plugfn(),
- planet::terrain::plugin.plugfn(),
+ planet::plugin.plugfn(),
ui::plugin.plugfn(),
))
.insert_resource(PkvStore::new_with_qualifier(
diff --git a/rs/src/planet.rs b/rs/src/planet.rs
index 8f44a5b..a1b8c99 100644
--- a/rs/src/planet.rs
+++ b/rs/src/planet.rs
@@ -1,15 +1,19 @@
-use bevy::{
- math::Vec3,
- prelude::{Component, Deref, DerefMut, Vec2},
-};
+use crate::{planet::day_night::DayNightCycle, util::IntoFnPlugin};
+use bevy::prelude::*;
use bevy_rapier3d::{na::Vector2, parry::math::Vector};
use serde::{Deserialize, Serialize};
use std::ops::{Add, Sub};
pub mod chunks;
+pub mod day_night;
pub mod sky;
pub mod terrain;
+pub fn plugin(app: &mut App) -> &mut App {
+ app.add_plugins((terrain::plugin.plugfn(), day_night::plugin.plugfn()))
+ .init_resource::()
+}
+
#[derive(
Component, Default, Debug, Copy, Clone, Deref, DerefMut, PartialEq, Serialize, Deserialize,
)]
diff --git a/rs/src/planet/day_night.rs b/rs/src/planet/day_night.rs
new file mode 100644
index 0000000..370d86e
--- /dev/null
+++ b/rs/src/planet/day_night.rs
@@ -0,0 +1,52 @@
+use bevy::{prelude::*, render::extract_resource::ExtractResource};
+use std::f64::consts::TAU;
+
+pub const DAY_LENGTH_MINUTES: f64 = 20.0;
+const SECS_PER_MIN: f64 = 60.0;
+const DAY_LENGTH_SECS: f64 = DAY_LENGTH_MINUTES * SECS_PER_MIN;
+
+pub fn plugin(app: &mut App) -> &mut App {
+ app.add_systems(Update, update_day_night)
+}
+
+#[derive(Resource, ExtractResource, Clone, Debug)]
+pub struct DayNightCycle {
+ pub mode: DayNightMode,
+ pub time_of_day: f64,
+ pub daylight: f64,
+ pub sun_position: Vec3,
+ pub moon_position: Vec3,
+}
+
+impl Default for DayNightCycle {
+ fn default() -> Self {
+ Self {
+ mode: default(),
+ time_of_day: 0.0,
+ daylight: 0.0,
+ sun_position: Vec3::splat(1.0).normalize(),
+ moon_position: Vec3::splat(-1.0).normalize(),
+ }
+ }
+}
+
+#[derive(Default, Clone, Copy, Debug)]
+pub enum DayNightMode {
+ #[default]
+ Running,
+ Forced,
+}
+
+pub fn update_day_night(mut day_night: ResMut, t: Res