This commit is contained in:
2026-05-09 14:57:07 +02:00
parent ddec91d515
commit 040ded5f0b
10 changed files with 146 additions and 820 deletions

View File

@@ -3,7 +3,6 @@ extends Node3D
const NOISE_TEXTURE: Texture2D = preload("res://core/daynight/noise.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
@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)
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():
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)
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:
if node is GeometryInstance3D:
node.material_overlay = material
if _geometry_uses_alpha_texture(node):
node.material_overlay = null
else:
node.material_overlay = material
for child in node.get_children():
_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:
#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

@@ -12,6 +12,7 @@ global uniform float global_snow_start_time;
global uniform float global_snow_accumulation_speed;
global uniform float global_snow_melt_time;
global uniform float global_snow_melt_speed;
global uniform float global_rain_intensity;
// --- PARAMETRI ESTETICI ---
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 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 float v_shade_factor;
@@ -131,12 +133,15 @@ void fragment() {
// Mescoliamo il colore variato con la neve
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;
ALPHA = tex.r * opacity;
ALPHA_SCISSOR_THRESHOLD = 0.5;
ROUGHNESS = 0.02;
ROUGHNESS = final_roughness;
}
void light() {

View File

@@ -6,12 +6,11 @@ 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;
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;
uniform sampler2D wind_noise : filter_linear_mipmap;
@@ -88,24 +87,23 @@ void fragment() {
vec2 shifted_uv = UV + texture_offset;
vec4 tex = texture(alpha_texture, shifted_uv);
//// Snow accumulation
//float snow_amount = 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);
//}
//if (global_snow_melt_time >= 0.0) {
//float melt = clamp((TIME - global_snow_melt_time) * global_snow_melt_speed, 0.0, 1.0);
//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);
// Snow accumulation
float snow_amount = 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);
}
if (global_snow_melt_time >= 0.0) {
float melt = clamp((TIME - global_snow_melt_time) * global_snow_melt_speed, 0.0, 1.0);
snow_amount *= (1.0 - melt);
}
//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);
vec3 final_albedo = v_final_color;
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);
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
float rain_int = clamp(global_rain_intensity, 0.0, 1.0);

View File

@@ -6,9 +6,9 @@
shader_type spatial;
#if USE_UNSHADED
render_mode unshaded, depth_draw_never;
render_mode unshaded, depth_draw_never;
#else
render_mode depth_draw_never;
render_mode depth_draw_never;
#endif
uniform sampler2D DEPTH_TEXTURE: hint_depth_texture;
@@ -24,16 +24,16 @@ uniform float surface_roughness : hint_range(0.0, 1.0, 0.01) = 0.05;
uniform float foam_roughness : hint_range(0.0, 1.0, 0.01) = 0.05;
#if USE_CAUSTICS
group_uniforms Caustics;
uniform sampler2D caustics_texture;
uniform float caustics_strength = 2.0;
uniform vec2 caustics_scale = vec2(0.5);
group_uniforms Caustics;
uniform sampler2D caustics_texture;
uniform float caustics_strength = 2.0;
uniform vec2 caustics_scale = vec2(0.5);
#endif
group_uniforms Wave;
uniform sampler2D wave_texture;
#if !USE_UNSHADED
uniform sampler2D wave_normal_texture;
uniform sampler2D wave_normal_texture;
#endif
uniform float wave_softness : hint_range(0.0, 10.0, 0.1) = 3.0;
uniform vec2 wave_scale = vec2(0.2);
@@ -52,36 +52,36 @@ uniform float foam_end : hint_range(0.0, 1.0, 0.05) = 0.3;
uniform float foam_exponent = 2.0;
#if USE_REFRACTION
group_uniforms Refraction;
uniform float refraction_amount = 0.5;
uniform float refraction_exponent = 0.5;
group_uniforms Refraction;
uniform float refraction_amount = 0.5;
uniform float refraction_exponent = 0.5;
#endif
#if USE_DISPLACEMENT
group_uniforms Displacement;
uniform float displacement_amount = 0.3;
group_uniforms Displacement;
uniform float displacement_amount = 0.3;
#endif
#if USE_STYLIZED_LIGHTING && !USE_UNSHADED
group_uniforms Lighting;
uniform float diffuse_steps = 12.0;
uniform float diffuse_smoothness : hint_range(0.0, 1.0, 0.01) = 0.2;
uniform float specular_steps = 12.0;
uniform float specular_smoothness : hint_range(0.0, 1.0, 0.01) = 0.2;
group_uniforms Lighting;
uniform float diffuse_steps = 12.0;
uniform float diffuse_smoothness : hint_range(0.0, 1.0, 0.01) = 0.2;
uniform float specular_steps = 12.0;
uniform float specular_smoothness : hint_range(0.0, 1.0, 0.01) = 0.2;
#endif
uniform sampler2D screen_texture : hint_screen_texture;
varying vec3 world_pos;
#if USE_CAUSTICS
vec3 sample_caustics(vec2 uv){
vec2 caustics_uv = uv * caustics_scale;
return vec3(
texture(caustics_texture, caustics_uv).r,
texture(caustics_texture, caustics_uv+vec2(0.02,0.02)).r,
texture(caustics_texture, caustics_uv+vec2(0.03,0.01)).r
);
}
vec3 sample_caustics(vec2 uv){
vec2 caustics_uv = uv * caustics_scale;
return vec3(
texture(caustics_texture, caustics_uv).r,
texture(caustics_texture, caustics_uv+vec2(0.02,0.02)).r,
texture(caustics_texture, caustics_uv+vec2(0.03,0.01)).r
);
}
#endif
vec4 sample_world_dpos(vec2 screen_uv, mat4 inv_proj_mat, mat4 inv_view_mat){
@@ -107,8 +107,8 @@ void vertex(){
world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
#if USE_DISPLACEMENT
float wave = sample_wave(wave_texture, world_pos.xz, wave_velocity, wave_softness).r;
VERTEX.y += wave*displacement_amount;
float wave = sample_wave(wave_texture, world_pos.xz, wave_velocity, wave_softness).r;
VERTEX.y += wave*displacement_amount;
#endif
}
@@ -120,17 +120,17 @@ void fragment() {
// Refraction
#if USE_REFRACTION
screen_uv += ((pow(wave, refraction_exponent)*2.0 - 0.5) * 0.01 * refraction_amount);
vec4 world_dpos = sample_world_dpos(screen_uv, INV_PROJECTION_MATRIX, INV_VIEW_MATRIX);
float pre_depth = pow(clamp((world_dpos.y - world_pos.y + depth_size)/depth_size, 0.0, 1.0), 4.0);
screen_uv = mix(screen_uv, SCREEN_UV, pre_depth);
if(world_dpos.y - world_pos.y > 0.0){
screen_uv = SCREEN_UV;
}
screen_uv += ((pow(wave, refraction_exponent)*2.0 - 0.5) * 0.01 * refraction_amount);
vec4 world_dpos = sample_world_dpos(screen_uv, INV_PROJECTION_MATRIX, INV_VIEW_MATRIX);
float pre_depth = pow(clamp((world_dpos.y - world_pos.y + depth_size)/depth_size, 0.0, 1.0), 4.0);
screen_uv = mix(screen_uv, SCREEN_UV, pre_depth);
if(world_dpos.y - world_pos.y > 0.0){
screen_uv = SCREEN_UV;
}
#else
vec4 world_dpos = sample_world_dpos(screen_uv, INV_PROJECTION_MATRIX, INV_VIEW_MATRIX);
vec4 world_dpos = sample_world_dpos(screen_uv, INV_PROJECTION_MATRIX, INV_VIEW_MATRIX);
#endif
world_dpos = sample_world_dpos(screen_uv, INV_PROJECTION_MATRIX, INV_VIEW_MATRIX);
@@ -141,9 +141,9 @@ void fragment() {
// Caustics
#if USE_CAUSTICS
vec3 caustics1 = sample_caustics(surface_uv + (TIME * -wave_velocity));
vec3 caustics2 = sample_caustics((surface_uv + (caustics1.r*0.05)) + (TIME * (wave_velocity*0.5)));
vec3 caustics = caustics2 * (1.0 - depth);
vec3 caustics1 = sample_caustics(surface_uv + (TIME * -wave_velocity));
vec3 caustics2 = sample_caustics((surface_uv + (caustics1.r*0.05)) + (TIME * (wave_velocity*0.5)));
vec3 caustics = caustics2 * (1.0 - depth);
#endif
// Edge Foam
@@ -163,15 +163,15 @@ void fragment() {
vec4 screen = texture(screen_texture, screen_uv);
vec3 color = screen.rgb;
#if USE_CAUSTICS
color += vec3(pow(caustics * caustics_strength, vec3(2.0)));
color += vec3(pow(caustics * caustics_strength, vec3(2.0)));
#endif
color = mix(flat_color, color, 0.4 * depth);
color = mix(color, surface_color.rgb, wave * wave_highlight);
color = mix(color, foam_color.rgb, foam);
#if !USE_UNSHADED
vec3 wave_normal_map = sample_wave(wave_normal_texture, world_pos.xz, wave_velocity, wave_softness).rgb;
NORMAL_MAP = wave_normal_map;
vec3 wave_normal_map = sample_wave(wave_normal_texture, world_pos.xz, wave_velocity, wave_softness).rgb;
NORMAL_MAP = wave_normal_map;
#endif
ROUGHNESS = mix(surface_roughness, foam_roughness, foam);
@@ -180,33 +180,33 @@ void fragment() {
}
#if USE_STYLIZED_LIGHTING && !USE_UNSHADED
void light(){
float ndotl = dot(NORMAL, LIGHT) * ATTENUATION;
//ndotl = smoothstep(0.0,1.0-ROUGHNESS,ndotl);
float light = ndotl;
float light_mult = light * diffuse_steps;
float light_step_base = floor(light_mult);
float light_factor = light_mult - light_step_base;
light_factor = smoothstep(0.5 - diffuse_smoothness * 0.5, 0.5 + diffuse_smoothness * 0.5, light_factor);
light = (light_step_base + light_factor) / diffuse_steps;
DIFFUSE_LIGHT += (LIGHT_COLOR+ALBEDO) * light / PI;
float roughness = mix(0.01, 0.99, ROUGHNESS);
vec3 h = normalize(VIEW + LIGHT);
float ndoth = clamp(dot(NORMAL, h), 0.0, 1.0) * ATTENUATION;
float specular = clamp(pow(ndoth, 16.0/(roughness)), 0.1, 0.99);
specular = mix(pow(specular, 2.0-roughness),0.00,pow(roughness, 0.1));
float specular_mult = specular * specular_steps;
float specular_step_base = floor(specular_mult);
float specular_factor = specular_mult - specular_step_base;
specular_factor = smoothstep(0.5 - specular_smoothness * 0.5, 0.5 + specular_smoothness * 0.5, specular_factor);
specular = (specular_step_base + specular_factor) / specular_steps;
SPECULAR_LIGHT += (LIGHT_COLOR + ALBEDO) * specular;
}
void light(){
float ndotl = dot(NORMAL, LIGHT) * ATTENUATION;
//ndotl = smoothstep(0.0,1.0-ROUGHNESS,ndotl);
float light = ndotl;
float light_mult = light * diffuse_steps;
float light_step_base = floor(light_mult);
float light_factor = light_mult - light_step_base;
light_factor = smoothstep(0.5 - diffuse_smoothness * 0.5, 0.5 + diffuse_smoothness * 0.5, light_factor);
light = (light_step_base + light_factor) / diffuse_steps;
DIFFUSE_LIGHT += (LIGHT_COLOR+ALBEDO) * light / PI;
float roughness = mix(0.01, 0.99, ROUGHNESS);
vec3 h = normalize(VIEW + LIGHT);
float ndoth = clamp(dot(NORMAL, h), 0.0, 1.0) * ATTENUATION;
float specular = clamp(pow(ndoth, 16.0/(roughness)), 0.1, 0.99);
specular = mix(pow(specular, 2.0-roughness),0.00,pow(roughness, 0.1));
float specular_mult = specular * specular_steps;
float specular_step_base = floor(specular_mult);
float specular_factor = specular_mult - specular_step_base;
specular_factor = smoothstep(0.5 - specular_smoothness * 0.5, 0.5 + specular_smoothness * 0.5, specular_factor);
specular = (specular_step_base + specular_factor) / specular_steps;
SPECULAR_LIGHT += (LIGHT_COLOR + ALBEDO) * specular;
}
#endif

View File

@@ -138,7 +138,7 @@ extends Resource
#Train start settings
@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
#Snow settings

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
[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"]

View File

@@ -35,3 +35,4 @@ shader_parameter/highlight_intensity = 0.10000000475
shader_parameter/light_steps = 8.600000361
shader_parameter/random_mix = 0.0150000007125
shader_parameter/cast_shadow_strength = 0.6
shader_parameter/wetness_darkening = 0.25

View File

@@ -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")]
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)
cast_shadow = 3
@@ -45,7 +45,7 @@ material_override = ExtResource("4_8rfui")
cast_shadow = 0
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")
surface_material_override/0 = ExtResource("3_imfiy")

View File

@@ -108,31 +108,31 @@ west = true
river_north = 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")
[node name="Flower_021" parent="." index="1" unique_id=1248562513]
[node name="Flower_021" parent="." index="1" unique_id=2125433847]
visible = false
[node name="FlowerG_020" parent="." index="2" unique_id=522984193]
[node name="FlowerG_020" parent="." index="2" unique_id=588074656]
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")
[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")
[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")
[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/1 = SubResource("ShaderMaterial_0snf2")
surface_material_override/2 = ExtResource("8_0snf2")
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")
[node name="grass2" type="Node3D" parent="." index="8" unique_id=1023384553 groups=["weather_vegetables_node", "wind_node"]]