fix wind and make compatible wind_decoration
This commit is contained in:
@@ -56,7 +56,7 @@ void fragment() {
|
|||||||
} else {
|
} else {
|
||||||
vec2 projected_xz = world_pos.xz + (world_pos.y * sun_angle);
|
vec2 projected_xz = world_pos.xz + (world_pos.y * sun_angle);
|
||||||
vec2 uv = projected_xz * cloud_scale;
|
vec2 uv = projected_xz * cloud_scale;
|
||||||
uv += TIME * cloud_speed * direction;
|
uv -= TIME * cloud_speed * direction;
|
||||||
|
|
||||||
float n = texture(noise_texture, uv).r;
|
float n = texture(noise_texture, uv).r;
|
||||||
|
|
||||||
@@ -71,4 +71,4 @@ void fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ void sky() {
|
|||||||
|
|
||||||
//Clouds
|
//Clouds
|
||||||
vec2 cloud_uv = EYEDIR.xz / (EYEDIR.y + 0.5);
|
vec2 cloud_uv = EYEDIR.xz / (EYEDIR.y + 0.5);
|
||||||
cloud_uv = cloud_uv * cloud_scale + (TIME * cloud_direction * cloud_speed);
|
cloud_uv = cloud_uv * cloud_scale - (TIME * cloud_direction * cloud_speed);
|
||||||
float noise = texture(cloud_noise, cloud_uv).r;
|
float noise = texture(cloud_noise, cloud_uv).r;
|
||||||
float cloud_alpha = smoothstep(cloud_threshold, cloud_threshold + cloud_edge_softness, noise);
|
float cloud_alpha = smoothstep(cloud_threshold, cloud_threshold + cloud_edge_softness, noise);
|
||||||
float color_gradient = smoothstep(cloud_threshold, cloud_threshold + cloud_edge_thickness, noise);
|
float color_gradient = smoothstep(cloud_threshold, cloud_threshold + cloud_edge_thickness, noise);
|
||||||
@@ -136,4 +136,4 @@ void sky() {
|
|||||||
final_sky = mix(final_sky, current_cloud_color, cloud_alpha);
|
final_sky = mix(final_sky, current_cloud_color, cloud_alpha);
|
||||||
|
|
||||||
COLOR = final_sky;
|
COLOR = final_sky;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
class_name WeatherController
|
class_name WeatherController
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
signal wind_parameters_changed(speed: float, strength: float, fade: float, direction: Vector2)
|
||||||
|
|
||||||
var thunder_audio_player: AudioStreamPlayer
|
var thunder_audio_player: AudioStreamPlayer
|
||||||
var thunder_sounds: Array[AudioStream]
|
var thunder_sounds: Array[AudioStream]
|
||||||
var rain_sounds: Array[AudioStream]
|
var rain_sounds: Array[AudioStream]
|
||||||
@@ -101,6 +103,8 @@ func _init(wind: GPUParticles3D, snow: GPUParticles3D,
|
|||||||
camera_pivot.get_node("pivot").camera_changed.connect(_set_camera)
|
camera_pivot.get_node("pivot").camera_changed.connect(_set_camera)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
#used for wind change state (wind_decoration)
|
||||||
|
add_to_group("weather_controller")
|
||||||
|
|
||||||
#connect events
|
#connect events
|
||||||
UIEvents.toggle_rain.connect(toggle_rain)
|
UIEvents.toggle_rain.connect(toggle_rain)
|
||||||
@@ -439,7 +443,7 @@ func _apply_wind_config() -> void:
|
|||||||
else:
|
else:
|
||||||
wind_cross = wind_cross.normalized()
|
wind_cross = wind_cross.normalized()
|
||||||
var wind_up := wind_cross.cross(wind_axis).normalized()
|
var wind_up := wind_cross.cross(wind_axis).normalized()
|
||||||
proc_mat_wind.direction = wind_axis
|
proc_mat_wind.direction = Vector3.UP
|
||||||
particles_wind.global_transform = Transform3D(Basis(wind_cross, wind_axis, wind_up), particles_wind.global_position)
|
particles_wind.global_transform = Transform3D(Basis(wind_cross, wind_axis, wind_up), particles_wind.global_position)
|
||||||
|
|
||||||
_apply_wind_state(true)
|
_apply_wind_state(true)
|
||||||
@@ -469,14 +473,23 @@ func _apply_wind_state(immediate: bool = false) -> void:
|
|||||||
func _set_current_wind_speed(value: float) -> void:
|
func _set_current_wind_speed(value: float) -> void:
|
||||||
current_wind_speed = value
|
current_wind_speed = value
|
||||||
RenderingServer.global_shader_parameter_set("global_wind_speed", value)
|
RenderingServer.global_shader_parameter_set("global_wind_speed", value)
|
||||||
|
_sync_wind_event_state()
|
||||||
|
|
||||||
func _set_current_wind_strength(value: float) -> void:
|
func _set_current_wind_strength(value: float) -> void:
|
||||||
current_wind_strength = value
|
current_wind_strength = value
|
||||||
RenderingServer.global_shader_parameter_set("global_wind_strength", value)
|
RenderingServer.global_shader_parameter_set("global_wind_strength", value)
|
||||||
|
_sync_wind_event_state()
|
||||||
|
|
||||||
func _set_current_wind_fade(value: float) -> void:
|
func _set_current_wind_fade(value: float) -> void:
|
||||||
current_wind_fade = value
|
current_wind_fade = value
|
||||||
RenderingServer.global_shader_parameter_set("global_wind_fade", value)
|
RenderingServer.global_shader_parameter_set("global_wind_fade", value)
|
||||||
|
_sync_wind_event_state()
|
||||||
|
|
||||||
|
func _sync_wind_event_state() -> void:
|
||||||
|
if environment_config == null:
|
||||||
|
return
|
||||||
|
#used to notify wind_decoration when wind change state
|
||||||
|
wind_parameters_changed.emit(current_wind_speed, current_wind_strength, current_wind_fade, environment_config.wind_direction)
|
||||||
|
|
||||||
func _finish_wind_fade_out() -> void:
|
func _finish_wind_fade_out() -> void:
|
||||||
if is_windy:
|
if is_windy:
|
||||||
|
|||||||
@@ -10,8 +10,17 @@ extends Node3D
|
|||||||
|
|
||||||
var tempo: float = 0.0
|
var tempo: float = 0.0
|
||||||
var offset_iniziale: float = 0.0
|
var offset_iniziale: float = 0.0
|
||||||
|
var _base_transform: Transform3D
|
||||||
|
var _wind_speed: float = 0.0
|
||||||
|
var _wind_strength: float = 0.0
|
||||||
|
var _wind_fade: float = 0.0
|
||||||
|
var _wind_direction: Vector2 = Vector2.ZERO
|
||||||
|
var _weather_controller: WeatherController
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
_base_transform = transform
|
||||||
|
call_deferred("_bind_weather_controller")
|
||||||
|
|
||||||
func _ready():
|
|
||||||
if sfasamento_casuale:
|
if sfasamento_casuale:
|
||||||
# Usiamo la posizione nel mondo per dare un ritmo diverso a ogni casa
|
# Usiamo la posizione nel mondo per dare un ritmo diverso a ogni casa
|
||||||
offset_iniziale = global_position.x + global_position.z
|
offset_iniziale = global_position.x + global_position.z
|
||||||
@@ -19,11 +28,48 @@ func _ready():
|
|||||||
# Partiamo da un punto casuale del ciclo per spezzare la monotonia
|
# Partiamo da un punto casuale del ciclo per spezzare la monotonia
|
||||||
tempo = randf_range(0.0, 10.0)
|
tempo = randf_range(0.0, 10.0)
|
||||||
|
|
||||||
func _process(delta: float):
|
func _process(delta: float) -> void:
|
||||||
tempo += delta * velocita
|
var wind_direction_3d := Vector3(_wind_direction.x, 0.0, _wind_direction.y)
|
||||||
|
|
||||||
# Calcoliamo l'angolo usando il seno
|
if _wind_speed <= 0.0 or _wind_strength <= 0.0 or _wind_fade <= 0.0 or wind_direction_3d.length_squared() <= 0.0:
|
||||||
var angolo = sin(tempo + offset_iniziale) * deg_to_rad(ampiezza_gradi)
|
transform = _base_transform
|
||||||
|
return
|
||||||
# Applichiamo la rotazione sull'asse X (avanti/indietro)
|
|
||||||
rotation.x = angolo
|
tempo += delta * _wind_speed * velocita
|
||||||
|
wind_direction_3d = wind_direction_3d.normalized()
|
||||||
|
|
||||||
|
# Ruota attorno all'asse perpendicolare alla direzione del vento, così il decoro oscilla
|
||||||
|
# nello stesso verso usato dai global shader parameter di foglie/erba.
|
||||||
|
var sway_axis_world := Vector3.UP.cross(wind_direction_3d).normalized()
|
||||||
|
var sway_axis_local := sway_axis_world
|
||||||
|
if get_parent() is Node3D:
|
||||||
|
var parent_node := get_parent() as Node3D
|
||||||
|
sway_axis_local = parent_node.global_basis.orthonormalized().inverse() * sway_axis_world
|
||||||
|
|
||||||
|
var angle := sin(tempo + offset_iniziale) * deg_to_rad(ampiezza_gradi) * _wind_strength * _wind_fade
|
||||||
|
var sway_basis := Basis(sway_axis_local.normalized(), angle)
|
||||||
|
transform = Transform3D(sway_basis * _base_transform.basis, _base_transform.origin)
|
||||||
|
|
||||||
|
func _on_wind_parameters_changed(speed: float, strength: float, fade: float, direction: Vector2) -> void:
|
||||||
|
_wind_speed = speed
|
||||||
|
_wind_strength = strength
|
||||||
|
_wind_fade = fade
|
||||||
|
_wind_direction = direction
|
||||||
|
|
||||||
|
func _bind_weather_controller() -> void:
|
||||||
|
#connect to wind_change_state
|
||||||
|
_weather_controller = get_tree().get_first_node_in_group("weather_controller") as WeatherController
|
||||||
|
if _weather_controller == null:
|
||||||
|
return
|
||||||
|
if not _weather_controller.wind_parameters_changed.is_connected(_on_wind_parameters_changed):
|
||||||
|
_weather_controller.wind_parameters_changed.connect(_on_wind_parameters_changed)
|
||||||
|
|
||||||
|
var wind_direction := Vector2.ZERO
|
||||||
|
if _weather_controller.environment_config != null:
|
||||||
|
wind_direction = _weather_controller.environment_config.wind_direction
|
||||||
|
_on_wind_parameters_changed(
|
||||||
|
_weather_controller.current_wind_speed,
|
||||||
|
_weather_controller.current_wind_strength,
|
||||||
|
_weather_controller.current_wind_fade,
|
||||||
|
wind_direction
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user