From 84b6fcfb44105c2662eb5351f27cc6f09e065837 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sat, 5 Mar 2022 18:30:30 -0500 Subject: [PATCH] Remove forRenderer from CGraphics PerspectiveProjectionMatrix --- Runtime/Camera/CGameCamera.cpp | 5 +- Runtime/Camera/CGameCamera.hpp | 4 +- Runtime/Graphics/CGraphics.cpp | 121 ++++-------------- Runtime/Graphics/CGraphics.hpp | 7 +- Runtime/Graphics/CLineRenderer.cpp | 4 +- Runtime/Graphics/Shaders/CAABoxShader.cpp | 2 +- .../Graphics/Shaders/CColoredStripShader.cpp | 2 +- Runtime/Graphics/Shaders/CEnergyBarShader.cpp | 2 +- .../Shaders/CFogVolumePlaneShader.cpp | 2 +- .../Graphics/Shaders/CMapSurfaceShader.cpp | 2 +- .../Graphics/Shaders/CRadarPaintShader.cpp | 2 +- .../Graphics/Shaders/CTexturedQuadFilter.cpp | 2 +- .../Graphics/Shaders/CWorldShadowShader.cpp | 2 +- Runtime/GuiSys/CGuiCamera.cpp | 4 +- Runtime/GuiSys/CGuiFrame.cpp | 2 +- Runtime/Particle/CDecal.cpp | 2 +- Runtime/Particle/CElementGen.cpp | 6 +- Runtime/Particle/CParticleSwoosh.cpp | 2 +- Runtime/World/CEnvFxManager.cpp | 6 +- aurora/lib/gfx/common.cpp | 7 +- 20 files changed, 61 insertions(+), 125 deletions(-) diff --git a/Runtime/Camera/CGameCamera.cpp b/Runtime/Camera/CGameCamera.cpp index d86d7c825..41aa31591 100644 --- a/Runtime/Camera/CGameCamera.cpp +++ b/Runtime/Camera/CGameCamera.cpp @@ -44,9 +44,8 @@ void CGameCamera::SetActive(bool active) { zeus::CMatrix4f CGameCamera::GetPerspectiveMatrix() const { if (x170_24_perspDirty) { - const_cast(this)->xec_perspectiveMatrix = - CGraphics::CalculatePerspectiveMatrix(x15c_currentFov, x168_aspect, x160_znear, x164_zfar, false); - const_cast(this)->x170_24_perspDirty = false; + xec_perspectiveMatrix = CGraphics::CalculatePerspectiveMatrix(x15c_currentFov, x168_aspect, x160_znear, x164_zfar); + x170_24_perspDirty = false; } return xec_perspectiveMatrix; diff --git a/Runtime/Camera/CGameCamera.hpp b/Runtime/Camera/CGameCamera.hpp index 0950cc897..db98ff966 100644 --- a/Runtime/Camera/CGameCamera.hpp +++ b/Runtime/Camera/CGameCamera.hpp @@ -15,14 +15,14 @@ class CGameCamera : public CActor { protected: TUniqueId xe8_watchedObject; - zeus::CMatrix4f xec_perspectiveMatrix; + mutable zeus::CMatrix4f xec_perspectiveMatrix; zeus::CTransform x12c_origXf; float x15c_currentFov; float x160_znear; float x164_zfar; float x168_aspect; u32 x16c_controllerIdx; - bool x170_24_perspDirty : 1 = true; + mutable bool x170_24_perspDirty : 1 = true; bool x170_25_disablesInput : 1; float x174_delayTime = 0.f; float x178_perspInterpRemTime = 0.f; diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index c6705dfd4..860d5b137 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -202,8 +202,7 @@ constexpr zeus::CMatrix4f PlusOneZ(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, constexpr zeus::CMatrix4f VulkanCorrect(1.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, 0.5f, 0.5f + FLT_EPSILON, 0.f, 0.f, 0.f, 1.f); -zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar, - bool forRenderer) { +zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar) { CProjectionState st; float tfov = std::tan(zeus::degToRad(fovy * 0.5f)); st.x14_near = znear; @@ -219,34 +218,17 @@ zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float tpb = st.xc_top + st.x10_bottom; float fpn = st.x18_far + st.x14_near; float fmn = st.x18_far - st.x14_near; - - if (!forRenderer) { - return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, - 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); - } - - // switch (g_BooPlatform) { - // case boo::IGraphicsDataFactory::Platform::OpenGL: - // default: { - // return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, - // 0.f, - // 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); - // } - // case boo::IGraphicsDataFactory::Platform::D3D11: - // case boo::IGraphicsDataFactory::Platform::Metal: { - zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, 0.f, - 0.f, st.x18_far / fmn, st.x14_near * st.x18_far / fmn, 0.f, 0.f, -1.f, 0.f); - return PlusOneZ * mat2; - // } - // case boo::IGraphicsDataFactory::Platform::Vulkan: { - // zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, - // 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); - // return VulkanCorrect * mat2; - // } - // } + // clang-format off + return { + 2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, + 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, + 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, + 0.f, 0.f, -1.f, 0.f, + }; + // clang-format on } -zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { +zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix() { if (g_Proj.x0_persp) { float rml = g_Proj.x8_right - g_Proj.x4_left; float rpl = g_Proj.x8_right + g_Proj.x4_left; @@ -254,34 +236,14 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { float tpb = g_Proj.xc_top + g_Proj.x10_bottom; float fpn = g_Proj.x18_far + g_Proj.x14_near; float fmn = g_Proj.x18_far - g_Proj.x14_near; - - if (!forRenderer) { - return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, - tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, - 0.f, -1.f, 0.f); - } - - // switch (g_BooPlatform) { - // case boo::IGraphicsDataFactory::Platform::OpenGL: - // default: { - // return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, - // tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, - // 0.f, 0.f, -1.f, 0.f); - // } - // case boo::IGraphicsDataFactory::Platform::D3D11: - // case boo::IGraphicsDataFactory::Platform::Metal: { - zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, tpb / tmb, - 0.f, 0.f, 0.f, g_Proj.x18_far / fmn, g_Proj.x14_near * g_Proj.x18_far / fmn, 0.f, 0.f, -1.f, - 0.f); - return PlusOneZ * mat2; - // } - // case boo::IGraphicsDataFactory::Platform::Vulkan: { - // zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, - // tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, - // 0.f, 0.f, -1.f, 0.f); - // return VulkanCorrect * mat2; - // } - // } + // clang-format off + return { + 2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, + 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f, + 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, + 0.f, 0.f, -1.f, 0.f, + }; + // clang-format on } else { float rml = g_Proj.x8_right - g_Proj.x4_left; float rpl = g_Proj.x8_right + g_Proj.x4_left; @@ -289,31 +251,14 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { float tpb = g_Proj.xc_top + g_Proj.x10_bottom; float fpn = g_Proj.x18_far + g_Proj.x14_near; float fmn = g_Proj.x18_far - g_Proj.x14_near; - - if (!forRenderer) { - return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, - -fpn / fmn, 0.f, 0.f, 0.f, 1.f); - } - - // switch (g_BooPlatform) { - // case boo::IGraphicsDataFactory::Platform::OpenGL: - // default: { - // return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / - // fmn, - // -fpn / fmn, 0.f, 0.f, 0.f, 1.f); - // } - // case boo::IGraphicsDataFactory::Platform::D3D11: - // case boo::IGraphicsDataFactory::Platform::Metal: { - zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, 1.f / fmn, - g_Proj.x14_near / fmn, 0.f, 0.f, 0.f, 1.f); - return PlusOneZ * mat2; - // } - // case boo::IGraphicsDataFactory::Platform::Vulkan: { - // zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, - // -fpn / fmn, 0.f, 0.f, 0.f, 1.f); - // return VulkanCorrect * mat2; - // } - // } + // clang-format off + return { + 2.f / rml, 0.f, 0.f, -rpl / rml, + 0.f, 2.f / tmb, 0.f, -tpb / tmb, + 0.f, 0.f, -2.f / fmn, -fpn / fmn, + 0.f, 0.f, 0.f, 1.f + }; + // clang-format on } } @@ -357,11 +302,11 @@ void CGraphics::FlushProjection() { } else { // Convert and load ortho } - aurora::gfx::update_projection(GetPerspectiveProjectionMatrix(true)); + aurora::gfx::update_projection(GetPerspectiveProjectionMatrix()); } zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point) { - zeus::CVector3f projPt = GetPerspectiveProjectionMatrix(false).multiplyOneOverW(point); + zeus::CVector3f projPt = GetPerspectiveProjectionMatrix().multiplyOneOverW(point); return {int(projPt.x() * g_Viewport.x10_halfWidth) + int(g_Viewport.x10_halfWidth), int(g_Viewport.xc_height) - (int(projPt.y() * g_Viewport.x14_halfHeight) + int(g_Viewport.x14_halfHeight))}; } @@ -426,16 +371,6 @@ SClipScreenRect CGraphics::ClipScreenRectFromVS(const zeus::CVector3f& p1, const 1.f - minY2 / float(g_Viewport.xc_height)}; } -zeus::CVector3f CGraphics::ProjectModelPointToViewportSpace(const zeus::CVector3f& point) { - zeus::CVector3f pt = g_GXModelView * point; - return GetPerspectiveProjectionMatrix(true).multiplyOneOverW(pt); -} - -zeus::CVector3f CGraphics::ProjectModelPointToViewportSpace(const zeus::CVector3f& point, float& wOut) { - zeus::CVector3f pt = g_GXModelView * point; - return GetPerspectiveProjectionMatrix(true).multiplyOneOverW(pt, wOut); -} - void CGraphics::SetViewportResolution(const zeus::CVector2i& res) { g_Viewport.x8_width = res.x; g_Viewport.xc_height = res.y; diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index be7b5712a..bb37c355c 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -164,9 +164,8 @@ public: static void SetViewPointMatrix(const zeus::CTransform& xf); static void SetViewMatrix(); static void SetModelMatrix(const zeus::CTransform& xf); - static zeus::CMatrix4f CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar, - bool forRenderer); - static zeus::CMatrix4f GetPerspectiveProjectionMatrix(bool forRenderer); + static zeus::CMatrix4f CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar); + static zeus::CMatrix4f GetPerspectiveProjectionMatrix(); static const CProjectionState& GetProjectionState(); static void SetProjectionState(const CProjectionState&); static void SetPerspective(float fovy, float aspect, float znear, float zfar); @@ -175,8 +174,6 @@ public: static zeus::CVector2i ProjectPoint(const zeus::CVector3f& point); static SClipScreenRect ClipScreenRectFromMS(const zeus::CVector3f& p1, const zeus::CVector3f& p2); static SClipScreenRect ClipScreenRectFromVS(const zeus::CVector3f& p1, const zeus::CVector3f& p2); - static zeus::CVector3f ProjectModelPointToViewportSpace(const zeus::CVector3f& point); - static zeus::CVector3f ProjectModelPointToViewportSpace(const zeus::CVector3f& point, float& wOut); static void SetViewportResolution(const zeus::CVector2i& res); static void SetViewport(int leftOff, int bottomOff, int width, int height); diff --git a/Runtime/Graphics/CLineRenderer.cpp b/Runtime/Graphics/CLineRenderer.cpp index 42bb70301..9fd344bfd 100644 --- a/Runtime/Graphics/CLineRenderer.cpp +++ b/Runtime/Graphics/CLineRenderer.cpp @@ -86,8 +86,8 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo return; float adjWidth = width / 480.f; - float w; - zeus::CVector3f projPt = CGraphics::ProjectModelPointToViewportSpace(position, w); + float w = 0.f; + zeus::CVector3f projPt = {}; // CGraphics::ProjectModelPointToViewportSpace(position, w); if (m_mode == EPrimitiveMode::LineLoop) { if (m_nextVert == 0) { diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index c5720df1a..749280c93 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -68,7 +68,7 @@ void CAABoxShader::setAABB(const zeus::CAABox& aabb) { void CAABoxShader::draw(const zeus::CColor& color) { SCOPED_GRAPHICS_DEBUG_GROUP("CAABoxShader::draw", zeus::skMagenta); - m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = color; // m_uniBuf->load(&m_uniform, sizeof(Uniform)); // diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp index e512770c6..71dc722b8 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.cpp @@ -73,7 +73,7 @@ void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const // m_vbo->load(verts, sizeof(Vert) * numVerts); - m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = color; // m_uniBuf->load(&m_uniform, sizeof(m_uniform)); // diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp index 835740f94..c17ed0202 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp @@ -20,7 +20,7 @@ void CEnergyBarShader::Shutdown() { } void CEnergyBarShader::updateModelMatrix() { - m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); } void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector& verts0, const zeus::CColor& color1, diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp index dabe4c05a..63dde5d69 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp @@ -35,7 +35,7 @@ namespace metaforce { //} void CFogVolumePlaneShader::addFan(const zeus::CVector3f* verts, int numVerts) { - zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true); + zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(/*true*/); zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]); if (!m_verts.empty()) { m_verts.push_back(m_verts.back()); diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp index af2c337b8..175fd0d19 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp @@ -31,7 +31,7 @@ CMapSurfaceShader::CMapSurfaceShader(aurora::ArrayRef vbo, void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) { SCOPED_GRAPHICS_DEBUG_GROUP("CMapSurfaceShader::draw", zeus::skMagenta); - Uniform uniform = {CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), color}; + Uniform uniform = {CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(), color}; // m_uniBuf->load(&uniform, sizeof(Uniform)); // CGraphics::SetShaderDataBinding(m_dataBind); // CGraphics::DrawArrayIndexed(start, count); diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp index eaf1b444a..26dc50508 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp @@ -42,7 +42,7 @@ void CRadarPaintShader::draw(const std::vector& instances, const CText // } BooTrace); } - zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); // m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f)); size_t mapSz = sizeof(Instance) * instances.size(); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index f32682ffb..f8c26e728 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -263,7 +263,7 @@ void CTexturedQuadFilter::drawVerts(const zeus::CColor& color, std::arrayload(verts.data(), sizeof(Vert) * verts.size()); - m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = color; m_uniform.m_lod = lod; // m_uniBuf->load(&m_uniform, sizeof(m_uniform)); diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp index 83e5f5814..1b6a282ee 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp @@ -55,7 +55,7 @@ void CWorldShadowShader::drawBase(float extent) { }}; // m_vbo->load(verts.data(), sizeof(verts)); - m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = zeus::skWhite; // m_uniBuf->load(&m_uniform, sizeof(m_uniform)); // diff --git a/Runtime/GuiSys/CGuiCamera.cpp b/Runtime/GuiSys/CGuiCamera.cpp index b173456df..5bc971cec 100644 --- a/Runtime/GuiSys/CGuiCamera.cpp +++ b/Runtime/GuiSys/CGuiCamera.cpp @@ -18,8 +18,8 @@ zeus::CVector3f CGuiCamera::ConvertToScreenSpace(const zeus::CVector3f& vec) con if (local.isZero()) return {-1.f, -1.f, 1.f}; - zeus::CMatrix4f mat = CGraphics::CalculatePerspectiveMatrix(m_proj.xbc_fov, m_proj.xc0_aspect, m_proj.xc4_znear, - m_proj.xc8_zfar, false); + zeus::CMatrix4f mat = + CGraphics::CalculatePerspectiveMatrix(m_proj.xbc_fov, m_proj.xc0_aspect, m_proj.xc4_znear, m_proj.xc8_zfar); local = zeus::CVector3f(local.x(), local.z(), -local.y()); return mat.multiplyOneOverW(local); } diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index 5cc723c6a..428bd7d83 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -149,7 +149,7 @@ void CGuiFrame::Draw(const CGuiWidgetDrawParms& parms) const { CGuiWidget* CGuiFrame::BestCursorHit(const zeus::CVector2f& point, const CGuiWidgetDrawParms& parms) const { x14_camera->Draw(parms); - zeus::CMatrix4f vp = CGraphics::GetPerspectiveProjectionMatrix(false) * CGraphics::g_CameraMatrix.toMatrix4f(); + zeus::CMatrix4f vp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_CameraMatrix.toMatrix4f(); CGuiWidget* ret = nullptr; for (const auto& widget : x2c_widgets) if (widget->GetMouseActive() && widget->TestCursorHit(vp, point)) diff --git a/Runtime/Particle/CDecal.cpp b/Runtime/Particle/CDecal.cpp index faa208a8a..dccf8c7ab 100644 --- a/Runtime/Particle/CDecal.cpp +++ b/Runtime/Particle/CDecal.cpp @@ -88,7 +88,7 @@ void CDecal::RenderQuad(CQuadDecal& decal, const SQuadDescr& desc) const { CGraphics::SetModelMatrix(modXf); SParticleUniforms uniformData = { - CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; + CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; // decal.m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); bool redToAlpha = sMoveRedToAlphaBuffer && desc.x18_ADD && desc.x14_TEX; diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index 84464c31e..9d54b55c4 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -943,7 +943,7 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { break; } - SParticleUniforms uniformData = {CGraphics::GetPerspectiveProjectionMatrix(true), {1.f, 1.f, 1.f, 1.f}}; + SParticleUniforms uniformData = {CGraphics::GetPerspectiveProjectionMatrix(/*true*/), {1.f, 1.f, 1.f, 1.f}}; // m_uniformBufPmus->load(&uniformData, sizeof(SParticleUniforms)); // @@ -1259,7 +1259,7 @@ void CElementGen::RenderParticles() { CTexture* cachedTex = nullptr; SParticleUniforms uniformData = { - CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; + CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; if (texr) { CParticle& target = x30_particles[0]; @@ -1661,7 +1661,7 @@ void CElementGen::RenderParticlesIndirectTexture() { CGraphics::SetModelMatrix(systemViewPointMatrix); SParticleUniforms uniformData = { - CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; + CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(), {1.f, 1.f, 1.f, 1.f}}; // m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms)); CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0); diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index b97c8528f..df4bb0dfb 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -1006,7 +1006,7 @@ void CParticleSwoosh::Render(const CActorLights*) { } } - zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); + zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); // m_uniformBuf->load(&mvp, sizeof(zeus::CMatrix4f)); // if (m_cachedVerts.size()) { // m_vertBuf->load(m_cachedVerts.data(), m_cachedVerts.size() * sizeof(CParticleSwooshShaders::Vert)); diff --git a/Runtime/World/CEnvFxManager.cpp b/Runtime/World/CEnvFxManager.cpp index c41cc7468..bb4e7b21b 100644 --- a/Runtime/World/CEnvFxManager.cpp +++ b/Runtime/World/CEnvFxManager.cpp @@ -376,7 +376,7 @@ static zeus::CColor GetFlakeColor(const zeus::CMatrix4f& mvp, const CEnvFxShader void CEnvFxManagerGrid::RenderSnowParticles(const zeus::CTransform& camXf) { const zeus::CVector3f xVec = 0.2f * camXf.basis[0]; const zeus::CVector3f zVec = 0.2f * camXf.basis[2]; - const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(false) * CGraphics::g_GXModelView.toMatrix4f(); + const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(); // auto* bufOut = m_instBuf.access(); // for (const auto& particle : x1c_particles) { // bufOut->positions[0] = particle.toVec3f(); @@ -413,7 +413,7 @@ void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) { void CEnvFxManagerGrid::RenderUnderwaterParticles(const zeus::CTransform& camXf) { const zeus::CVector3f xVec = 0.5f * camXf.basis[0]; const zeus::CVector3f zVec = 0.5f * camXf.basis[2]; - const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(false) * CGraphics::g_GXModelView.toMatrix4f(); + const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(); // auto* bufOut = m_instBuf.access(); // for (const auto& particle : x1c_particles) { // bufOut->positions[0] = particle.toVec3f(); @@ -436,7 +436,7 @@ void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransfor if (!x1c_particles.empty() && x14_block.first) { CGraphics::SetModelMatrix(xf * zeus::CTransform::Translate(x4_position.toVec2f() / 256.f)); parent.m_uniformData.mv = CGraphics::g_GXModelView.toMatrix4f(); - parent.m_uniformData.proj = CGraphics::GetPerspectiveProjectionMatrix(true); + parent.m_uniformData.proj = CGraphics::GetPerspectiveProjectionMatrix(/*true*/); switch (fxType) { case EEnvFxType::Snow: case EEnvFxType::Rain: { diff --git a/aurora/lib/gfx/common.cpp b/aurora/lib/gfx/common.cpp index 6538cbda4..0b5fe5a3d 100644 --- a/aurora/lib/gfx/common.cpp +++ b/aurora/lib/gfx/common.cpp @@ -167,7 +167,12 @@ void update_model_view(const zeus::CMatrix4f& mv, const zeus::CMatrix4f& mv_inv) g_mv = mv; g_mvInv = mv_inv; } -void update_projection(const zeus::CMatrix4f& proj) noexcept { g_proj = proj; } +constexpr zeus::CMatrix4f DepthCorrect( + 1.f, 0.f, 0.f, 0.f, + 0.f, 1.f, 0.f, 0.f, + 0.f, 0.f, 0.5f, 0.5f, + 0.f, 0.f, 0.f, 1.f); +void update_projection(const zeus::CMatrix4f& proj) noexcept { g_proj = DepthCorrect * proj; } void update_fog_state(const metaforce::CFogState& state) noexcept { g_fogState = state; } void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept { g_commands.push_back({CommandType::SetViewport, {.setViewport = {rect, znear, zfar}}});