From fa72ef72469c4b52bdf1f091976687cac77e3a48 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 7 Jul 2022 13:08:44 +0800 Subject: [PATCH] Fix matrix in GEVulkanCameraSceneNode::render --- .../src/ge_vulkan_camera_scene_node.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/graphics_engine/src/ge_vulkan_camera_scene_node.cpp b/lib/graphics_engine/src/ge_vulkan_camera_scene_node.cpp index b28ded2f2..bfce10b68 100644 --- a/lib/graphics_engine/src/ge_vulkan_camera_scene_node.cpp +++ b/lib/graphics_engine/src/ge_vulkan_camera_scene_node.cpp @@ -1,5 +1,7 @@ #include "ge_vulkan_camera_scene_node.hpp" +#include "ge_main.hpp" +#include "ge_vulkan_driver.hpp" #include "ge_vulkan_dynamic_buffer.hpp" namespace GE @@ -29,16 +31,22 @@ void GEVulkanCameraSceneNode::render() m_ubo_data.m_view_matrix = ViewArea.getTransform(irr::video::ETS_VIEW); m_ubo_data.m_projection_matrix = ViewArea.getTransform(irr::video::ETS_PROJECTION); + // Irrlicht matrix4 was originally designed for OpenGL, + // where the Y coordinate of the clip coordinates is inverted. + // The easiest way to compensate for that is to flip the sign on the + // scaling factor of the Y axis in the projection matrix. + m_ubo_data.m_projection_matrix(1, 1) *= -1.0f; + m_ubo_data.m_projection_matrix = getVKDriver()->getPreRotationMatrix() * + m_ubo_data.m_projection_matrix; irr::core::matrix4 mat; ViewArea.getTransform(irr::video::ETS_VIEW).getInverse(mat); m_ubo_data.m_inverse_view_matrix = mat; - ViewArea.getTransform(irr::video::ETS_PROJECTION).getInverse(mat); + m_ubo_data.m_projection_matrix.getInverse(mat); m_ubo_data.m_inverse_projection_matrix = mat; - mat = ViewArea.getTransform(irr::video::ETS_PROJECTION) * - ViewArea.getTransform(irr::video::ETS_VIEW); + mat = m_ubo_data.m_projection_matrix * m_ubo_data.m_view_matrix; m_ubo_data.m_projection_view_matrix = mat; } // render