diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp index 4180d3b12..f937e5f60 100644 --- a/rendering/opengl46/opengl46renderer.cpp +++ b/rendering/opengl46/opengl46renderer.cpp @@ -1625,13 +1625,26 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode) air -= owner->VectorFront() * owner->MoverParameters->V; scene_ubs.rain_wind = glm::vec4{glm::vec3{air}, 0.f}; } - if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->MoverParameters->CabActive) + // the wipers of the vehicle the camera is in, or of the train driven when the camera is outside it: the moments the blades + // were at the ends of their sweep (the drops on the glass come back from then) are kept while the camera is away, so the glass + // looks as the blades left it when it's back in the cab. they're forgotten only for another vehicle + TDynamicObject const *owner = Global.pCamera.m_owner; + if ((owner == nullptr) || (owner->MoverParameters->CabActive == 0)) + owner = (simulation::Train != nullptr) ? simulation::Train->Dynamic() : nullptr; + if (owner != m_wipervehicle) { + m_wipervehicle = owner; + scene_ubs.wiper_timer_out = glm::vec4{-1000.}; + scene_ubs.wiper_timer_return = glm::vec4{-1000.}; + } + if (owner != nullptr) + { + auto const cabactive{owner->MoverParameters->CabActive != 0 ? owner->MoverParameters->CabActive : 1}; for (int i = 0; i < 4; ++i) { if (i < owner->dWiperPos.size()) { - int index = owner->MoverParameters->CabActive > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; + int index = cabactive > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; scene_ubs.wiper_pos[i] = owner->dWiperPos[index]; if (owner->dWiperPos[index] > 0. && owner->wiperDirection[index]) { @@ -1657,8 +1670,6 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode) else { scene_ubs.wiper_pos = glm::vec4{0.}; - scene_ubs.wiper_timer_out = glm::vec4{-1000.}; - scene_ubs.wiper_timer_return = glm::vec4{-1000.}; } } // the reflections: the ground below the horizon of the environment map, and the screen space ones set up for the colour diff --git a/rendering/opengl46/opengl46renderer.h b/rendering/opengl46/opengl46renderer.h index 08d92e4b7..08b9116e9 100644 --- a/rendering/opengl46/opengl46renderer.h +++ b/rendering/opengl46/opengl46renderer.h @@ -844,6 +844,8 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk { // persistently mapped with Global.gfx_bufferstreaming std::unique_ptr m_instancestream; gl::scene_ubs scene_ubs; + // the vehicle whose wipers the timers of the blades in scene_ubs (wiper_timer_out / wiper_timer_return) follow + TDynamicObject const *m_wipervehicle{nullptr}; gl::light_data light_data; std::unordered_map> m_shaders; diff --git a/rendering/vulkan14/vulkan14frame.cpp b/rendering/vulkan14/vulkan14frame.cpp index 82aa2645d..694a71891 100644 --- a/rendering/vulkan14/vulkan14frame.cpp +++ b/rendering/vulkan14/vulkan14frame.cpp @@ -1489,13 +1489,26 @@ void vulkan14_renderer::render_viewport(std::size_t const Index) air -= owner->VectorFront() * owner->MoverParameters->V; scene_ubs.rain_wind = glm::vec4{glm::vec3{air}, 0.f}; } - if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->MoverParameters->CabActive) + // the wipers of the vehicle the camera is in, or of the train driven when the camera is outside it: the moments the blades + // were at the ends of their sweep (the drops on the glass come back from then) are kept while the camera is away, so the glass + // looks as the blades left it when it's back in the cab. they're forgotten only for another vehicle + TDynamicObject const *owner = Global.pCamera.m_owner; + if ((owner == nullptr) || (owner->MoverParameters->CabActive == 0)) + owner = (simulation::Train != nullptr) ? simulation::Train->Dynamic() : nullptr; + if (owner != m_wipervehicle) { + m_wipervehicle = owner; + scene_ubs.wiper_timer_out = glm::vec4{-1000.}; + scene_ubs.wiper_timer_return = glm::vec4{-1000.}; + } + if (owner != nullptr) + { + auto const cabactive{owner->MoverParameters->CabActive != 0 ? owner->MoverParameters->CabActive : 1}; for (int i = 0; i < 4; ++i) { if (i < owner->dWiperPos.size()) { - int index = owner->MoverParameters->CabActive > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; + int index = cabactive > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; scene_ubs.wiper_pos[i] = owner->dWiperPos[index]; if (owner->dWiperPos[index] > 0. && owner->wiperDirection[index]) { @@ -1521,8 +1534,6 @@ void vulkan14_renderer::render_viewport(std::size_t const Index) else { scene_ubs.wiper_pos = glm::vec4{0.}; - scene_ubs.wiper_timer_out = glm::vec4{-1000.}; - scene_ubs.wiper_timer_return = glm::vec4{-1000.}; } } // the stages after D: no contact shadows, no cascades fitted to the depth, no shadow maps of headlights diff --git a/rendering/vulkan14/vulkan14renderer.h b/rendering/vulkan14/vulkan14renderer.h index 66cf70fd3..f73dc98fa 100644 --- a/rendering/vulkan14/vulkan14renderer.h +++ b/rendering/vulkan14/vulkan14renderer.h @@ -550,6 +550,8 @@ class vulkan14_renderer : public gfx_renderer, public gfx::scene_walk glm::vec3 m_fogcolor{0.f}; glm::vec4 m_shadowcolor{colors::shadow}; gl::scene_ubs scene_ubs{}; + // the vehicle whose wipers the timers of the blades in scene_ubs (wiper_timer_out / wiper_timer_return) follow + TDynamicObject const *m_wipervehicle{nullptr}; 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