fix rain
This commit is contained in:
@@ -3,7 +3,6 @@ extends Node3D
|
|||||||
|
|
||||||
const NOISE_TEXTURE: Texture2D = preload("res://core/daynight/noise.tres")
|
const NOISE_TEXTURE: Texture2D = preload("res://core/daynight/noise.tres")
|
||||||
const WEATHER_SHADER: Material = preload("res://core/daynight/weather_overlay.tres")
|
const WEATHER_SHADER: Material = preload("res://core/daynight/weather_overlay.tres")
|
||||||
const WEATHER_PLAIN_SHADER: Material = preload("res://core/daynight/weather_plain_shader.tres")
|
|
||||||
const DYNAMIC_ENVIRONMENT_UPDATES_PER_FRAME: int = 2 #how many update of the environment (apply materials) will be done per frame
|
const DYNAMIC_ENVIRONMENT_UPDATES_PER_FRAME: int = 2 #how many update of the environment (apply materials) will be done per frame
|
||||||
|
|
||||||
@export var environment_config: EnvironmentConfig
|
@export var environment_config: EnvironmentConfig
|
||||||
@@ -134,7 +133,7 @@ func _apply_dynamic_environment_materials(node: Node) -> void:
|
|||||||
_apply_weather_overlay_to_node(node, WEATHER_SHADER)
|
_apply_weather_overlay_to_node(node, WEATHER_SHADER)
|
||||||
|
|
||||||
if node.is_in_group("weather_vegetables_node"):
|
if node.is_in_group("weather_vegetables_node"):
|
||||||
_apply_weather_overlay_to_node(node, WEATHER_PLAIN_SHADER)
|
_clear_weather_overlay_from_node(node)
|
||||||
|
|
||||||
func ApplyWindNoiseToMaterials():
|
func ApplyWindNoiseToMaterials():
|
||||||
for node in get_tree().get_nodes_in_group("wind_node"):
|
for node in get_tree().get_nodes_in_group("wind_node"):
|
||||||
@@ -160,15 +159,50 @@ func ApplyWeatherShaderToMaterials():
|
|||||||
_apply_weather_overlay_to_node(node, WEATHER_SHADER)
|
_apply_weather_overlay_to_node(node, WEATHER_SHADER)
|
||||||
|
|
||||||
for node in get_tree().get_nodes_in_group("weather_vegetables_node"):
|
for node in get_tree().get_nodes_in_group("weather_vegetables_node"):
|
||||||
_apply_weather_overlay_to_node(node, WEATHER_PLAIN_SHADER)
|
_clear_weather_overlay_from_node(node)
|
||||||
|
|
||||||
func _apply_weather_overlay_to_node(node: Node, material: Material) -> void:
|
func _apply_weather_overlay_to_node(node: Node, material: Material) -> void:
|
||||||
if node is GeometryInstance3D:
|
if node is GeometryInstance3D:
|
||||||
|
if _geometry_uses_alpha_texture(node):
|
||||||
|
node.material_overlay = null
|
||||||
|
else:
|
||||||
node.material_overlay = material
|
node.material_overlay = material
|
||||||
|
|
||||||
for child in node.get_children():
|
for child in node.get_children():
|
||||||
_apply_weather_overlay_to_node(child, material)
|
_apply_weather_overlay_to_node(child, material)
|
||||||
|
|
||||||
|
func _clear_weather_overlay_from_node(node: Node) -> void:
|
||||||
|
if node is GeometryInstance3D:
|
||||||
|
node.material_overlay = null
|
||||||
|
|
||||||
|
for child in node.get_children():
|
||||||
|
_clear_weather_overlay_from_node(child)
|
||||||
|
|
||||||
|
func _geometry_uses_alpha_texture(node: GeometryInstance3D) -> bool:
|
||||||
|
var material_override := node.material_override as ShaderMaterial
|
||||||
|
if _shader_material_uses_alpha_texture(material_override):
|
||||||
|
return true
|
||||||
|
|
||||||
|
if node is MeshInstance3D:
|
||||||
|
for surface_index in node.get_surface_override_material_count():
|
||||||
|
var surface_material := node.get_surface_override_material(surface_index) as ShaderMaterial
|
||||||
|
if _shader_material_uses_alpha_texture(surface_material):
|
||||||
|
return true
|
||||||
|
|
||||||
|
if node.mesh:
|
||||||
|
for surface_index in node.mesh.get_surface_count():
|
||||||
|
var mesh_material := node.mesh.surface_get_material(surface_index) as ShaderMaterial
|
||||||
|
if _shader_material_uses_alpha_texture(mesh_material):
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
|
func _shader_material_uses_alpha_texture(material: ShaderMaterial) -> bool:
|
||||||
|
if material == null or material.shader == null:
|
||||||
|
return false
|
||||||
|
|
||||||
|
return material.shader.code.find("alpha_texture") != -1
|
||||||
|
|
||||||
func select_day_time(normalized_time: float) -> void:
|
func select_day_time(normalized_time: float) -> void:
|
||||||
#set show_day_time_debug = true to show debug on screen
|
#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
|
#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
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ global uniform float global_snow_start_time;
|
|||||||
global uniform float global_snow_accumulation_speed;
|
global uniform float global_snow_accumulation_speed;
|
||||||
global uniform float global_snow_melt_time;
|
global uniform float global_snow_melt_time;
|
||||||
global uniform float global_snow_melt_speed;
|
global uniform float global_snow_melt_speed;
|
||||||
|
global uniform float global_rain_intensity;
|
||||||
|
|
||||||
// --- PARAMETRI ESTETICI ---
|
// --- PARAMETRI ESTETICI ---
|
||||||
uniform bool billboard_enabled = true;
|
uniform bool billboard_enabled = true;
|
||||||
@@ -41,6 +42,7 @@ uniform float light_steps : hint_range(1.0, 10.0) = 4.0;
|
|||||||
uniform float random_mix : hint_range(0.0, 1.0) = 0.3;
|
uniform float random_mix : hint_range(0.0, 1.0) = 0.3;
|
||||||
|
|
||||||
uniform float cast_shadow_strength : hint_range(0.0, 1.0) = 0.6;
|
uniform float cast_shadow_strength : hint_range(0.0, 1.0) = 0.6;
|
||||||
|
uniform float wetness_darkening : hint_range(0.0, 0.5) = 0.25;
|
||||||
|
|
||||||
varying vec3 v_final_color;
|
varying vec3 v_final_color;
|
||||||
varying float v_shade_factor;
|
varying float v_shade_factor;
|
||||||
@@ -131,12 +133,15 @@ void fragment() {
|
|||||||
|
|
||||||
// Mescoliamo il colore variato con la neve
|
// Mescoliamo il colore variato con la neve
|
||||||
vec3 final_albedo = mix(varied_grass_color, shaded_snow, snow_mask);
|
vec3 final_albedo = mix(varied_grass_color, shaded_snow, snow_mask);
|
||||||
|
float rain_int = clamp(global_rain_intensity, 0.0, 1.0);
|
||||||
|
final_albedo *= mix(1.0, 1.0 - wetness_darkening, rain_int);
|
||||||
|
float final_roughness = mix(0.02, 0.005, rain_int);
|
||||||
|
|
||||||
ALBEDO = final_albedo;
|
ALBEDO = final_albedo;
|
||||||
ALPHA = tex.r * opacity;
|
ALPHA = tex.r * opacity;
|
||||||
ALPHA_SCISSOR_THRESHOLD = 0.5;
|
ALPHA_SCISSOR_THRESHOLD = 0.5;
|
||||||
|
|
||||||
ROUGHNESS = 0.02;
|
ROUGHNESS = final_roughness;
|
||||||
}
|
}
|
||||||
|
|
||||||
void light() {
|
void light() {
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ global uniform vec2 global_wind_direction;
|
|||||||
global uniform float global_wind_scale;
|
global uniform float global_wind_scale;
|
||||||
global uniform float global_wind_strength;
|
global uniform float global_wind_strength;
|
||||||
global uniform float global_wind_fade;
|
global uniform float global_wind_fade;
|
||||||
/*
|
|
||||||
global uniform float global_snow_start_time;
|
global uniform float global_snow_start_time;
|
||||||
global uniform float global_snow_accumulation_speed;
|
global uniform float global_snow_accumulation_speed;
|
||||||
global uniform float global_snow_melt_time;
|
global uniform float global_snow_melt_time;
|
||||||
global uniform float global_snow_melt_speed;
|
global uniform float global_snow_melt_speed;
|
||||||
global uniform vec4 global_snow_color;*/
|
global uniform vec4 global_snow_color;
|
||||||
global uniform float global_rain_intensity;
|
global uniform float global_rain_intensity;
|
||||||
|
|
||||||
uniform sampler2D wind_noise : filter_linear_mipmap;
|
uniform sampler2D wind_noise : filter_linear_mipmap;
|
||||||
@@ -88,24 +87,23 @@ void fragment() {
|
|||||||
vec2 shifted_uv = UV + texture_offset;
|
vec2 shifted_uv = UV + texture_offset;
|
||||||
vec4 tex = texture(alpha_texture, shifted_uv);
|
vec4 tex = texture(alpha_texture, shifted_uv);
|
||||||
|
|
||||||
//// Snow accumulation
|
// Snow accumulation
|
||||||
//float snow_amount = 0.0;
|
float snow_amount = 0.0;
|
||||||
//if (global_snow_start_time >= 0.0) {
|
if (global_snow_start_time >= 0.0) {
|
||||||
//snow_amount = clamp((TIME - global_snow_start_time) * global_snow_accumulation_speed, 0.0, 1.0);
|
snow_amount = clamp((TIME - global_snow_start_time) * global_snow_accumulation_speed, 0.0, 1.0);
|
||||||
//}
|
}
|
||||||
//if (global_snow_melt_time >= 0.0) {
|
if (global_snow_melt_time >= 0.0) {
|
||||||
//float melt = clamp((TIME - global_snow_melt_time) * global_snow_melt_speed, 0.0, 1.0);
|
float melt = clamp((TIME - global_snow_melt_time) * global_snow_melt_speed, 0.0, 1.0);
|
||||||
//snow_amount *= (1.0 - melt);
|
snow_amount *= (1.0 - melt);
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//float top_mask = 1.0 - shifted_uv.y;
|
|
||||||
//float snow_mask = smoothstep(1.0 - snow_amount, 1.2 - snow_amount, top_mask);
|
|
||||||
//snow_mask *= step(0.01, snow_amount);
|
|
||||||
|
|
||||||
//vec3 dark_snow = global_snow_color.rgb * (1.0 - shadow_intensity);
|
float top_mask = 1.0 - shifted_uv.y;
|
||||||
//vec3 shaded_snow = mix(dark_snow, global_snow_color.rgb, v_shade_factor);
|
float snow_mask = smoothstep(1.0 - snow_amount, 1.2 - snow_amount, top_mask);
|
||||||
//vec3 final_albedo = mix(v_final_color, shaded_snow, snow_mask);
|
snow_mask *= step(0.01, snow_amount);
|
||||||
vec3 final_albedo = v_final_color;
|
|
||||||
|
vec3 dark_snow = global_snow_color.rgb * (1.0 - shadow_intensity);
|
||||||
|
vec3 shaded_snow = mix(dark_snow, global_snow_color.rgb, v_shade_factor);
|
||||||
|
vec3 final_albedo = mix(v_final_color, shaded_snow, snow_mask);
|
||||||
|
|
||||||
// Rain wetness: darken and make shinier
|
// Rain wetness: darken and make shinier
|
||||||
float rain_int = clamp(global_rain_intensity, 0.0, 1.0);
|
float rain_int = clamp(global_rain_intensity, 0.0, 1.0);
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ extends Resource
|
|||||||
|
|
||||||
#Train start settings
|
#Train start settings
|
||||||
@export_group("Train Start")
|
@export_group("Train Start")
|
||||||
@export var train_start_from_random_position: bool = false #When enabled the train starts from a random offset on the rail curve instead of a stop
|
@export var train_start_from_random_position: bool = true #When enabled the train starts from a random offset on the rail curve instead of a stop
|
||||||
@export_range(0, 64, 1, "or_greater") var train_start_stop_index: int = 1 #Stop index used for the train start when random start is disabled
|
@export_range(0, 64, 1, "or_greater") var train_start_stop_index: int = 1 #Stop index used for the train start when random start is disabled
|
||||||
|
|
||||||
#Snow settings
|
#Snow settings
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
|||||||
[gd_resource type="ShaderMaterial" format=3 uid="uid://d37iugof887py"]
|
[gd_resource type="ShaderMaterial" format=3 uid="uid://d37iugof887py"]
|
||||||
|
|
||||||
[ext_resource type="Shader" path="res://core/daynight/water_river.gdshader" id="1_qxgaw"]
|
[ext_resource type="Shader" uid="uid://cb12c2j8rfu6a" path="res://core/daynight/water_river.gdshader" id="1_qxgaw"]
|
||||||
|
|
||||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_qxgaw"]
|
[sub_resource type="FastNoiseLite" id="FastNoiseLite_qxgaw"]
|
||||||
|
|
||||||
|
|||||||
@@ -35,3 +35,4 @@ shader_parameter/highlight_intensity = 0.10000000475
|
|||||||
shader_parameter/light_steps = 8.600000361
|
shader_parameter/light_steps = 8.600000361
|
||||||
shader_parameter/random_mix = 0.0150000007125
|
shader_parameter/random_mix = 0.0150000007125
|
||||||
shader_parameter/cast_shadow_strength = 0.6
|
shader_parameter/cast_shadow_strength = 0.6
|
||||||
|
shader_parameter/wetness_darkening = 0.25
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ shader_parameter/puddle_threshold = 0.45
|
|||||||
[node name="TreeTest3" unique_id=1532527216 groups=["weather_node", "wind_node"] instance=ExtResource("1_8jt4o")]
|
[node name="TreeTest3" unique_id=1532527216 groups=["weather_node", "wind_node"] instance=ExtResource("1_8jt4o")]
|
||||||
transform = Transform3D(1.7, 0, 0, 0, 1.7, 0, 0, 0, 1.7, 0, 0, 0)
|
transform = Transform3D(1.7, 0, 0, 0, 1.7, 0, 0, 0, 1.7, 0, 0, 0)
|
||||||
|
|
||||||
[node name="Leaf" parent="." index="0" unique_id=2098078578]
|
[node name="Leaf" parent="." index="0" unique_id=2028330452]
|
||||||
transform = Transform3D(100, 0, 0, 0, -4.3711384e-06, 99.99999, 0, -99.99999, -4.3711384e-06, 0, 0, 0)
|
transform = Transform3D(100, 0, 0, 0, -4.3711384e-06, 99.99999, 0, -99.99999, -4.3711384e-06, 0, 0, 0)
|
||||||
cast_shadow = 3
|
cast_shadow = 3
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ material_override = ExtResource("4_8rfui")
|
|||||||
cast_shadow = 0
|
cast_shadow = 0
|
||||||
multimesh = SubResource("MultiMesh_8rfui")
|
multimesh = SubResource("MultiMesh_8rfui")
|
||||||
|
|
||||||
[node name="tree" parent="." index="1" unique_id=1483228573]
|
[node name="tree" parent="." index="1" unique_id=2124791569]
|
||||||
material_overlay = SubResource("ShaderMaterial_kpc41")
|
material_overlay = SubResource("ShaderMaterial_kpc41")
|
||||||
surface_material_override/0 = ExtResource("3_imfiy")
|
surface_material_override/0 = ExtResource("3_imfiy")
|
||||||
|
|
||||||
|
|||||||
@@ -108,31 +108,31 @@ west = true
|
|||||||
river_north = true
|
river_north = true
|
||||||
river_south = true
|
river_south = true
|
||||||
|
|
||||||
[node name="Argini_F_003" parent="." index="0" unique_id=1943456620]
|
[node name="Argini_F_003" parent="." index="0" unique_id=1480268542]
|
||||||
surface_material_override/0 = ExtResource("2_wqn5s")
|
surface_material_override/0 = ExtResource("2_wqn5s")
|
||||||
|
|
||||||
[node name="Flower_021" parent="." index="1" unique_id=1248562513]
|
[node name="Flower_021" parent="." index="1" unique_id=2125433847]
|
||||||
visible = false
|
visible = false
|
||||||
|
|
||||||
[node name="FlowerG_020" parent="." index="2" unique_id=522984193]
|
[node name="FlowerG_020" parent="." index="2" unique_id=588074656]
|
||||||
visible = false
|
visible = false
|
||||||
|
|
||||||
[node name="MSH_Staccioanta_1_019" parent="." index="3" unique_id=712328040]
|
[node name="MSH_Staccioanta_1_019" parent="." index="3" unique_id=1959253560]
|
||||||
surface_material_override/0 = ExtResource("3_amhor")
|
surface_material_override/0 = ExtResource("3_amhor")
|
||||||
|
|
||||||
[node name="Strada_011" parent="." index="4" unique_id=1636902357]
|
[node name="Strada_011" parent="." index="4" unique_id=651344270]
|
||||||
surface_material_override/0 = ExtResource("4_amhor")
|
surface_material_override/0 = ExtResource("4_amhor")
|
||||||
|
|
||||||
[node name="Water_F_003" parent="." index="5" unique_id=1352549891]
|
[node name="Water_F_003" parent="." index="5" unique_id=1436454617]
|
||||||
surface_material_override/0 = ExtResource("6_es1d0")
|
surface_material_override/0 = ExtResource("6_es1d0")
|
||||||
|
|
||||||
[node name="bridge" parent="." index="6" unique_id=283522162]
|
[node name="bridge" parent="." index="6" unique_id=780103758]
|
||||||
surface_material_override/0 = ExtResource("6_062h7")
|
surface_material_override/0 = ExtResource("6_062h7")
|
||||||
surface_material_override/1 = SubResource("ShaderMaterial_0snf2")
|
surface_material_override/1 = SubResource("ShaderMaterial_0snf2")
|
||||||
surface_material_override/2 = ExtResource("8_0snf2")
|
surface_material_override/2 = ExtResource("8_0snf2")
|
||||||
surface_material_override/3 = SubResource("ShaderMaterial_i6s7h")
|
surface_material_override/3 = SubResource("ShaderMaterial_i6s7h")
|
||||||
|
|
||||||
[node name="grass" parent="." index="7" unique_id=863206516]
|
[node name="grass" parent="." index="7" unique_id=995119855]
|
||||||
surface_material_override/0 = ExtResource("2_wqn5s")
|
surface_material_override/0 = ExtResource("2_wqn5s")
|
||||||
|
|
||||||
[node name="grass2" type="Node3D" parent="." index="8" unique_id=1023384553 groups=["weather_vegetables_node", "wind_node"]]
|
[node name="grass2" type="Node3D" parent="." index="8" unique_id=1023384553 groups=["weather_vegetables_node", "wind_node"]]
|
||||||
|
|||||||
Reference in New Issue
Block a user