fix shaders

This commit is contained in:
2026-04-23 15:07:04 +02:00
parent 174ae98242
commit 8b2cbab23b
18 changed files with 255 additions and 171 deletions

View File

@@ -1,16 +1,21 @@
class_name DayNightController
extends Node
const TIME_OPTION_SUNRISE: int = 0
const TIME_OPTION_DAY: int = 1
const TIME_OPTION_SUNSET: int = 2
const TIME_OPTION_NIGHT: int = 3
var environment_config: EnvironmentConfig
#Multiply for debug
@export var time_scale: float = 1.0
@export var paused: bool = false
signal time_changed(time: float)
var current_time: float = 0.0
var _current_time_option_index: int = -1
func _init(environmentconfig: EnvironmentConfig) -> void:
environment_config = environmentconfig
@@ -19,6 +24,7 @@ func _ready() -> void:
#connect events
UIEvents.set_day_time.connect(_on_set_day_time)
UIEvents.toggle_pause_daytime.connect(_on_toggle_pause_daytime)
UIEvents.time_option_item_changed.connect(_time_option_changed)
current_time = environment_config.start_time
update_time(current_time)
@@ -44,9 +50,34 @@ func set_time(t: float) -> void:
update_time(current_time)
func update_time(currtime: float) -> void:
var time_option_index: int = get_time_option_index(currtime)
if time_option_index != _current_time_option_index:
_current_time_option_index = time_option_index
UIEvents.day_time_option_changed.emit(time_option_index)
emit_signal("time_changed", currtime)
UIEvents.day_time_changed.emit(currtime, get_time_string())
func get_time_option_index(currtime: float) -> int:
if currtime >= environment_config.night or currtime < environment_config.sunrise:
return TIME_OPTION_NIGHT
if currtime < environment_config.day:
return TIME_OPTION_SUNRISE
if currtime < environment_config.sunset:
return TIME_OPTION_DAY
return TIME_OPTION_SUNSET
func _time_option_changed(index: int) -> void:
match index:
TIME_OPTION_SUNRISE:
set_time(environment_config.sunrise)
TIME_OPTION_DAY:
set_time(environment_config.day)
TIME_OPTION_SUNSET:
set_time(environment_config.sunset)
TIME_OPTION_NIGHT:
set_time(environment_config.night)
func _on_set_day_time(value: float) -> void:
set_time(value)

View File

@@ -98,6 +98,14 @@ func ApplyWeatherShaderToMaterials():
if child is GeometryInstance3D:
child.material_overlay = weather_shader
for node in get_tree().get_nodes_in_group("weather_vegetables_node"):
if node is GeometryInstance3D:
node.material_overlay = weather_shader
else:
for child in node.get_children():
if child is GeometryInstance3D:
child.material_overlay = weather_shader
func select_day_time(normalized_time: float) -> void:
#set show_day_time_debug = true to show debug on screen
#normalized_time is a value between 0 and 1; the time of the day is calculate as "normalized_time" * 1440; day_time is the step to pass from sunrise, to day, to sunset, to night

View File

@@ -29,3 +29,7 @@ signal toggle_shadows(value: bool)
signal toggle_pause_daytime(value: bool)
@warning_ignore("unused_signal")
signal day_time_changed(value: float, time_string: String)
@warning_ignore("unused_signal")
signal time_option_item_changed(index: int)
@warning_ignore("unused_signal")
signal day_time_option_changed(index: int)