From f9dde40bdc10e829fac86b3e3067652cc9df8760 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 23:14:37 +0100 Subject: [PATCH] Windscreen: rain keeps its last state and dries, snow stays and melts after snowfall [skip ci] - Rain drops, rivulets and micro droplets run on a rain clock (rain_state.w) that only advances while it rains, so they freeze when the rain stops and fade as the glass dries. - Glass wetness fills only during "rain:" weather. - Snow glasses keep their snow material after snowfall ends (until rain), so the snow stays, melts above 0 C into a wet film and drops, and dries. - The baked snow layer uses a larger drop share while melting. No new assets; no change to file formats. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD --- gl/ubo.h | 3 +- rendering/common/windscreenwater.cpp | 59 +++++++++++++++++++++++++ rendering/common/windscreenwater.h | 9 ++++ rendering/opengl46/opengl46renderer.cpp | 13 ++++-- rendering/opengl46/opengl46renderer.h | 1 + rendering/vulkan14/vulkan14frame.cpp | 13 ++++-- rendering/vulkan14/vulkan14renderer.h | 1 + shaders/ogl46/common.glsl | 2 +- shaders/ogl46/mat_rain_windscreen.frag | 6 +-- shaders/ogl46/rain_cells.comp | 2 +- shaders/ogl46/snow_sprites.glsl | 3 +- shaders/ogl46/water_snowlayer.comp | 4 ++ shaders/vk14/common.glsl | 2 +- shaders/vk14/mat_rain_windscreen.frag | 6 +-- shaders/vk14/rain_cells.comp | 2 +- shaders/vk14/snow_sprites.glsl | 3 +- shaders/vk14/water_snowlayer.comp | 4 ++ 17 files changed, 114 insertions(+), 19 deletions(-) diff --git a/gl/ubo.h b/gl/ubo.h index fc33d9018..4d6fb7513 100644 --- a/gl/ubo.h +++ b/gl/ubo.h @@ -212,7 +212,8 @@ namespace gl glm::vec4 camera_lo; // the rain the glass meets (mat_rain_windscreen): x the rain fallen so far, in seconds of the heaviest rain standing still (more // at speed: the glass runs into it); y how wet the glass is, 0 dry .. 1 as full of drops as it gets (it fills with the rain, - // dries when it stops); z how fast the glass fills: the share left to fill goes down as exp(-z x the rain fallen); w unused + // dries when it stops); z how fast the glass fills: the share left to fill goes down as exp(-z x the rain fallen); w the clock of + // the drops, s: it runs while it rains, so the glass keeps its last drops while it dries glm::vec4 rain_state; // the rain fallen (rain_state.x) when a blade last went over a place of its sweep: element b for the places b / 64 .. (b + 1) // / 64 of dWiperPos (the value of the wiper mask of a pixel), x .. w the blades (as wiper_pos); -1 not known. the drops and the diff --git a/rendering/common/windscreenwater.cpp b/rendering/common/windscreenwater.cpp index 498b85248..219cfbe25 100644 --- a/rendering/common/windscreenwater.cpp +++ b/rendering/common/windscreenwater.cpp @@ -29,6 +29,35 @@ http://mozilla.org/MPL/2.0/. namespace gfx { +// what the material of a glass of the snow draws with (the parts opengl_material copies for its variants, model/material.cpp) +struct snow_look +{ + opengl_material::texture_set textures{}; + std::vector texture_variants; + std::array params{}; + std::vector params_state; + std::shared_ptr shader; + std::optional opacity; + std::optional selfillum; + float glossiness{10.f}; + + static snow_look of(opengl_material const &Material) + { + return snow_look{Material.textures, Material.texture_variants, Material.params, Material.params_state, Material.shader, Material.opacity, Material.selfillum, Material.glossiness}; + } + void give(opengl_material &Material) const + { + Material.textures = textures; + Material.texture_variants = texture_variants; + Material.params = params; + Material.params_state = params_state; + Material.shader = shader; + Material.opacity = opacity; + Material.selfillum = selfillum; + Material.glossiness = glossiness; + } +}; + namespace { @@ -295,6 +324,10 @@ void windscreen_water::build(TModel3d &Cab) glass.material = material; auto const *opengl{m_host.material(material)}; glass.snow = is_snow_glass(opengl); + if (glass.snow) + { + glass.snowmaterial = std::make_shared(snow_look::of(*opengl)); + } glass.mask = opengl->textures[opengl->shader->texture_conf.at("wipermask").id]; for (std::size_t texel = 0; texel < texels; ++texel) { @@ -357,6 +390,10 @@ void windscreen_water::update(double const Seconds) } auto const *vehicle{simulation::Train != nullptr ? simulation::Train->Dynamic() : nullptr}; auto *cab{vehicle != nullptr ? vehicle->mdKabina : nullptr}; + if ((vehicle == m_vehicle) && (cab == m_cab)) + { + keep_snow(); + } // a material of the glasses of another kind: the weather changed, the materials have the shaders of the other weather (the // snow comes with the shader of the snow and goes with it) auto const changed{std::ranges::any_of(m_kinds, [this](auto const &Kind) { return glass_kind(m_host.material(Kind.first)) != Kind.second; })}; @@ -554,6 +591,28 @@ std::array windscreen_water::layer_info(std::size_t const Slot return info; } +void windscreen_water::keep_snow() +{ + if (Global.Weather == "rain:") + { + // the rain washes the snow off: the glass of the snow becomes a glass of the water again (built anew) + return; + } + for (std::size_t slot = 0; slot < m_glasscount; ++slot) + { + auto const &glass{m_glasses[slot]}; + if ((false == glass.snow) || (false == bool(glass.snowmaterial))) + { + continue; + } + if (auto *material{m_host.material(glass.material)}; (material != nullptr) && (false == is_snow_glass(material))) + { + // the weather took the shader of the snow away: it's given back (the slot param is set again by assign()) + glass.snowmaterial->give(*material); + } + } +} + void windscreen_water::lay_snow(gl::water_ubs const &Block) { // the one glass with the layer diff --git a/rendering/common/windscreenwater.h b/rendering/common/windscreenwater.h index 4acfe991e..bceebccf8 100644 --- a/rendering/common/windscreenwater.h +++ b/rendering/common/windscreenwater.h @@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/. #include #include #include +#include #include #include #include @@ -29,6 +30,8 @@ class TDynamicObject; namespace gfx { +struct snow_look; // the look of the material of a glass of the snow (windscreenwater.cpp) + // the water on the windscreens of the cab of the train, simulated on the gpu, whichever api runs it. // // a glass is a material of mat_rain_windscreen (one with a mask of the wipers) in the model of the cab of the train, up to @@ -95,6 +98,9 @@ class windscreen_water double landings{0.0}; // the share of a landing left over from the steps before bool baked{false}; bool snow{false}; // a glass of the snow (mat_snow_windscreen), else of the water + // the material of a glass of the snow as it was set up: it stays on the glass when it stops snowing (until it rains), so + // the snow left on it melts into drops and dries + std::shared_ptr snowmaterial; }; // the glasses of the model of a cab found and set up @@ -105,6 +111,9 @@ class windscreen_water void assign(bool Assigned); // the snow of the glasses of the snow Block says are simulated laid together, after the step void lay_snow(gl::water_ubs const &Block); + // the glasses of the snow keep the material of the snow when it stops snowing, until it rains (the weather gave the material + // the shader of the rain back) + void keep_snow(); protected: // where the layer of the snow of a glass lies (water.glsl): the rectangle of the uv its map holds the glass in (the corner and diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp index d566a965d..abf3c2f2e 100644 --- a/rendering/opengl46/opengl46renderer.cpp +++ b/rendering/opengl46/opengl46renderer.cpp @@ -1672,11 +1672,18 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode) auto const speed{(owner != nullptr) ? std::min(std::abs(owner->MoverParameters->V) * 3.6 / 100.0, 1.0) : 0.0}; auto const meet{static_cast(percipitation_intensity) * (1.0 + fill_speed * speed)}; m_wiperrain += dt * meet; - if (percipitation_intensity > 0.f) + // the glass gets wet with the rain only (the snow lies on it, the glass of the snow melts it into its own water), and its + // drops live by the clock of the rain, which stands while it doesn't rain: the rain stopped, the glass keeps its last drops + // and rivulets where they are while it dries + auto const raining{(percipitation_intensity > 0.f) && (Global.Weather == "rain:")}; + if (raining) + { m_glasswet += (1.0 - m_glasswet) * (1.0 - std::exp(-fill_rate * dt * meet)); + m_raintime += dt; + } else m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed)); - scene_ubs.rain_state = glm::vec4{static_cast(m_wiperrain), static_cast(m_glasswet), static_cast(fill_rate), 0.f}; + scene_ubs.rain_state = glm::vec4{static_cast(m_wiperrain), static_cast(m_glasswet), static_cast(fill_rate), static_cast(m_raintime)}; } if (owner != nullptr) { @@ -1740,7 +1747,7 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode) m_windscreenwater.update(Timer::GetDeltaTime()); // the drops and the rivulets of the glasses with rain, for the time of the block of the scene // (the drops a cell may hold: as many as the glass is wet) - m_windscreenwater.update_rain_cells(scene_ubs.time, (scene_ubs.rain_state.y > 0.001f) ? std::min(scene_ubs.rain_state.y + 0.01f, 1.f) : 0.f); + m_windscreenwater.update_rain_cells(static_cast(m_raintime), (scene_ubs.rain_state.y > 0.001f) ? std::min(scene_ubs.rain_state.y + 0.01f, 1.f) : 0.f); } m_windscreenwater.bind(); diff --git a/rendering/opengl46/opengl46renderer.h b/rendering/opengl46/opengl46renderer.h index ccb24df54..41cffeb9d 100644 --- a/rendering/opengl46/opengl46renderer.h +++ b/rendering/opengl46/opengl46renderer.h @@ -861,6 +861,7 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk { // the rain the glass met so far and how wet it is (scene_ubs::rain_state) double m_wiperrain{0.0}; double m_glasswet{0.0}; + double m_raintime{0.0}; // the clock of the drops of the rain, s: it runs while it rains (scene_ubs.rain_state.w) gl::light_data light_data; std::unordered_map> m_shaders; diff --git a/rendering/vulkan14/vulkan14frame.cpp b/rendering/vulkan14/vulkan14frame.cpp index 5432b35af..72102190b 100644 --- a/rendering/vulkan14/vulkan14frame.cpp +++ b/rendering/vulkan14/vulkan14frame.cpp @@ -1048,7 +1048,7 @@ void vulkan14_renderer::render_scene() scene.water.update(Timer::GetDeltaTime()); // the drops and the rivulets of the glasses with rain, for the time the block of the scene gets (scene_ubs.time) // (the drops a cell may hold: as many as the glass is wet, a little more, since it's the wetness of the frame before) - scene.water.update_rain_cells(static_cast(Timer::GetTime()), (m_glasswet > 0.001) ? static_cast(std::min(m_glasswet + 0.01, 1.0)) : 0.f); + scene.water.update_rain_cells(static_cast(m_raintime), (m_glasswet > 0.001) ? static_cast(std::min(m_glasswet + 0.01, 1.0)) : 0.f); if (scene.targets.size() < m_viewports.size()) { scene.targets.resize(m_viewports.size()); @@ -1527,11 +1527,18 @@ void vulkan14_renderer::render_viewport(std::size_t const Index) auto const speed{(owner != nullptr) ? std::min(std::abs(owner->MoverParameters->V) * 3.6 / 100.0, 1.0) : 0.0}; auto const meet{static_cast(percipitation_intensity) * (1.0 + fill_speed * speed)}; m_wiperrain += dt * meet; - if (percipitation_intensity > 0.f) + // the glass gets wet with the rain only (the snow lies on it, the glass of the snow melts it into its own water), and its + // drops live by the clock of the rain, which stands while it doesn't rain: the rain stopped, the glass keeps its last drops + // and rivulets where they are while it dries + auto const raining{(percipitation_intensity > 0.f) && (Global.Weather == "rain:")}; + if (raining) + { m_glasswet += (1.0 - m_glasswet) * (1.0 - std::exp(-fill_rate * dt * meet)); + m_raintime += dt; + } else m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed)); - scene_ubs.rain_state = glm::vec4{static_cast(m_wiperrain), static_cast(m_glasswet), static_cast(fill_rate), 0.f}; + scene_ubs.rain_state = glm::vec4{static_cast(m_wiperrain), static_cast(m_glasswet), static_cast(fill_rate), static_cast(m_raintime)}; } if (owner != nullptr) { diff --git a/rendering/vulkan14/vulkan14renderer.h b/rendering/vulkan14/vulkan14renderer.h index 0ba5e015d..dffc2dad5 100644 --- a/rendering/vulkan14/vulkan14renderer.h +++ b/rendering/vulkan14/vulkan14renderer.h @@ -562,6 +562,7 @@ class vulkan14_renderer : public gfx_renderer, public gfx::scene_walk // the rain the glass met so far and how wet it is (scene_ubs::rain_state) double m_wiperrain{0.0}; double m_glasswet{0.0}; + double m_raintime{0.0}; // the clock of the drops of the rain, s: it runs while it rains (scene_ubs.rain_state.w) gl::light_data light_data{}; std::uint32_t m_lightcount{1}; // lights written to light_data // the copies of the light buffer in the ring of the frame since the lights were last written, by the header and the sun diff --git a/shaders/ogl46/common.glsl b/shaders/ogl46/common.glsl index f2193e498..6ac79e5d7 100644 --- a/shaders/ogl46/common.glsl +++ b/shaders/ogl46/common.glsl @@ -385,7 +385,7 @@ layout(std140, binding = SCENE_UBO_BINDING) uniform scene_ubo // the place of the camera of the pass in the world (whole 64 m, the rest), see gl::scene_ubs vec4 camera_hi; vec4 camera_lo; - // the rain the glass meets: x fallen so far, y how wet the glass is, z how fast it fills (mat_rain_windscreen), see gl::scene_ubs + // the rain the glass meets: x fallen so far, y how wet the glass is, z how fast it fills, w the clock of its drops (mat_rain_windscreen), see gl::scene_ubs vec4 rain_state; // the rain fallen when a blade last went over a place of its sweep (the wiper mask / 64), see gl::scene_ubs vec4 wiper_rain_pass[WIPER_PASS_BUCKETS]; diff --git a/shaders/ogl46/mat_rain_windscreen.frag b/shaders/ogl46/mat_rain_windscreen.frag index ca68ca98e..e3f012bc5 100644 --- a/shaders/ogl46/mat_rain_windscreen.frag +++ b/shaders/ogl46/mat_rain_windscreen.frag @@ -406,7 +406,7 @@ float rivWob(Riv r, float dW, out float ramp, out float wobD) ramp = rampT * rampT * (3.0 - 2.0 * rampT); float rampD = 3.0 * rampT * (1.0 - rampT) / 2.5; float a1 = dW * r.wavK + r.wavPh; - float a2 = dW * r.wavK * 1.7 - time * r.wavSp * 1.0472 + r.wavPh * 2.0; // the wave runs DOWN + float a2 = dW * r.wavK * 1.7 - rain_state.w * r.wavSp * 1.0472 + r.wavPh * 2.0; // the wave runs DOWN (the clock of the rain) float w1 = 0.7 * sin(a1) + 0.3 * sin(a2); float w1D = 0.7 * cos(a1) * r.wavK + 0.3 * cos(a2) * r.wavK * 1.7; wobD = -streak_wiggle * (rampD * w1 + ramp * w1D); @@ -535,7 +535,7 @@ void drawRivulet(inout Hit hit, Riv r, vec2 sUVr, vec2 rd1, vec2 rd2) vec2 slope = -nxy / max(nz, 0.08); if (!inHead) slope.y = slope.y * vtSign / STREAK_TAIL_SCALE - slope.x * wobD - + streak_flow * ramp * sin(dW * 4.8 - time * 4.0); + + streak_flow * ramp * sin(dW * 4.8 - rain_state.w * 4.0); // the slope of the layer to the one of the glass if (STREAK_FLIP_Y != 0) slope.y = -slope.y; slope = wsFromLayerDir(slope); @@ -787,7 +787,7 @@ void main() uvec2 mk = cellKey(mc); uint m0 = Hash(uvec3(mk, 51u)); float mLife = micro_life * mix(0.6, 1.6, RandF(m0)); - float mtt = time / mLife + RandF(m0); + float mtt = rain_state.w / mLife + RandF(m0); // the clock of the rain: still when it doesn't rain float mph = fract(mtt); uint mep = uint(mod(floor(mtt), 65521.0)); uint m1 = Hash(uvec3(mk, mep * 4u + 1u)); diff --git a/shaders/ogl46/rain_cells.comp b/shaders/ogl46/rain_cells.comp index 43ab26a60..1756b4009 100644 --- a/shaders/ogl46/rain_cells.comp +++ b/shaders/ogl46/rain_cells.comp @@ -6,7 +6,7 @@ #include "common.glsl" -layout(location = 0) uniform float rain_time; // the time of the block of the scene (scene_ubs.time) +layout(location = 0) uniform float rain_time; // the clock of the rain (scene_ubs.rain_state.w): it runs while it rains, the drops stay as they are when it stops layout(location = 1) uniform float rain_amount; // how wet the glass is (scene_ubs.rain_state.y, a little more) layout(location = 2) uniform int rain_pass; // 0 the cells, 1 the reach of the drops diff --git a/shaders/ogl46/snow_sprites.glsl b/shaders/ogl46/snow_sprites.glsl index a7291d671..015d0b2db 100644 --- a/shaders/ogl46/snow_sprites.glsl +++ b/shaders/ogl46/snow_sprites.glsl @@ -40,6 +40,7 @@ const float SNOW_PACKED = 0.4; // and of packed snow const int TILE_DROP = 15; vec2 snUV = vec2(0.0); // the place on the glass laid, uv +float snDrops = snow_drops; // share of the texels with water showing a drop (water_snowlayer.comp: more when it stopped snowing) int snSlot = 0; uint snMap = 0u; bool snBig = true; // a 4 x 4 atlas (else the older 2 x 2) @@ -167,7 +168,7 @@ void snFlakes(vec2 span, float pixelUV, inout sprite_acc acc) bool crystal = (q.x >= 0.05); if ((false == drop) && (false == crystal)) continue; - if (chance > (drop ? snow_drops * smoothstep(0.03, 0.2, q.y) : snow_crystals)) + if (chance > (drop ? snDrops * smoothstep(0.03, 0.2, q.y) : snow_crystals)) continue; float size = sizeDraw * (drop ? mix(0.7, 1.4, smoothstep(0.03, 0.3, q.y)) : 1.0); if (false == snLocal(p, centre, size, vec2(1.0), rot, flip, 1.0, local)) diff --git a/shaders/ogl46/water_snowlayer.comp b/shaders/ogl46/water_snowlayer.comp index 524f83e95..4181b1615 100644 --- a/shaders/ogl46/water_snowlayer.comp +++ b/shaders/ogl46/water_snowlayer.comp @@ -22,6 +22,9 @@ layout(local_size_x = WATER_GROUP_SIZE) in; // the share of the sweep of a blade around where it went in the step whose snow is laid anew: a lump is laid by the snow at its // middle, up to two of its cells (~3 cm) away from a texel it covers const float SNOW_LAYER_BLADE_MARGIN = 0.06; +// the share of the texels with the water of the melted snow showing a drop when it doesn't snow (while it snows: snow_drops, rare): +// the snow left on the glass melts into drops, which dry +const float SNOW_LAYER_MELT_DROPS = 0.5; // whether a blade went over the texel of the map, or near it, in the step bool snow_layer_swept(uint mapTexel) @@ -67,6 +70,7 @@ void main() if (false == due) return; snSlot = int(slot); + snDrops = (water_step.w > 0.5) ? snow_drops : SNOW_LAYER_MELT_DROPS; snMap = map; snBig = (textureSize(raindropsatlas, 0).x >= 2048); vec2 span = max(vec2(length(water_axes[axis].xyz), length(water_axes[axis + 1u].xyz)), vec2(0.05)); diff --git a/shaders/vk14/common.glsl b/shaders/vk14/common.glsl index fd55c939e..f673bf16d 100644 --- a/shaders/vk14/common.glsl +++ b/shaders/vk14/common.glsl @@ -345,7 +345,7 @@ layout(std140, set = PASS_SET, binding = SCENE_UBO) uniform scene_ubo // the place of the camera of the pass in the world (whole 64 m, the rest), see gl::scene_ubs vec4 camera_hi; vec4 camera_lo; - // the rain the glass meets: x fallen so far, y how wet the glass is, z how fast it fills (mat_rain_windscreen), see gl::scene_ubs + // the rain the glass meets: x fallen so far, y how wet the glass is, z how fast it fills, w the clock of its drops (mat_rain_windscreen), see gl::scene_ubs vec4 rain_state; // the rain fallen when a blade last went over a place of its sweep (the wiper mask / 64), see gl::scene_ubs vec4 wiper_rain_pass[WIPER_PASS_BUCKETS]; diff --git a/shaders/vk14/mat_rain_windscreen.frag b/shaders/vk14/mat_rain_windscreen.frag index 89f1c263f..2338a9341 100644 --- a/shaders/vk14/mat_rain_windscreen.frag +++ b/shaders/vk14/mat_rain_windscreen.frag @@ -411,7 +411,7 @@ float rivWob(Riv r, float dW, out float ramp, out float wobD) ramp = rampT * rampT * (3.0 - 2.0 * rampT); float rampD = 3.0 * rampT * (1.0 - rampT) / 2.5; float a1 = dW * r.wavK + r.wavPh; - float a2 = dW * r.wavK * 1.7 - time * r.wavSp * 1.0472 + r.wavPh * 2.0; // the wave runs DOWN + float a2 = dW * r.wavK * 1.7 - rain_state.w * r.wavSp * 1.0472 + r.wavPh * 2.0; // the wave runs DOWN (the clock of the rain) float w1 = 0.7 * sin(a1) + 0.3 * sin(a2); float w1D = 0.7 * cos(a1) * r.wavK + 0.3 * cos(a2) * r.wavK * 1.7; wobD = -streak_wiggle * (rampD * w1 + ramp * w1D); @@ -540,7 +540,7 @@ void drawRivulet(inout Hit hit, Riv r, vec2 sUVr, vec2 rd1, vec2 rd2) vec2 slope = -nxy / max(nz, 0.08); if (!inHead) slope.y = slope.y * vtSign / STREAK_TAIL_SCALE - slope.x * wobD - + streak_flow * ramp * sin(dW * 4.8 - time * 4.0); + + streak_flow * ramp * sin(dW * 4.8 - rain_state.w * 4.0); // the slope of the layer to the one of the glass if (STREAK_FLIP_Y != 0) slope.y = -slope.y; slope = wsFromLayerDir(slope); @@ -792,7 +792,7 @@ void main() uvec2 mk = cellKey(mc); uint m0 = Hash(uvec3(mk, 51u)); float mLife = micro_life * mix(0.6, 1.6, RandF(m0)); - float mtt = time / mLife + RandF(m0); + float mtt = rain_state.w / mLife + RandF(m0); // the clock of the rain: still when it doesn't rain float mph = fract(mtt); uint mep = uint(mod(floor(mtt), 65521.0)); uint m1 = Hash(uvec3(mk, mep * 4u + 1u)); diff --git a/shaders/vk14/rain_cells.comp b/shaders/vk14/rain_cells.comp index 9b6848a2b..9fb5414c6 100644 --- a/shaders/vk14/rain_cells.comp +++ b/shaders/vk14/rain_cells.comp @@ -10,7 +10,7 @@ layout(push_constant) uniform kernel_constants { - float rain_time; // the time of the block of the scene (scene_ubs.time) + float rain_time; // the clock of the rain (scene_ubs.rain_state.w): it runs while it rains, the drops stay as they are when it stops float rain_amount; // how wet the glass is (scene_ubs.rain_state.y, a little more) int rain_pass; // 0 the cells, 1 the reach of the drops }; diff --git a/shaders/vk14/snow_sprites.glsl b/shaders/vk14/snow_sprites.glsl index a7291d671..015d0b2db 100644 --- a/shaders/vk14/snow_sprites.glsl +++ b/shaders/vk14/snow_sprites.glsl @@ -40,6 +40,7 @@ const float SNOW_PACKED = 0.4; // and of packed snow const int TILE_DROP = 15; vec2 snUV = vec2(0.0); // the place on the glass laid, uv +float snDrops = snow_drops; // share of the texels with water showing a drop (water_snowlayer.comp: more when it stopped snowing) int snSlot = 0; uint snMap = 0u; bool snBig = true; // a 4 x 4 atlas (else the older 2 x 2) @@ -167,7 +168,7 @@ void snFlakes(vec2 span, float pixelUV, inout sprite_acc acc) bool crystal = (q.x >= 0.05); if ((false == drop) && (false == crystal)) continue; - if (chance > (drop ? snow_drops * smoothstep(0.03, 0.2, q.y) : snow_crystals)) + if (chance > (drop ? snDrops * smoothstep(0.03, 0.2, q.y) : snow_crystals)) continue; float size = sizeDraw * (drop ? mix(0.7, 1.4, smoothstep(0.03, 0.3, q.y)) : 1.0); if (false == snLocal(p, centre, size, vec2(1.0), rot, flip, 1.0, local)) diff --git a/shaders/vk14/water_snowlayer.comp b/shaders/vk14/water_snowlayer.comp index a69efdf1f..fbae658a5 100644 --- a/shaders/vk14/water_snowlayer.comp +++ b/shaders/vk14/water_snowlayer.comp @@ -24,6 +24,9 @@ layout(local_size_x = WATER_GROUP_SIZE) in; // the share of the sweep of a blade around where it went in the step whose snow is laid anew: a lump is laid by the snow at its // middle, up to two of its cells (~3 cm) away from a texel it covers const float SNOW_LAYER_BLADE_MARGIN = 0.06; +// the share of the texels with the water of the melted snow showing a drop when it doesn't snow (while it snows: snow_drops, rare): +// the snow left on the glass melts into drops, which dry +const float SNOW_LAYER_MELT_DROPS = 0.5; // whether a blade went over the texel of the map, or near it, in the step bool snow_layer_swept(uint mapTexel) @@ -69,6 +72,7 @@ void main() if (false == due) return; snSlot = int(slot); + snDrops = (water_step.w > 0.5) ? snow_drops : SNOW_LAYER_MELT_DROPS; snMap = map; snBig = (textureSize(raindropsatlas, 0).x >= 2048); vec2 span = max(vec2(length(water_axes[axis].xyz), length(water_axes[axis + 1u].xyz)), vec2(0.05));