improve snow

This commit is contained in:
2026-06-06 18:35:50 +02:00
parent 326d32c946
commit 9579f26a63
23 changed files with 168 additions and 69 deletions

View File

@@ -16,6 +16,7 @@ global uniform float global_snow_cap_flatness_start = 0.72;
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 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;
@@ -86,6 +87,18 @@ float get_snow_progress() {
return snow_progress;
}
float get_visual_snow_progress(float snow_progress) {
return pow(clamp(snow_progress, 0.0, 1.0), SNOW_VISUAL_RESPONSE);
}
float get_snow_noise_mask(vec3 world_pos, float snow_progress) {
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);
float threshold = mix(0.92, 0.08, snow_progress);
return smoothstep(threshold - 0.18, threshold + 0.18, combined_noise);
}
float ripple_ring(vec2 uv, float time_offset) {
float d = length(uv);
float ring = sin(d * 30.0 - TIME * ripple_speed + time_offset) * 0.5 + 0.5;
@@ -94,7 +107,7 @@ float ripple_ring(vec2 uv, float time_offset) {
}
void vertex() {
float snow_progress = get_snow_progress();
float snow_progress = get_visual_snow_progress(get_snow_progress());
float snow_accumulation = snow_progress * global_snow_max_accumulation;
vec3 world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
vec3 world_normal = normalize((MODEL_MATRIX * vec4(NORMAL, 0.0)).xyz);
@@ -104,7 +117,7 @@ void vertex() {
global_snow_cap_flatness_end,
world_normal.y
);
float accumulation_growth = smoothstep(0.08, 0.65, snow_progress);
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_variation = mix(1.0 - global_snow_cap_noise_strength, 1.0 + global_snow_cap_noise_strength, cap_noise);
@@ -118,6 +131,8 @@ void fragment() {
vec3 world_pos = (INV_VIEW_MATRIX * vec4(VERTEX, 1.0)).xyz;
vec3 world_normal = normalize((INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz);
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;
//Snow
@@ -127,14 +142,15 @@ void fragment() {
float snow_edge = smoothstep(
global_snow_threshold - snow_edge_softness,
global_snow_threshold + snow_edge_softness,
facing_up
snow_facing_up
);
float flat_accumulation = smoothstep(0.0, 0.35, v_snow_cap_mask) * snow_accumulation;
float snow_noise_mask = get_snow_noise_mask(world_pos, snow_progress);
float snow_variation = mix(0.75, 1.15, noise_val);
float snow_coverage = clamp(snow_progress * snow_variation + flat_accumulation * 0.25, 0.0, 1.0);
float snow_coverage = clamp(mix(snow_progress * 0.35, snow_progress * snow_variation, snow_noise_mask) + flat_accumulation * 0.15, 0.0, 1.0);
float snow_factor = max(snow_edge * snow_coverage, flat_accumulation);
float snow_opacity = clamp(snow_factor, 0.0, 1.0);
snow_opacity = max(snow_opacity, flat_accumulation * 0.9);
snow_opacity = max(snow_opacity, flat_accumulation * mix(0.45, 0.9, snow_noise_mask));
float shade = mix(-snow_color_variation, snow_color_variation, noise_val);
vec3 snow_albedo = clamp(global_snow_color.rgb + vec3(shade), 0.0, 1.0);