18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 21:07:06 +01:00

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
This commit is contained in:
Claude
2026-11-14 23:14:37 +01:00
parent 10b723106e
commit e8a0e78677
17 changed files with 114 additions and 19 deletions
+2 -1
View File
@@ -208,7 +208,8 @@ namespace gl
glm::vec4 camera_lo; 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 // 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, // 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; 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) // 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 // / 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
+59
View File
@@ -29,6 +29,35 @@ http://mozilla.org/MPL/2.0/.
namespace gfx 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<opengl_material::texture_set> texture_variants;
std::array<glm::vec4, gl::MAX_PARAMS> params{};
std::vector<gfx::shader_param_entry> params_state;
std::shared_ptr<gfx::shader_program> shader;
std::optional<float> opacity;
std::optional<float> 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 namespace
{ {
@@ -295,6 +324,10 @@ void windscreen_water::build(TModel3d &Cab)
glass.material = material; glass.material = material;
auto const *opengl{m_host.material(material)}; auto const *opengl{m_host.material(material)};
glass.snow = is_snow_glass(opengl); glass.snow = is_snow_glass(opengl);
if (glass.snow)
{
glass.snowmaterial = std::make_shared<snow_look>(snow_look::of(*opengl));
}
glass.mask = opengl->textures[opengl->shader->texture_conf.at("wipermask").id]; glass.mask = opengl->textures[opengl->shader->texture_conf.at("wipermask").id];
for (std::size_t texel = 0; texel < texels; ++texel) 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 const *vehicle{simulation::Train != nullptr ? simulation::Train->Dynamic() : nullptr};
auto *cab{vehicle != nullptr ? vehicle->mdKabina : 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 // 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) // 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; })}; 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<std::uint32_t, 8> windscreen_water::layer_info(std::size_t const Slot
return info; 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) void windscreen_water::lay_snow(gl::water_ubs const &Block)
{ {
// the one glass with the layer // the one glass with the layer
+9
View File
@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
@@ -29,6 +30,8 @@ class TDynamicObject;
namespace gfx 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. // 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 // 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 double landings{0.0}; // the share of a landing left over from the steps before
bool baked{false}; bool baked{false};
bool snow{false}; // a glass of the snow (mat_snow_windscreen), else of the water 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<snow_look> snowmaterial;
}; };
// the glasses of the model of a cab found and set up // the glasses of the model of a cab found and set up
@@ -105,6 +111,9 @@ class windscreen_water
void assign(bool Assigned); void assign(bool Assigned);
// the snow of the glasses of the snow Block says are simulated laid together, after the step // 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); 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: 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 // 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
+10 -3
View File
@@ -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 speed{(owner != nullptr) ? std::min(std::abs(owner->MoverParameters->V) * 3.6 / 100.0, 1.0) : 0.0};
auto const meet{static_cast<double>(percipitation_intensity) * (1.0 + fill_speed * speed)}; auto const meet{static_cast<double>(percipitation_intensity) * (1.0 + fill_speed * speed)};
m_wiperrain += dt * meet; 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_glasswet += (1.0 - m_glasswet) * (1.0 - std::exp(-fill_rate * dt * meet));
m_raintime += dt;
}
else else
m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed)); m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed));
scene_ubs.rain_state = glm::vec4{static_cast<float>(m_wiperrain), static_cast<float>(m_glasswet), static_cast<float>(fill_rate), 0.f}; scene_ubs.rain_state = glm::vec4{static_cast<float>(m_wiperrain), static_cast<float>(m_glasswet), static_cast<float>(fill_rate), static_cast<float>(m_raintime)};
} }
if (owner != nullptr) if (owner != nullptr)
{ {
@@ -1740,7 +1747,7 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
m_windscreenwater.update(Timer::GetDeltaTime()); 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 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) // (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<float>(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(); m_windscreenwater.bind();
+1
View File
@@ -855,6 +855,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) // the rain the glass met so far and how wet it is (scene_ubs::rain_state)
double m_wiperrain{0.0}; double m_wiperrain{0.0};
double m_glasswet{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; gl::light_data light_data;
std::unordered_map<std::string, std::shared_ptr<gl::program>> m_shaders; std::unordered_map<std::string, std::shared_ptr<gl::program>> m_shaders;
+10 -3
View File
@@ -1048,7 +1048,7 @@ void vulkan14_renderer::render_scene()
scene.water.update(Timer::GetDeltaTime()); 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 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) // (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<float>(Timer::GetTime()), (m_glasswet > 0.001) ? static_cast<float>(std::min(m_glasswet + 0.01, 1.0)) : 0.f); scene.water.update_rain_cells(static_cast<float>(m_raintime), (m_glasswet > 0.001) ? static_cast<float>(std::min(m_glasswet + 0.01, 1.0)) : 0.f);
if (scene.targets.size() < m_viewports.size()) if (scene.targets.size() < m_viewports.size())
{ {
scene.targets.resize(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 speed{(owner != nullptr) ? std::min(std::abs(owner->MoverParameters->V) * 3.6 / 100.0, 1.0) : 0.0};
auto const meet{static_cast<double>(percipitation_intensity) * (1.0 + fill_speed * speed)}; auto const meet{static_cast<double>(percipitation_intensity) * (1.0 + fill_speed * speed)};
m_wiperrain += dt * meet; 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_glasswet += (1.0 - m_glasswet) * (1.0 - std::exp(-fill_rate * dt * meet));
m_raintime += dt;
}
else else
m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed)); m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed));
scene_ubs.rain_state = glm::vec4{static_cast<float>(m_wiperrain), static_cast<float>(m_glasswet), static_cast<float>(fill_rate), 0.f}; scene_ubs.rain_state = glm::vec4{static_cast<float>(m_wiperrain), static_cast<float>(m_glasswet), static_cast<float>(fill_rate), static_cast<float>(m_raintime)};
} }
if (owner != nullptr) if (owner != nullptr)
{ {
+1
View File
@@ -557,6 +557,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) // the rain the glass met so far and how wet it is (scene_ubs::rain_state)
double m_wiperrain{0.0}; double m_wiperrain{0.0};
double m_glasswet{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{}; gl::light_data light_data{};
std::uint32_t m_lightcount{1}; // lights written to 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 // the copies of the light buffer in the ring of the frame since the lights were last written, by the header and the sun
+1 -1
View File
@@ -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 // 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_hi;
vec4 camera_lo; 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; 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 // 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]; vec4 wiper_rain_pass[WIPER_PASS_BUCKETS];
+3 -3
View File
@@ -406,7 +406,7 @@ float rivWob(Riv r, float dW, out float ramp, out float wobD)
ramp = rampT * rampT * (3.0 - 2.0 * rampT); ramp = rampT * rampT * (3.0 - 2.0 * rampT);
float rampD = 3.0 * rampT * (1.0 - rampT) / 2.5; float rampD = 3.0 * rampT * (1.0 - rampT) / 2.5;
float a1 = dW * r.wavK + r.wavPh; 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 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; float w1D = 0.7 * cos(a1) * r.wavK + 0.3 * cos(a2) * r.wavK * 1.7;
wobD = -streak_wiggle * (rampD * w1 + ramp * w1D); 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); vec2 slope = -nxy / max(nz, 0.08);
if (!inHead) if (!inHead)
slope.y = slope.y * vtSign / STREAK_TAIL_SCALE - slope.x * wobD 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 // the slope of the layer to the one of the glass
if (STREAK_FLIP_Y != 0) slope.y = -slope.y; if (STREAK_FLIP_Y != 0) slope.y = -slope.y;
slope = wsFromLayerDir(slope); slope = wsFromLayerDir(slope);
@@ -787,7 +787,7 @@ void main()
uvec2 mk = cellKey(mc); uvec2 mk = cellKey(mc);
uint m0 = Hash(uvec3(mk, 51u)); uint m0 = Hash(uvec3(mk, 51u));
float mLife = micro_life * mix(0.6, 1.6, RandF(m0)); 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); float mph = fract(mtt);
uint mep = uint(mod(floor(mtt), 65521.0)); uint mep = uint(mod(floor(mtt), 65521.0));
uint m1 = Hash(uvec3(mk, mep * 4u + 1u)); uint m1 = Hash(uvec3(mk, mep * 4u + 1u));
+1 -1
View File
@@ -6,7 +6,7 @@
#include "common.glsl" #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 = 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 layout(location = 2) uniform int rain_pass; // 0 the cells, 1 the reach of the drops
+2 -1
View File
@@ -40,6 +40,7 @@ const float SNOW_PACKED = 0.4; // and of packed snow
const int TILE_DROP = 15; const int TILE_DROP = 15;
vec2 snUV = vec2(0.0); // the place on the glass laid, uv 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; int snSlot = 0;
uint snMap = 0u; uint snMap = 0u;
bool snBig = true; // a 4 x 4 atlas (else the older 2 x 2) 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); bool crystal = (q.x >= 0.05);
if ((false == drop) && (false == crystal)) if ((false == drop) && (false == crystal))
continue; 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; continue;
float size = sizeDraw * (drop ? mix(0.7, 1.4, smoothstep(0.03, 0.3, q.y)) : 1.0); 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)) if (false == snLocal(p, centre, size, vec2(1.0), rot, flip, 1.0, local))
+4
View File
@@ -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 // 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 // middle, up to two of its cells (~3 cm) away from a texel it covers
const float SNOW_LAYER_BLADE_MARGIN = 0.06; 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 // whether a blade went over the texel of the map, or near it, in the step
bool snow_layer_swept(uint mapTexel) bool snow_layer_swept(uint mapTexel)
@@ -67,6 +70,7 @@ void main()
if (false == due) if (false == due)
return; return;
snSlot = int(slot); snSlot = int(slot);
snDrops = (water_step.w > 0.5) ? snow_drops : SNOW_LAYER_MELT_DROPS;
snMap = map; snMap = map;
snBig = (textureSize(raindropsatlas, 0).x >= 2048); snBig = (textureSize(raindropsatlas, 0).x >= 2048);
vec2 span = max(vec2(length(water_axes[axis].xyz), length(water_axes[axis + 1u].xyz)), vec2(0.05)); vec2 span = max(vec2(length(water_axes[axis].xyz), length(water_axes[axis + 1u].xyz)), vec2(0.05));
+1 -1
View File
@@ -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 // 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_hi;
vec4 camera_lo; 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; 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 // 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]; vec4 wiper_rain_pass[WIPER_PASS_BUCKETS];
+3 -3
View File
@@ -411,7 +411,7 @@ float rivWob(Riv r, float dW, out float ramp, out float wobD)
ramp = rampT * rampT * (3.0 - 2.0 * rampT); ramp = rampT * rampT * (3.0 - 2.0 * rampT);
float rampD = 3.0 * rampT * (1.0 - rampT) / 2.5; float rampD = 3.0 * rampT * (1.0 - rampT) / 2.5;
float a1 = dW * r.wavK + r.wavPh; 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 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; float w1D = 0.7 * cos(a1) * r.wavK + 0.3 * cos(a2) * r.wavK * 1.7;
wobD = -streak_wiggle * (rampD * w1 + ramp * w1D); 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); vec2 slope = -nxy / max(nz, 0.08);
if (!inHead) if (!inHead)
slope.y = slope.y * vtSign / STREAK_TAIL_SCALE - slope.x * wobD 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 // the slope of the layer to the one of the glass
if (STREAK_FLIP_Y != 0) slope.y = -slope.y; if (STREAK_FLIP_Y != 0) slope.y = -slope.y;
slope = wsFromLayerDir(slope); slope = wsFromLayerDir(slope);
@@ -792,7 +792,7 @@ void main()
uvec2 mk = cellKey(mc); uvec2 mk = cellKey(mc);
uint m0 = Hash(uvec3(mk, 51u)); uint m0 = Hash(uvec3(mk, 51u));
float mLife = micro_life * mix(0.6, 1.6, RandF(m0)); 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); float mph = fract(mtt);
uint mep = uint(mod(floor(mtt), 65521.0)); uint mep = uint(mod(floor(mtt), 65521.0));
uint m1 = Hash(uvec3(mk, mep * 4u + 1u)); uint m1 = Hash(uvec3(mk, mep * 4u + 1u));
+1 -1
View File
@@ -10,7 +10,7 @@
layout(push_constant) uniform kernel_constants 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) 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 int rain_pass; // 0 the cells, 1 the reach of the drops
}; };
+2 -1
View File
@@ -40,6 +40,7 @@ const float SNOW_PACKED = 0.4; // and of packed snow
const int TILE_DROP = 15; const int TILE_DROP = 15;
vec2 snUV = vec2(0.0); // the place on the glass laid, uv 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; int snSlot = 0;
uint snMap = 0u; uint snMap = 0u;
bool snBig = true; // a 4 x 4 atlas (else the older 2 x 2) 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); bool crystal = (q.x >= 0.05);
if ((false == drop) && (false == crystal)) if ((false == drop) && (false == crystal))
continue; 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; continue;
float size = sizeDraw * (drop ? mix(0.7, 1.4, smoothstep(0.03, 0.3, q.y)) : 1.0); 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)) if (false == snLocal(p, centre, size, vec2(1.0), rot, flip, 1.0, local))
+4
View File
@@ -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 // 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 // middle, up to two of its cells (~3 cm) away from a texel it covers
const float SNOW_LAYER_BLADE_MARGIN = 0.06; 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 // whether a blade went over the texel of the map, or near it, in the step
bool snow_layer_swept(uint mapTexel) bool snow_layer_swept(uint mapTexel)
@@ -69,6 +72,7 @@ void main()
if (false == due) if (false == due)
return; return;
snSlot = int(slot); snSlot = int(slot);
snDrops = (water_step.w > 0.5) ? snow_drops : SNOW_LAYER_MELT_DROPS;
snMap = map; snMap = map;
snBig = (textureSize(raindropsatlas, 0).x >= 2048); snBig = (textureSize(raindropsatlas, 0).x >= 2048);
vec2 span = max(vec2(length(water_axes[axis].xyz), length(water_axes[axis + 1u].xyz)), vec2(0.05)); vec2 span = max(vec2(length(water_axes[axis].xyz), length(water_axes[axis + 1u].xyz)), vec2(0.05));