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

Windscreen water: the review of 27.11 (the snow list stops when full, the cells of the rain only for a cab with a glass of the rain)

- snList() stops listing when its SN_REFS are taken: no lumps worked out for nothing, and the cover of the texel counts only the
  sprites the glass lays (no gaps where it took the dropped ones for covering); OpenGL 4.6 and Vulkan
- update_rain_cells() gets no rain for a cab without a material of the shader of the rain in this weather
  (windscreen_water::wants_rain_cells(); as before when the simulation isn't used)
- Vulkan: a rain-cell buffer which can't be made leaves the glasses with rain dry (a small stand-in the pass sets hold) instead of
  failing the whole windscreen water; it is still made at the start, since the pass sets and those of the cullings hold it

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-27 12:42:31 +01:00
parent a9579a9841
commit 160e8b8a46
8 changed files with 56 additions and 16 deletions
+15
View File
@@ -130,6 +130,7 @@ void windscreen_water::release()
m_logged.fill(-1);
m_layerlogged = -1;
m_kinds.clear();
m_cabmaterials.clear();
m_vehicle = nullptr;
m_cab = nullptr;
}
@@ -272,6 +273,8 @@ void windscreen_water::build(TModel3d &Cab)
}
}
auto const material{Submodel->m_material};
if ((material != null_handle) && (material > 0) && (Submodel->eType == GL_TRIANGLES) && (std::find(m_cabmaterials.begin(), m_cabmaterials.end(), material) == m_cabmaterials.end()))
m_cabmaterials.push_back(material);
if ((material != null_handle) && (material > 0) && (Submodel->eType == GL_TRIANGLES) && std::ranges::none_of(m_kinds, [material](auto const &Kind) { return Kind.first == material; }))
{
// every material with a mask of the wipers, what it is kept: it's a glass of another kind when the weather changes
@@ -362,6 +365,18 @@ void windscreen_water::build(TModel3d &Cab)
}
}
bool windscreen_water::wants_rain_cells()
{
// without the simulation the cab isn't looked at: the cells as before, whenever it rains
if (m_state <= 0)
return true;
// a material of the cab of the shader of the rain, as it is in this weather (with a mask of the wipers or without)
return std::ranges::any_of(m_cabmaterials, [this](material_handle const Material) {
auto const *opengl{m_host.material(Material)};
return (opengl != nullptr) && (opengl->shader != nullptr) && (opengl->shader->param_conf.count("water_slot") > 0);
});
}
void windscreen_water::update(double const Seconds)
{
if (false == available())
+4
View File
@@ -63,6 +63,9 @@ class windscreen_water
// once a frame, before the colour passes: the cab of the train followed, the step of the simulation run. Seconds: of the
// simulation since the frame before (0 when it's paused)
void update(double Seconds);
// whether the glasses need the cells of the rain worked out: the cab of the train has a glass of the rain (or the simulation
// isn't used, the cab not looked at)
bool wants_rain_cells();
// the materials let go of their slots, the glasses forgotten (the storage stays as it is, unused)
void release();
std::string info() const;
@@ -121,6 +124,7 @@ class windscreen_water
int m_state{0}; // 0: not set up yet, 1: ready, -1: can't be used
TDynamicObject const *m_vehicle{nullptr};
TModel3d const *m_cab{nullptr};
std::vector<material_handle> m_cabmaterials; // the materials of the cab (for the glasses with rain it has, wants_rain_cells())
std::vector<std::pair<material_handle, int>> m_kinds; // the materials of the cab with a mask of the wipers, what kind of glass they were
std::array<glass, gl::WATER_SLOTS> m_glasses{};
std::size_t m_glasscount{0};
+2 -1
View File
@@ -1808,7 +1808,8 @@ 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);
// (none for a cab without a glass of the rain)
m_windscreenwater.update_rain_cells(scene_ubs.time, ((scene_ubs.rain_state.y > 0.001f) && m_windscreenwater.wants_rain_cells()) ? std::min(scene_ubs.rain_state.y + 0.01f, 1.f) : 0.f);
}
m_windscreenwater.bind();
+2 -1
View File
@@ -1137,7 +1137,8 @@ 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<float>(Timer::GetTime()), (m_glasswet > 0.001) ? static_cast<float>(std::min(m_glasswet + 0.01, 1.0)) : 0.f);
// (none for a cab without a glass of the rain)
scene.water.update_rain_cells(static_cast<float>(Timer::GetTime()), ((m_glasswet > 0.001) && scene.water.wants_rain_cells()) ? static_cast<float>(std::min(m_glasswet + 0.01, 1.0)) : 0.f);
if (scene.targets.size() < m_viewports.size())
{
scene.targets.resize(m_viewports.size());
+14 -4
View File
@@ -51,11 +51,20 @@ bool windscreen_water::init(VkDevice const Device, pipeline_library &Pipelines,
m_ring = &Ring;
m_alignment = std::max<VkDeviceSize>(Alignment, 16);
m_host = std::move(Host);
// the cells of the rain: the pass sets hold their buffer from the start (made later, the sets of the passes and of the cullings
// would have to be written anew in the middle of a frame). without it a small stand-in, which no glass reads (the glasses with
// rain stay dry, the rest of the simulation works on)
m_raincells = std::make_shared<buffer>();
if (false == m_raincells->create(Memory, static_cast<VkDeviceSize>(gl::RAIN_CELLS_COUNT * 16), storage_usage, memory_kind::device, "rain cells"))
m_raincellsfull = m_raincells->create(Memory, static_cast<VkDeviceSize>(gl::RAIN_CELLS_COUNT * 16), storage_usage, memory_kind::device, "rain cells");
if (false == m_raincellsfull)
{
m_raincells.reset();
return false;
ErrorLog("rain cells: no storage of " + std::to_string(gl::RAIN_CELLS_COUNT * 16 / (1024 * 1024)) + " MiB, the glasses with rain stay dry");
m_raincells = std::make_shared<buffer>();
if (false == m_raincells->create(Memory, 65536, storage_usage, memory_kind::device, "rain cells"))
{
m_raincells.reset();
return false;
}
}
m_storage = std::make_shared<buffer>();
m_full = m_storage->create(Memory, static_cast<VkDeviceSize>(gl::WATER_STORAGE_SIZE), storage_usage, memory_kind::device, "windscreen water");
@@ -85,6 +94,7 @@ void windscreen_water::destroy()
}
m_raincellkernel.destroy(m_device);
m_raincelltried = false;
m_raincellsfull = false;
m_raincells.reset();
m_storage.reset();
m_device = VK_NULL_HANDLE;
@@ -199,7 +209,7 @@ void windscreen_water::gpu_setup(std::size_t const Slot, std::vector<glm::vec4>
void windscreen_water::update_rain_cells(float const Time, float const Rain)
{
if ((m_device == VK_NULL_HANDLE) || (false == bool(m_raincells)) || (Rain <= 0.f) || (false == bool(m_host.commands)))
if ((m_device == VK_NULL_HANDLE) || (false == bool(m_raincells)) || (false == m_raincellsfull) || (Rain <= 0.f) || (false == bool(m_host.commands)))
{
return;
}
+1
View File
@@ -103,6 +103,7 @@ class windscreen_water : public gfx::windscreen_water
std::shared_ptr<buffer> m_raincells;
compute_kernel m_raincellkernel;
bool m_raincelltried{false};
bool m_raincellsfull{false}; // the cells of the rain have their storage (else a stand-in: the glasses with rain stay dry)
bool m_full{false}; // the storage is as large as the simulation needs (else a stand-in, the glasses make their water up)
bool m_cleared{false};
bool m_snowkernels{true}; // the passes of the snow made (they are optional: without them the glasses of the snow stay clear)
+9 -5
View File
@@ -349,7 +349,7 @@ snow_layer_s snCompose(vec2 uv, vec2 span, float pixelUV)
// 1 + the list (0 the flakes, 1 .. SN_GRIDS the grids of the lumps) times 16 + the cell around the texel (0 .. 8: 1 - the column
// offset + 3 * (1 - the row offset)), 0 after the last one (a layer cleared to zeros lists nothing). the glass lays only those at
// its pixels, sharp from the atlas as when it laid all of the cells around itself, at a fraction of the cost
const int SN_REFS = 6; // the top ones: those under them are covered (sixteen fit in the four uint)
const int SN_REFS = 6; // the top ones, the listing stops when full (sixteen fit in the four uint; 8 if thick snow shows gaps)
// the sprites over a texel covering it on the whole (the level of the atlas the size of the texel): those under it are left out
const float SN_LIST_COVERED = 0.97;
@@ -380,19 +380,23 @@ uvec4 snList(vec2 uv, vec2 span, float pixelUV)
float reachF = half_diagonal * max(perF.x, perF.y) * 1.25;
for (int k = 0; k < 9; ++k)
{
if ((count < 2) && snFlakeCell(pF, hereF + ivec2(1 - k % 3, 1 - k / 3), perF, pixelUV, reachF, flakes))
snRef(uint(k), refs, count); // two flakes at most, the rest of the list for the lumps
if (count >= 2)
break; // two flakes at most, the rest of the list for the lumps
if (snFlakeCell(pF, hereF + ivec2(1 - k % 3, 1 - k / 3), perF, pixelUV, reachF, flakes))
snRef(uint(k), refs, count);
}
vec2 perL = span / snow_lump_cell;
float reachL = half_diagonal * max(perL.x, perL.y) * 1.25 + 0.05;
for (int g = 0; g < SN_GRIDS; ++g)
{
if (layer.a >= SN_LIST_COVERED)
break; // the grids over this one cover the texel
if ((layer.a >= SN_LIST_COVERED) || (count >= SN_REFS))
break; // the grids over this one cover the texel, or the list is full
vec2 pL = uv * perL + sn_grids[g].shift;
ivec2 hereL = ivec2(floor(pL));
for (int k = 0; k < 9; ++k)
{
if (count >= SN_REFS)
break; // the list is full: nothing more worked out, and the cover counts only the sprites the glass lays
if (snLumpCell(pL, hereL + ivec2(1 - k % 3, 1 - k / 3), perL, sn_grids[g], pixelUV, reachL, layer))
snRef(uint(16 * (g + 1) + k), refs, count);
}
+9 -5
View File
@@ -349,7 +349,7 @@ snow_layer_s snCompose(vec2 uv, vec2 span, float pixelUV)
// 1 + the list (0 the flakes, 1 .. SN_GRIDS the grids of the lumps) times 16 + the cell around the texel (0 .. 8: 1 - the column
// offset + 3 * (1 - the row offset)), 0 after the last one (a layer cleared to zeros lists nothing). the glass lays only those at
// its pixels, sharp from the atlas as when it laid all of the cells around itself, at a fraction of the cost
const int SN_REFS = 6; // the top ones: those under them are covered (sixteen fit in the four uint)
const int SN_REFS = 6; // the top ones, the listing stops when full (sixteen fit in the four uint; 8 if thick snow shows gaps)
// the sprites over a texel covering it on the whole (the level of the atlas the size of the texel): those under it are left out
const float SN_LIST_COVERED = 0.97;
@@ -380,19 +380,23 @@ uvec4 snList(vec2 uv, vec2 span, float pixelUV)
float reachF = half_diagonal * max(perF.x, perF.y) * 1.25;
for (int k = 0; k < 9; ++k)
{
if ((count < 2) && snFlakeCell(pF, hereF + ivec2(1 - k % 3, 1 - k / 3), perF, pixelUV, reachF, flakes))
snRef(uint(k), refs, count); // two flakes at most, the rest of the list for the lumps
if (count >= 2)
break; // two flakes at most, the rest of the list for the lumps
if (snFlakeCell(pF, hereF + ivec2(1 - k % 3, 1 - k / 3), perF, pixelUV, reachF, flakes))
snRef(uint(k), refs, count);
}
vec2 perL = span / snow_lump_cell;
float reachL = half_diagonal * max(perL.x, perL.y) * 1.25 + 0.05;
for (int g = 0; g < SN_GRIDS; ++g)
{
if (layer.a >= SN_LIST_COVERED)
break; // the grids over this one cover the texel
if ((layer.a >= SN_LIST_COVERED) || (count >= SN_REFS))
break; // the grids over this one cover the texel, or the list is full
vec2 pL = uv * perL + sn_grids[g].shift;
ivec2 hereL = ivec2(floor(pL));
for (int k = 0; k < 9; ++k)
{
if (count >= SN_REFS)
break; // the list is full: nothing more worked out, and the cover counts only the sprites the glass lays
if (snLumpCell(pL, hereL + ivec2(1 - k % 3, 1 - k / 3), perL, sn_grids[g], pixelUV, reachL, layer))
snRef(uint(16 * (g + 1) + k), refs, count);
}