Merge branch 'main' into game_menu
This commit is contained in:
@@ -39,6 +39,7 @@ var weather_controller: WeatherController
|
||||
var day_tween: Tween
|
||||
var day_time: float = 0.0
|
||||
var pending_environment_nodes: Dictionary = {}
|
||||
var weather_shader_no_noise: Material
|
||||
|
||||
func _ready() -> void:
|
||||
|
||||
@@ -80,6 +81,9 @@ func _ready() -> void:
|
||||
weather_controller.name = "WeatherController"
|
||||
add_child(weather_controller)
|
||||
|
||||
if day_night_controller != null:
|
||||
select_day_time(day_night_controller.current_time)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
_process_pending_environment_nodes()
|
||||
|
||||
@@ -135,10 +139,10 @@ func _apply_dynamic_environment_materials(node: Node) -> void:
|
||||
if node.is_in_group("wind_node"):
|
||||
_apply_wind_noise_to_node(node, NOISE_TEXTURE)
|
||||
|
||||
if node.is_in_group("weather_node"):
|
||||
_apply_weather_overlay_to_node(node, WEATHER_SHADER)
|
||||
if node.is_in_group("weather_node") or node.is_in_group("weather_vegetables_node"):
|
||||
_apply_weather_overlay_to_node(node, _get_weather_overlay_material(node))
|
||||
|
||||
if _should_clear_weather_overlay(node):
|
||||
if _should_ignore_weather_overlay(node):
|
||||
_clear_weather_overlay_from_node(node)
|
||||
|
||||
func ApplyWindNoiseToMaterials():
|
||||
@@ -162,19 +166,30 @@ func _apply_wind_noise_to_node(node: Node, noise_tex: Texture2D) -> void:
|
||||
|
||||
func ApplyWeatherShaderToMaterials():
|
||||
for node in get_tree().get_nodes_in_group("weather_node"):
|
||||
_apply_weather_overlay_to_node(node, WEATHER_SHADER)
|
||||
_apply_weather_overlay_to_node(node, _get_weather_overlay_material(node))
|
||||
|
||||
for node in get_tree().get_nodes_in_group("weather_vegetables_node"):
|
||||
if _should_clear_weather_overlay(node):
|
||||
_clear_weather_overlay_from_node(node)
|
||||
_apply_weather_overlay_to_node(node, _get_weather_overlay_material(node))
|
||||
|
||||
func _get_weather_overlay_material(node: Node) -> Material:
|
||||
if not node.is_in_group("weather_overlay_no_noise"):
|
||||
return WEATHER_SHADER
|
||||
|
||||
if weather_shader_no_noise == null:
|
||||
weather_shader_no_noise = WEATHER_SHADER.duplicate() as Material
|
||||
var shader_material := weather_shader_no_noise as ShaderMaterial
|
||||
if shader_material:
|
||||
shader_material.set_shader_parameter("snow_noise_enabled", false)
|
||||
|
||||
return weather_shader_no_noise
|
||||
|
||||
func _apply_weather_overlay_to_node(node: Node, material: Material) -> void:
|
||||
if _should_clear_weather_overlay(node):
|
||||
if _should_ignore_weather_overlay(node):
|
||||
_clear_weather_overlay_from_node(node)
|
||||
return
|
||||
|
||||
if node is GeometryInstance3D:
|
||||
if _geometry_uses_alpha_texture(node):
|
||||
if _should_clear_weather_overlay(node) or _geometry_uses_alpha_texture(node):
|
||||
node.material_overlay = null
|
||||
else:
|
||||
node.material_overlay = material
|
||||
@@ -214,6 +229,9 @@ func _shader_material_uses_alpha_texture(material: ShaderMaterial) -> bool:
|
||||
|
||||
return material.shader.code.find("alpha_texture") != -1
|
||||
|
||||
func _should_ignore_weather_overlay(node: Node) -> bool:
|
||||
return node.is_in_group("weather_overlay_ignore")
|
||||
|
||||
func _should_clear_weather_overlay(node: Node) -> bool:
|
||||
return node.is_in_group("weather_vegetables_node")
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ var is_storm: bool = false
|
||||
var cold_tween: Tween
|
||||
var wind_tween: Tween
|
||||
var is_windy: bool = false
|
||||
var thereare_fireflies: bool = false
|
||||
var thereare_fireflies: bool = true
|
||||
var current_wind_speed: float = 0.0
|
||||
var current_wind_strength: float = 0.0
|
||||
var current_wind_fade: float = 0.0
|
||||
@@ -128,10 +128,8 @@ func _process(delta: float) -> void:
|
||||
|
||||
_follow_camera()
|
||||
|
||||
var is_night = day_time >= 2.5
|
||||
if particles_fireflies:
|
||||
particles_fireflies.emitting = thereare_fireflies and is_night and not is_raining and not is_snowing and not is_storm
|
||||
|
||||
_update_fireflies_visibility()
|
||||
|
||||
var base_tint: Color
|
||||
var base_sky_top: Color
|
||||
var base_sky_horizon: Color
|
||||
@@ -197,11 +195,9 @@ func _process(delta: float) -> void:
|
||||
var final_fog_color = base_fog_color.lerp(base_fog_color * weather_color, clamp(rain_intensity, 0.0, 1.0))
|
||||
var final_fog_density = lerp(base_fog_density, base_fog_density * 4.0, clamp(rain_intensity, 0.0, 1.0))
|
||||
var final_water_color = base_water_color.darkened(clamp(environment_config.water_darkening_rain, 0.0, 1.0) * clamp(rain_intensity, 0.0, 1.0))
|
||||
var rain_weather_amount: float = 0.0
|
||||
if is_raining:
|
||||
rain_weather_amount = clamp(rain_intensity, 0.0, 1.0)
|
||||
var rain_weather_amount: float = clamp(rain_intensity, 0.0, 1.0)
|
||||
var storm_weather_amount: float = 0.0
|
||||
if is_raining and is_storm:
|
||||
if is_storm:
|
||||
if environment_config.storm_rain_intensity_multiplier > 1.0:
|
||||
storm_weather_amount = clamp((rain_intensity - 1.0) / (environment_config.storm_rain_intensity_multiplier - 1.0), 0.0, 1.0)
|
||||
else:
|
||||
@@ -389,9 +385,7 @@ func _follow_camera() -> void:
|
||||
|
||||
func toggle_fireflies(value: bool):
|
||||
thereare_fireflies = value
|
||||
var is_night = day_time >= 2.5
|
||||
if particles_fireflies:
|
||||
particles_fireflies.emitting = thereare_fireflies and is_night and not is_raining
|
||||
_update_fireflies_visibility()
|
||||
|
||||
#disable fireflies and set default values and materials
|
||||
func init_fireflies():
|
||||
@@ -402,7 +396,16 @@ func init_fireflies():
|
||||
var proc_mat = particles_fireflies.process_material as ParticleProcessMaterial
|
||||
if proc_mat:
|
||||
proc_mat.emission_box_extents = Vector3(environment_config.fireflies_spawn_ray, environment_config.fireflies_spawn_height, environment_config.fireflies_spawn_ray)
|
||||
|
||||
_update_fireflies_visibility()
|
||||
|
||||
func _should_show_fireflies() -> bool:
|
||||
var is_night: bool = day_time >= 2.5
|
||||
return thereare_fireflies and is_night and not is_raining and not is_snowing and not is_storm
|
||||
|
||||
func _update_fireflies_visibility() -> void:
|
||||
if particles_fireflies:
|
||||
particles_fireflies.emitting = _should_show_fireflies()
|
||||
|
||||
#endregion
|
||||
|
||||
#region Wind
|
||||
@@ -410,7 +413,7 @@ func init_fireflies():
|
||||
func toggle_wind(value: bool):
|
||||
is_windy = value
|
||||
if particles_wind:
|
||||
particles_wind.emitting = is_windy
|
||||
particles_wind.emitting = true
|
||||
|
||||
_apply_wind_state()
|
||||
_emit_weather_event_label()
|
||||
@@ -420,7 +423,7 @@ func init_wind():
|
||||
_update_wind_amount_from_strength(environment_config.wind_strength)
|
||||
if particles_wind:
|
||||
particles_wind.visible = true
|
||||
particles_wind.emitting = false
|
||||
particles_wind.emitting = true
|
||||
particles_wind.amount = environment_config.wind_amount
|
||||
var proc_mat_wind = particles_wind.process_material as ParticleProcessMaterial
|
||||
if proc_mat_wind:
|
||||
@@ -451,6 +454,11 @@ func _apply_wind_config() -> void:
|
||||
|
||||
_apply_wind_state(true)
|
||||
|
||||
func _get_target_wind_strength() -> float:
|
||||
if is_windy:
|
||||
return environment_config.wind_boost_strength
|
||||
return environment_config.wind_strength
|
||||
|
||||
func _apply_wind_state(immediate: bool = false) -> void:
|
||||
if environment_config == null:
|
||||
return
|
||||
@@ -458,20 +466,23 @@ func _apply_wind_state(immediate: bool = false) -> void:
|
||||
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
|
||||
var active_wind_fade := 1.0 if is_windy else 0.0
|
||||
if particles_wind:
|
||||
particles_wind.emitting = true
|
||||
|
||||
var active_wind_speed := environment_config.wind_speed
|
||||
var active_wind_strength := _get_target_wind_strength()
|
||||
var active_wind_fade := 1.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)
|
||||
_set_current_wind_speed(active_wind_speed)
|
||||
_set_current_wind_fade(active_wind_fade)
|
||||
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)
|
||||
wind_tween.tween_method(_set_current_wind_strength, current_wind_strength, active_wind_strength, environment_config.wind_fade_in_out_time)
|
||||
wind_tween.tween_callback(_finish_wind_transition)
|
||||
|
||||
func _set_current_wind_speed(value: float) -> void:
|
||||
current_wind_speed = value
|
||||
@@ -481,6 +492,7 @@ func _set_current_wind_speed(value: float) -> void:
|
||||
func _set_current_wind_strength(value: float) -> void:
|
||||
current_wind_strength = value
|
||||
RenderingServer.global_shader_parameter_set("global_wind_strength", value)
|
||||
_set_wind_particles_amount_from_strength(value)
|
||||
_sync_wind_event_state()
|
||||
|
||||
func _set_current_wind_fade(value: float) -> void:
|
||||
@@ -494,13 +506,10 @@ func _sync_wind_event_state() -> void:
|
||||
#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:
|
||||
if is_windy:
|
||||
return
|
||||
|
||||
_set_current_wind_speed(0.0)
|
||||
_set_current_wind_strength(0.0)
|
||||
_set_current_wind_fade(0.0)
|
||||
func _finish_wind_transition() -> void:
|
||||
_set_current_wind_speed(environment_config.wind_speed)
|
||||
_set_current_wind_strength(_get_target_wind_strength())
|
||||
_set_current_wind_fade(1.0)
|
||||
|
||||
func change_wind_strength(value: float) -> void:
|
||||
if environment_config == null:
|
||||
@@ -508,10 +517,11 @@ func change_wind_strength(value: float) -> void:
|
||||
|
||||
environment_config.wind_strength = value
|
||||
_update_wind_amount_from_strength(value)
|
||||
if is_windy or current_wind_fade > 0.0:
|
||||
if current_wind_fade > 0.0 and not is_windy:
|
||||
_set_current_wind_strength(value)
|
||||
if particles_wind:
|
||||
particles_wind.amount = environment_config.wind_amount
|
||||
_apply_wind_state()
|
||||
|
||||
func _update_wind_amount_from_strength(value: float) -> void:
|
||||
if environment_config == null:
|
||||
@@ -519,12 +529,22 @@ func _update_wind_amount_from_strength(value: float) -> void:
|
||||
if max_wind_amount <= 0:
|
||||
max_wind_amount = max(environment_config.wind_amount, 1)
|
||||
|
||||
environment_config.wind_amount = _get_wind_particles_amount_from_strength(value)
|
||||
|
||||
func _get_wind_particles_amount_from_strength(value: float) -> int:
|
||||
if max_wind_amount <= 0:
|
||||
max_wind_amount = 1
|
||||
|
||||
var normalized_strength: float = clamp(value, 0.0, 1.0)
|
||||
var amount_ratio: float = normalized_strength
|
||||
if normalized_strength > 0.0 and normalized_strength < 0.3:
|
||||
amount_ratio = lerp(0.08, 0.25, normalized_strength / 0.3)
|
||||
|
||||
environment_config.wind_amount = roundi(max_wind_amount * amount_ratio)
|
||||
return roundi(max_wind_amount * amount_ratio)
|
||||
|
||||
func _set_wind_particles_amount_from_strength(value: float) -> void:
|
||||
if particles_wind:
|
||||
particles_wind.amount = _get_wind_particles_amount_from_strength(value)
|
||||
|
||||
func trigger_random_weather_event(duration: float = 0.0) -> void:
|
||||
if random_weather_restore_tween and random_weather_restore_tween.is_valid():
|
||||
|
||||
@@ -17,6 +17,7 @@ global uniform float global_snow_cap_flatness_end = 0.96;
|
||||
global uniform float global_snow_cap_noise_scale = 0.22;
|
||||
global uniform float global_snow_cap_noise_strength = 0.18;
|
||||
const float SNOW_VISUAL_RESPONSE = 0.55;
|
||||
uniform bool snow_noise_enabled = true;
|
||||
uniform float snow_noise_scale : hint_range(0.01, 1.0) = 0.15;
|
||||
uniform float snow_edge_softness : hint_range(0.01, 0.5) = 0.2;
|
||||
uniform float snow_roughness_variation : hint_range(0.0, 0.3) = 0.15;
|
||||
@@ -92,6 +93,10 @@ float get_visual_snow_progress(float snow_progress) {
|
||||
}
|
||||
|
||||
float get_snow_noise_mask(vec3 world_pos, float snow_progress) {
|
||||
if (!snow_noise_enabled) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float detail_noise = texture(noise_texture, world_pos.xz * snow_noise_scale).r;
|
||||
float broad_noise = texture(noise_texture, world_pos.xz * snow_noise_scale * 0.35 + vec2(19.1, 7.4)).r;
|
||||
float combined_noise = mix(detail_noise, broad_noise, 0.35);
|
||||
@@ -118,7 +123,7 @@ void vertex() {
|
||||
world_normal.y
|
||||
);
|
||||
float accumulation_growth = smoothstep(0.02, 0.45, snow_progress);
|
||||
float cap_noise = fbm(world_pos.xz * global_snow_cap_noise_scale + vec2(11.3, 4.7));
|
||||
float cap_noise = snow_noise_enabled ? fbm(world_pos.xz * global_snow_cap_noise_scale + vec2(11.3, 4.7)) : 0.5;
|
||||
float cap_variation = mix(1.0 - global_snow_cap_noise_strength, 1.0 + global_snow_cap_noise_strength, cap_noise);
|
||||
|
||||
v_snow_amount = snow_progress;
|
||||
@@ -133,7 +138,7 @@ void fragment() {
|
||||
float facing_up = clamp(world_normal.y, 0.0, 1.0);
|
||||
vec3 geometric_normal = normalize(cross(dFdx(world_pos), dFdy(world_pos)));
|
||||
float snow_facing_up = max(facing_up, abs(geometric_normal.y));
|
||||
float noise_val = texture(noise_texture, world_pos.xz * snow_noise_scale).r;
|
||||
float noise_val = snow_noise_enabled ? texture(noise_texture, world_pos.xz * snow_noise_scale).r : 0.5;
|
||||
|
||||
//Snow
|
||||
float snow_progress = v_snow_amount;
|
||||
|
||||
Reference in New Issue
Block a user