diff --git a/rendering/common/windscreenwater.cpp b/rendering/common/windscreenwater.cpp index f5d6e1e48..7dc8d200d 100644 --- a/rendering/common/windscreenwater.cpp +++ b/rendering/common/windscreenwater.cpp @@ -127,6 +127,8 @@ void windscreen_water::release() m_glasses = {}; m_glasscount = 0; m_layerslot = -1; + m_logged.fill(-1); + m_layerlogged = -1; m_kinds.clear(); m_vehicle = nullptr; m_cab = nullptr; @@ -460,6 +462,14 @@ void windscreen_water::update(double const Seconds) auto const *material{m_host.material(glass.material)}; auto const snowed{glass.baked && glass.snow && is_snow_glass(material)}; block.snow_slots[static_cast(slot)] = (snowed ? 1.f : 0.f); + // the state of the glass in the log once it changes: why a glass stays without its water or snow + if (auto const state{(glass.baked ? 1 : 0) | (glass.snow ? 2 : 0) | (glass_kind(material) << 2) | (snowed ? 16 : 0)}; state != m_logged[slot]) + { + m_logged[slot] = state; + WriteLog("windscreen water: glass " + std::to_string(slot + 1) + (glass.baked ? " baked" : " not baked yet (the mask of the wipers not loaded)") + + (glass.snow ? ", built as a glass of the snow" : ", built as a glass of the water") + ", its material now " + + std::to_string(glass_kind(material)) + " (0 none, 1 water, 2 snow)" + (snowed ? ", its snow simulated" : "")); + } anysnow = anysnow || snowed; auto const simulated{glass.baked && (false == glass.snow) && is_water_glass(material)}; glass.landings += static_cast(perground / fall * coming * glass.densest) * seconds; @@ -573,7 +583,12 @@ void windscreen_water::lay_snow(gl::water_ubs const &Block) auto layer{Block}; layer.counts.z = static_cast(slot); layer.counts.w = m_step; - gpu_snow_layer(slot, atlas, normal, layer); + auto const laid{gpu_snow_layer(slot, atlas, normal, layer)}; + if (int const state{laid ? 1 : 0}; state != m_layerlogged) + { + m_layerlogged = state; + WriteLog("windscreen water: the layer of the snow of glass " + std::to_string(slot + 1) + (laid ? " laid" : " not laid (the atlas of the snow not loaded)")); + } } } } diff --git a/rendering/common/windscreenwater.h b/rendering/common/windscreenwater.h index 4acfe991e..29469b9fe 100644 --- a/rendering/common/windscreenwater.h +++ b/rendering/common/windscreenwater.h @@ -124,6 +124,8 @@ class windscreen_water std::array m_glasses{}; std::size_t m_glasscount{0}; int m_layerslot{-1}; // the glass with the layer of the snow, -1 none + std::array m_logged{-1, -1, -1, -1}; // what the log last said of each glass (baked, snow, the shader, simulated) + int m_layerlogged{-1}; // what the log last said of the layer of the snow glm::vec4 m_bladesbefore{-1.f}; double m_time{0.0}; // seconds the simulation runs std::uint32_t m_step{0}; diff --git a/shaders/ogl46/mat_snow_windscreen.frag b/shaders/ogl46/mat_snow_windscreen.frag index e4772cb01..56ca3a8a6 100644 --- a/shaders/ogl46/mat_snow_windscreen.frag +++ b/shaders/ogl46/mat_snow_windscreen.frag @@ -95,6 +95,13 @@ void main() float snowTr = 0.0; float wet = 0.0; snSlot = int(param[2].z + 0.5) - 1; + // the material without its slot (the opengl renderer may give the glass a fresh copy of the material after the weather + // changed, without it): the first glass whose snow the simulation keeps + for (int s = 0; (snSlot < 0) && (s < WATER_SLOTS); ++s) + { + if (water_header[s].z > 0.5) + snSlot = s; + } if ((snSlot >= 0) && (snSlot < WATER_SLOTS) && water_snow_map(uint(snSlot), snMap)) { // the sprites coming within the texel of the layer at the pixel (water_snowlayer.comp) laid at the pixel, sharp from the diff --git a/shaders/ogl46/water_snow.comp b/shaders/ogl46/water_snow.comp index 57e968437..1ca6a8c5a 100644 --- a/shaders/ogl46/water_snow.comp +++ b/shaders/ogl46/water_snow.comp @@ -218,7 +218,7 @@ vec4 snow_move(ivec2 texel, vec4 state, float seconds) vec2 waterout = snow_out(motion.zw, seconds); float snow = state.x * (1.0 - snowout.x - snowout.y); float water = state.y * (1.0 - waterout.x - waterout.y); - float packed = state.z * snow; + float packing = state.z * snow; // (not "packed": a reserved word of GLSL, the NVIDIA OpenGL compiler refuses it) const ivec2 sides[4] = ivec2[4](ivec2(1, 0), ivec2(-1, 0), ivec2(0, 1), ivec2(0, -1)); for (int k = 0; k < 4; ++k) { @@ -244,10 +244,10 @@ vec4 snow_move(ivec2 texel, vec4 state, float seconds) water += (itsmotion.w * float(side.y) < 0.0) ? neighbour.y * itswater.y : 0.0; } snow += coming; - packed += coming * neighbour.z; + packing += coming * neighbour.z; } snow = max(snow, 0.0); - return vec4(snow, max(water, 0.0), (snow > 1e-4) ? clamp(packed / snow, 0.0, 1.0) : 0.0, state.w); + return vec4(snow, max(water, 0.0), (snow > 1e-4) ? clamp(packing / snow, 0.0, 1.0) : 0.0, state.w); } void main() diff --git a/shaders/vk14/mat_snow_windscreen.frag b/shaders/vk14/mat_snow_windscreen.frag index 43f0c455f..5bdd3bdfa 100644 --- a/shaders/vk14/mat_snow_windscreen.frag +++ b/shaders/vk14/mat_snow_windscreen.frag @@ -100,6 +100,13 @@ void main() float snowTr = 0.0; float wet = 0.0; snSlot = int(param[2].z + 0.5) - 1; + // the material without its slot (the opengl renderer may give the glass a fresh copy of the material after the weather + // changed, without it): the first glass whose snow the simulation keeps + for (int s = 0; (snSlot < 0) && (s < WATER_SLOTS); ++s) + { + if (water_header[s].z > 0.5) + snSlot = s; + } if ((snSlot >= 0) && (snSlot < WATER_SLOTS) && water_snow_map(uint(snSlot), snMap)) { // the sprites coming within the texel of the layer at the pixel (water_snowlayer.comp) laid at the pixel, sharp from the diff --git a/shaders/vk14/water_snow.comp b/shaders/vk14/water_snow.comp index 69fa1acad..b7620c7ab 100644 --- a/shaders/vk14/water_snow.comp +++ b/shaders/vk14/water_snow.comp @@ -221,7 +221,7 @@ vec4 snow_move(ivec2 texel, vec4 state, float seconds) vec2 waterout = snow_out(motion.zw, seconds); float snow = state.x * (1.0 - snowout.x - snowout.y); float water = state.y * (1.0 - waterout.x - waterout.y); - float packed = state.z * snow; + float packing = state.z * snow; // (not "packed": a reserved word of GLSL, the NVIDIA OpenGL compiler refuses it) const ivec2 sides[4] = ivec2[4](ivec2(1, 0), ivec2(-1, 0), ivec2(0, 1), ivec2(0, -1)); for (int k = 0; k < 4; ++k) { @@ -247,10 +247,10 @@ vec4 snow_move(ivec2 texel, vec4 state, float seconds) water += (itsmotion.w * float(side.y) < 0.0) ? neighbour.y * itswater.y : 0.0; } snow += coming; - packed += coming * neighbour.z; + packing += coming * neighbour.z; } snow = max(snow, 0.0); - return vec4(snow, max(water, 0.0), (snow > 1e-4) ? clamp(packed / snow, 0.0, 1.0) : 0.0, state.w); + return vec4(snow, max(water, 0.0), (snow > 1e-4) ? clamp(packing / snow, 0.0, 1.0) : 0.0, state.w); } void main()