From dbd786f8b26ff6b4ab6669a8d5dd1e7935c110fa Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Thu, 3 Dec 2026 14:44:27 +0100 Subject: [PATCH] fix(rendering): the turns to the local axes of the body in helpers, out of the long functions of the Vulkan frame Sonar's quality gate of #612 failed on the cognitive complexity of vulkan14_renderer::Render() and render_environment(), which the two curved-body branches raised. They are free functions now; what is drawn does not change. --- rendering/vulkan14/vulkan14frame.cpp | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/rendering/vulkan14/vulkan14frame.cpp b/rendering/vulkan14/vulkan14frame.cpp index b61a944f9..eb4ba2cef 100644 --- a/rendering/vulkan14/vulkan14frame.cpp +++ b/rendering/vulkan14/vulkan14frame.cpp @@ -538,6 +538,26 @@ bool make_targets(vk14::allocator &Memory, vk14::deletion_queue &Deletions, std: return true; } +// the sky and the weather take the sun in the local axes of the body at the camera; its light shades the world, whose axes those are +// only on the plane: on a curved body the direction is turned to the world +glm::vec3 sunlight_in_world(glm::vec3 const &Direction, glm::dvec3 const &Camera) +{ + auto const &body{world_geometry::current_body()}; + if (false == body.curved()) + return Direction; + return glm::vec3{glm::transpose(world_geometry::local_frame(body, Camera)) * glm::dvec3{Direction}}; +} + +// the sun, the moon and the stars are in the local axes of the body at the camera: on a curved body the view of the world is turned +// to them +glm::mat4 view_in_local_axes(glm::mat4 const &Modelview, glm::dvec3 const &Camera) +{ + auto const &body{world_geometry::current_body()}; + if (false == body.curved()) + return Modelview; + return Modelview * glm::mat4{glm::mat3{glm::transpose(world_geometry::local_frame(body, Camera))}}; +} + } // namespace // the frame @@ -839,10 +859,8 @@ bool vulkan14_renderer::Render() ctx.passes.end_async(); m_commands = ctx.commands; } - // the sky and the weather above take the sun in the local axes of the body at the camera; its light shades the world, whose - // axes those are only on the plane - if (auto const &body{world_geometry::current_body()}; body.curved()) - m_sunlight.direction = glm::vec3{glm::transpose(world_geometry::local_frame(body, Global.pCamera.Pos)) * glm::dvec3{m_sunlight.direction}}; + // the sky and the weather above take the sun in the local axes of the body at the camera + m_sunlight.direction = sunlight_in_world(m_sunlight.direction, Global.pCamera.Pos); // lamps of models and vehicles around the camera and the cab lamp, for the views of the frame to take into their light buffers if ((false == Global.gfx_skiprendering) && (simulation::Region != nullptr)) { @@ -2833,11 +2851,8 @@ void vulkan14_renderer::render_environment(world_environment *Environment) ::glPopMatrix(); } - // the sun, the moon and the stars are in the local axes of the body at the camera: on a curved body the view of the world is - // turned to them - glm::mat4 modelview{OpenGLMatrices.data(GL_MODELVIEW)}; - if (auto const &body{world_geometry::current_body()}; body.curved()) - modelview *= glm::mat4{glm::mat3{glm::transpose(world_geometry::local_frame(body, m_renderpass.pass_camera.position()))}}; + // the sun, the moon and the stars are in the local axes of the body at the camera + glm::mat4 const modelview{view_in_local_axes(OpenGLMatrices.data(GL_MODELVIEW), m_renderpass.pass_camera.position())}; // stars of the catalogue, turned by the sidereal time; the fog and the clouds go over them render_stars(modelview); // the bodies give their colour premultiplied, and as alpha how much of the sky behind them they hide (celestial.frag)