add wind fade in/out + add wire movement when is windy
This commit is contained in:
@@ -2,6 +2,7 @@ shader_type canvas_item;
|
||||
|
||||
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
|
||||
global uniform float global_wind_speed;
|
||||
global uniform float global_wind_fade;
|
||||
|
||||
uniform vec4 dust_color : source_color = vec4(1.0, 0.456, 0.125, 0.6);
|
||||
|
||||
@@ -30,7 +31,7 @@ void fragment() {
|
||||
float base_time = TIME * dust_speed;
|
||||
|
||||
vec2 osc = vec2(sin(TIME * 0.5), cos(TIME * 0.3)) * wind_oscillation;
|
||||
float wind_active = step(0.0001, abs(global_wind_speed));
|
||||
float wind_active = global_wind_fade * step(0.0001, abs(global_wind_speed));
|
||||
vec2 final_wind = ((wind_speed + osc) * dust_speed) * wind_active;
|
||||
|
||||
float final_particle_alpha = 0.0;
|
||||
|
||||
@@ -5,6 +5,7 @@ global uniform float global_wind_speed;
|
||||
global uniform vec2 global_wind_direction;
|
||||
global uniform float global_wind_scale;
|
||||
global uniform float global_wind_strength;
|
||||
global uniform float global_wind_fade;
|
||||
global uniform float global_snow_start_time;
|
||||
global uniform float global_snow_accumulation_speed;
|
||||
global uniform float global_snow_melt_time;
|
||||
@@ -43,12 +44,12 @@ void vertex() {
|
||||
vec3 instance_pos = MODEL_MATRIX[3].xyz;
|
||||
|
||||
float total_angle = radians(rotation_degrees);
|
||||
if (wind_enabled && global_wind_speed > 0.0 && global_wind_strength > 0.0) {
|
||||
if (wind_enabled && global_wind_speed > 0.0 && global_wind_strength > 0.0 && global_wind_fade > 0.0) {
|
||||
float time = TIME * global_wind_speed;
|
||||
vec2 noise_uv = (instance_pos.xz * global_wind_scale) + (time * global_wind_direction * 0.5);
|
||||
float noise_val = textureLod(wind_noise, noise_uv, 2.0).r;
|
||||
float sway = sin(time + (noise_val * 10.0));
|
||||
total_angle += (sway * global_wind_strength);
|
||||
total_angle += (sway * global_wind_strength * global_wind_fade);
|
||||
}
|
||||
|
||||
float h_factor = clamp((instance_pos.y - height_min) / (height_max - height_min), 0.0, 1.0);
|
||||
|
||||
@@ -42,8 +42,12 @@ var actual_snow_amount: float = 0.0
|
||||
|
||||
var is_storm: bool = false
|
||||
var cold_tween: Tween
|
||||
var wind_tween: Tween
|
||||
var is_windy: bool = false
|
||||
var thereare_fireflies: bool = false
|
||||
var current_wind_speed: float = 0.0
|
||||
var current_wind_strength: float = 0.0
|
||||
var current_wind_fade: float = 0.0
|
||||
|
||||
func _init(wind: GPUParticles3D, snow: GPUParticles3D,
|
||||
fireflies: GPUParticles3D, rain: GPUParticles3D, ray: PackedScene,
|
||||
@@ -91,6 +95,7 @@ func _ready() -> void:
|
||||
UIEvents.toggle_rain.connect(toggle_rain)
|
||||
UIEvents.toggle_snow.connect(toggle_snow)
|
||||
UIEvents.toggle_wind.connect(toggle_wind)
|
||||
UIEvents.wind_change.connect(change_wind_strength)
|
||||
UIEvents.toggle_fireflies.connect(toggle_fireflies)
|
||||
UIEvents.toggle_storm.connect(toggle_storm)
|
||||
UIEvents.toggle_dust.connect(toggle_dust)
|
||||
@@ -334,16 +339,57 @@ func _apply_wind_config() -> void:
|
||||
proc_mat_wind.direction = wind_axis
|
||||
particles_wind.global_transform = Transform3D(Basis(wind_cross, wind_axis, wind_up), particles_wind.global_position)
|
||||
|
||||
_apply_wind_state()
|
||||
_apply_wind_state(true)
|
||||
|
||||
func _apply_wind_state() -> void:
|
||||
func _apply_wind_state(immediate: bool = false) -> void:
|
||||
if environment_config == null:
|
||||
return
|
||||
|
||||
if wind_tween and wind_tween.is_valid():
|
||||
wind_tween.kill()
|
||||
|
||||
var active_wind_speed := environment_config.wind_speed if is_windy else 0.0
|
||||
var active_wind_strength := environment_config.wind_strength if is_windy else 0.0
|
||||
RenderingServer.global_shader_parameter_set("global_wind_speed", active_wind_speed)
|
||||
RenderingServer.global_shader_parameter_set("global_wind_strength", active_wind_strength)
|
||||
var active_wind_fade := 1.0 if is_windy else 0.0
|
||||
if immediate:
|
||||
_set_current_wind_speed(active_wind_speed)
|
||||
_set_current_wind_strength(active_wind_strength)
|
||||
_set_current_wind_fade(active_wind_fade)
|
||||
return
|
||||
|
||||
_set_current_wind_speed(environment_config.wind_speed)
|
||||
_set_current_wind_strength(environment_config.wind_strength)
|
||||
wind_tween = create_tween()
|
||||
wind_tween.tween_method(_set_current_wind_fade, current_wind_fade, active_wind_fade, environment_config.wind_fade_in_out_time)
|
||||
wind_tween.tween_callback(_finish_wind_fade_out)
|
||||
|
||||
func _set_current_wind_speed(value: float) -> void:
|
||||
current_wind_speed = value
|
||||
RenderingServer.global_shader_parameter_set("global_wind_speed", value)
|
||||
|
||||
func _set_current_wind_strength(value: float) -> void:
|
||||
current_wind_strength = value
|
||||
RenderingServer.global_shader_parameter_set("global_wind_strength", value)
|
||||
|
||||
func _set_current_wind_fade(value: float) -> void:
|
||||
current_wind_fade = value
|
||||
RenderingServer.global_shader_parameter_set("global_wind_fade", value)
|
||||
|
||||
func _finish_wind_fade_out() -> void:
|
||||
if is_windy:
|
||||
return
|
||||
|
||||
_set_current_wind_speed(0.0)
|
||||
_set_current_wind_strength(0.0)
|
||||
_set_current_wind_fade(0.0)
|
||||
|
||||
func change_wind_strength(value: float) -> void:
|
||||
if environment_config == null:
|
||||
return
|
||||
|
||||
environment_config.wind_strength = value
|
||||
if is_windy or current_wind_fade > 0.0:
|
||||
_set_current_wind_strength(value)
|
||||
|
||||
func _apply_cloud_config() -> void:
|
||||
var dir = environment_config.wind_direction
|
||||
|
||||
Reference in New Issue
Block a user