18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 01:32:43 +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
+59
View File
@@ -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<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
{
@@ -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>(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<std::uint32_t, 8> 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