@ -0,0 +1,5 @@ | |||||
[gd_resource type="Gradient" format=3 uid="uid://bgsedjexjylfr"] | |||||
[resource] | |||||
offsets = PackedFloat32Array(0) | |||||
colors = PackedColorArray(0.301961, 0.266667, 0.823529, 1) |
@ -0,0 +1,5 @@ | |||||
[gd_resource type="Curve" format=3 uid="uid://cmmbliff4tja2"] | |||||
[resource] | |||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.25, 0), 0.0, 0.0, 0, 0, Vector2(0.75, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0] | |||||
point_count = 4 |
@ -0,0 +1,5 @@ | |||||
[gd_resource type="Gradient" format=3 uid="uid://dvpnjt66dtk46"] | |||||
[resource] | |||||
offsets = PackedFloat32Array(0.1, 0.25, 0.401515, 0.6, 0.75, 0.9) | |||||
colors = PackedColorArray(0.317647, 0.333333, 0.65098, 1, 0.87451, 0.521569, 0.407843, 1, 0.584314, 0.980392, 0.980392, 1, 0.584314, 0.980392, 0.980392, 1, 0.87451, 0.521569, 0.407843, 1, 0.317647, 0.333333, 0.65098, 1) |
@ -0,0 +1,5 @@ | |||||
[gd_resource type="Gradient" format=3 uid="uid://d0cpq2rok3jsi"] | |||||
[resource] | |||||
offsets = PackedFloat32Array(0.1, 0.4, 0.6, 0.9) | |||||
colors = PackedColorArray(0.317647, 0.333333, 0.65098, 1, 0.583728, 0.979416, 0.978736, 1, 0.584314, 0.980392, 0.980392, 1, 0.317647, 0.333333, 0.65098, 1) |
@ -0,0 +1,5 @@ | |||||
[gd_resource type="Gradient" format=3 uid="uid://chetnl1mrww83"] | |||||
[resource] | |||||
offsets = PackedFloat32Array(0, 0.3, 0.7, 1) | |||||
colors = PackedColorArray(1, 0.584314, 0.262745, 1, 0.968627, 0.921569, 0.858824, 1, 0.968627, 0.921569, 0.858824, 1, 1, 0.584314, 0.262745, 1) |
@ -0,0 +1,5 @@ | |||||
[gd_resource type="Curve" format=3 uid="uid://ds0dqy41plskw"] | |||||
[resource] | |||||
_data = [Vector2(0.2, 0), 0.0, 0.0, 0, 0, Vector2(0.3, 1), 0.0, 0.0, 0, 0, Vector2(0.7, 1), 0.0, 0.0, 0, 0, Vector2(0.8, 0), 0.0, 0.0, 0, 0] | |||||
point_count = 4 |
@ -0,0 +1,89 @@ | |||||
extends Node3D | |||||
signal end_of_day | |||||
signal pause_time | |||||
signal resume_time | |||||
signal set_day_length(length_in_seconds: float) | |||||
signal set_rate_of_time(rate: float) ## 2.0 for 2x | |||||
signal set_time(time: float) ## Time should be between 0 and 1 | |||||
@export var day_length: float = 60.0 ## Day length in seconds | |||||
@export var start_time: float = 0.3 ## Between 0-1 (0.3 is morning, 0.5 noon) | |||||
@export var time_paused: bool = false | |||||
@export_group("Colors and Intensity") | |||||
@export var moon_color: Gradient | |||||
@export var moon_intensity: Curve | |||||
@export var sun_color: Gradient | |||||
@export var sun_intensity: Curve | |||||
@export var sky_top_color: Gradient | |||||
@export var sky_horizon_color: Gradient | |||||
@export var ground_bottom_color: Gradient | |||||
@export var ground_horizon_color: Gradient | |||||
@export_group("Node Exports") | |||||
@export var environment: WorldEnvironment | |||||
@export var sun: DirectionalLight3D | |||||
@export var moon: DirectionalLight3D | |||||
@onready var tick_rate: float = 1.0 / day_length | |||||
@onready var time: float = start_time ## Between 0-1 (0.5 - noon) | |||||
func _process(delta: float) -> void: | |||||
if time_paused: return | |||||
time += tick_rate * delta | |||||
if time >= 1.0: | |||||
time = 0.0 | |||||
end_of_day.emit() | |||||
# 90 to fix alignment | |||||
sun.rotation_degrees.x = time * 360 + 90 | |||||
sun.light_color = sun_color.sample(time) | |||||
sun.light_energy = sun_intensity.sample(time) | |||||
# 90 to fix alignment | |||||
moon.rotation_degrees.x = time * 360 + 90 + 180 # 180 for opposite of sun | |||||
moon.light_color = moon_color.sample(time) | |||||
moon.light_energy = moon_intensity.sample(time) | |||||
# Show / Hide Sun and Moon | |||||
sun.visible = sun.light_energy > 0 | |||||
moon.visible = moon.light_energy > 0 | |||||
# Sky and Ground Colors | |||||
environment.environment.sky.sky_material.set("sky_top_color", sky_top_color.sample(time)) | |||||
environment.environment.sky.sky_material.set("sky_horizon_color", sky_horizon_color.sample(time)) | |||||
environment.environment.sky.sky_material.set("ground_bottom_color", ground_bottom_color.sample(time)) | |||||
environment.environment.sky.sky_material.set("ground_horizon_color", ground_horizon_color.sample(time)) | |||||
func _ready() -> void: | |||||
pause_time.connect(_on_pause_time) | |||||
resume_time.connect(_on_resume_time) | |||||
set_day_length.connect(_on_set_day_length) | |||||
set_rate_of_time.connect(_on_set_rate_of_time) | |||||
func update_tick_rate(new_rate: float = 1.0) -> void: | |||||
tick_rate = new_rate / day_length | |||||
func _on_pause_time() -> void: | |||||
time_paused = true | |||||
func _on_resume_time() -> void: | |||||
time_paused = true | |||||
func _on_set_day_length(seconds: float) -> void: | |||||
day_length = seconds | |||||
update_tick_rate() | |||||
func _on_set_rate_of_time(new_rate: float) -> void: | |||||
update_tick_rate(new_rate) | |||||
func _on_set_time(new_time: float) -> void: | |||||
time = new_time |
@ -0,0 +1 @@ | |||||
uid://odh7sbmaku32 |
@ -0,0 +1,44 @@ | |||||
[gd_scene load_steps=11 format=3 uid="uid://58cvwtpnkq8r"] | |||||
[ext_resource type="Script" uid="uid://odh7sbmaku32" path="res://scenes/world/day_night_cycle_component.gd" id="1_xc0aj"] | |||||
[ext_resource type="Gradient" uid="uid://bgsedjexjylfr" path="res://resources/world/moon_color_gradient.tres" id="2_65gyo"] | |||||
[ext_resource type="Curve" uid="uid://cmmbliff4tja2" path="res://resources/world/moon_intensity_curve.tres" id="3_bdvt6"] | |||||
[ext_resource type="Gradient" uid="uid://chetnl1mrww83" path="res://resources/world/sun_color_gradient.tres" id="4_yeijk"] | |||||
[ext_resource type="Curve" uid="uid://ds0dqy41plskw" path="res://resources/world/sun_intensity_curve.tres" id="5_wylv2"] | |||||
[ext_resource type="Gradient" uid="uid://d0cpq2rok3jsi" path="res://resources/world/sky_top_color_gradient.tres" id="6_ckt1h"] | |||||
[ext_resource type="Gradient" uid="uid://dvpnjt66dtk46" path="res://resources/world/sky_horizon_color_gradient.tres" id="7_03v7x"] | |||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_4rhad"] | |||||
[sub_resource type="Sky" id="Sky_dphjl"] | |||||
sky_material = SubResource("ProceduralSkyMaterial_4rhad") | |||||
[sub_resource type="Environment" id="Environment_sl2e5"] | |||||
background_mode = 2 | |||||
sky = SubResource("Sky_dphjl") | |||||
tonemap_mode = 2 | |||||
glow_enabled = true | |||||
[node name="DayNightCycleComponent" type="Node3D" node_paths=PackedStringArray("environment", "sun", "moon")] | |||||
script = ExtResource("1_xc0aj") | |||||
moon_color = ExtResource("2_65gyo") | |||||
moon_intensity = ExtResource("3_bdvt6") | |||||
sun_color = ExtResource("4_yeijk") | |||||
sun_intensity = ExtResource("5_wylv2") | |||||
sky_top_color = ExtResource("6_ckt1h") | |||||
sky_horizon_color = ExtResource("7_03v7x") | |||||
ground_bottom_color = ExtResource("6_ckt1h") | |||||
ground_horizon_color = ExtResource("7_03v7x") | |||||
environment = NodePath("WorldEnvironment") | |||||
sun = NodePath("Sun") | |||||
moon = NodePath("Moon") | |||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."] | |||||
environment = SubResource("Environment_sl2e5") | |||||
[node name="Sun" type="DirectionalLight3D" parent="."] | |||||
shadow_enabled = true | |||||
[node name="Moon" type="DirectionalLight3D" parent="."] | |||||
shadow_enabled = true | |||||
sky_mode = 1 |