Remove forRenderer from CGraphics PerspectiveProjectionMatrix

This commit is contained in:
Luke Street 2022-03-05 18:30:30 -05:00
parent 6b1948176a
commit 84b6fcfb44
20 changed files with 61 additions and 125 deletions

View File

@ -44,9 +44,8 @@ void CGameCamera::SetActive(bool active) {
zeus::CMatrix4f CGameCamera::GetPerspectiveMatrix() const { zeus::CMatrix4f CGameCamera::GetPerspectiveMatrix() const {
if (x170_24_perspDirty) { if (x170_24_perspDirty) {
const_cast<CGameCamera*>(this)->xec_perspectiveMatrix = xec_perspectiveMatrix = CGraphics::CalculatePerspectiveMatrix(x15c_currentFov, x168_aspect, x160_znear, x164_zfar);
CGraphics::CalculatePerspectiveMatrix(x15c_currentFov, x168_aspect, x160_znear, x164_zfar, false); x170_24_perspDirty = false;
const_cast<CGameCamera*>(this)->x170_24_perspDirty = false;
} }
return xec_perspectiveMatrix; return xec_perspectiveMatrix;

View File

@ -15,14 +15,14 @@ class CGameCamera : public CActor {
protected: protected:
TUniqueId xe8_watchedObject; TUniqueId xe8_watchedObject;
zeus::CMatrix4f xec_perspectiveMatrix; mutable zeus::CMatrix4f xec_perspectiveMatrix;
zeus::CTransform x12c_origXf; zeus::CTransform x12c_origXf;
float x15c_currentFov; float x15c_currentFov;
float x160_znear; float x160_znear;
float x164_zfar; float x164_zfar;
float x168_aspect; float x168_aspect;
u32 x16c_controllerIdx; u32 x16c_controllerIdx;
bool x170_24_perspDirty : 1 = true; mutable bool x170_24_perspDirty : 1 = true;
bool x170_25_disablesInput : 1; bool x170_25_disablesInput : 1;
float x174_delayTime = 0.f; float x174_delayTime = 0.f;
float x178_perspInterpRemTime = 0.f; float x178_perspInterpRemTime = 0.f;

View File

@ -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, 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); 0.f, 0.f, 0.f, 1.f);
zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar, zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar) {
bool forRenderer) {
CProjectionState st; CProjectionState st;
float tfov = std::tan(zeus::degToRad(fovy * 0.5f)); float tfov = std::tan(zeus::degToRad(fovy * 0.5f));
st.x14_near = znear; 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 tpb = st.xc_top + st.x10_bottom;
float fpn = st.x18_far + st.x14_near; float fpn = st.x18_far + st.x14_near;
float fmn = st.x18_far - st.x14_near; float fmn = st.x18_far - st.x14_near;
// clang-format off
if (!forRenderer) { return {
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, 2.f * st.x14_near / rml, 0.f, rpl / rml, 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); 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: // clang-format on
// 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;
// }
// }
} }
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix() {
if (g_Proj.x0_persp) { if (g_Proj.x0_persp) {
float rml = g_Proj.x8_right - g_Proj.x4_left; float rml = g_Proj.x8_right - g_Proj.x4_left;
float rpl = 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 tpb = g_Proj.xc_top + g_Proj.x10_bottom;
float fpn = g_Proj.x18_far + g_Proj.x14_near; float fpn = g_Proj.x18_far + g_Proj.x14_near;
float fmn = g_Proj.x18_far - g_Proj.x14_near; float fmn = g_Proj.x18_far - g_Proj.x14_near;
// clang-format off
if (!forRenderer) { return {
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, 2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f,
tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f,
0.f, -1.f, 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) { // clang-format on
// 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;
// }
// }
} else { } else {
float rml = g_Proj.x8_right - g_Proj.x4_left; float rml = g_Proj.x8_right - g_Proj.x4_left;
float rpl = 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 tpb = g_Proj.xc_top + g_Proj.x10_bottom;
float fpn = g_Proj.x18_far + g_Proj.x14_near; float fpn = g_Proj.x18_far + g_Proj.x14_near;
float fmn = g_Proj.x18_far - g_Proj.x14_near; float fmn = g_Proj.x18_far - g_Proj.x14_near;
// clang-format off
if (!forRenderer) { return {
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, 2.f / rml, 0.f, 0.f, -rpl / rml,
-fpn / fmn, 0.f, 0.f, 0.f, 1.f); 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: // clang-format on
// 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;
// }
// }
} }
} }
@ -357,11 +302,11 @@ void CGraphics::FlushProjection() {
} else { } else {
// Convert and load ortho // Convert and load ortho
} }
aurora::gfx::update_projection(GetPerspectiveProjectionMatrix(true)); aurora::gfx::update_projection(GetPerspectiveProjectionMatrix());
} }
zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point) { 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), 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))}; 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)}; 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) { void CGraphics::SetViewportResolution(const zeus::CVector2i& res) {
g_Viewport.x8_width = res.x; g_Viewport.x8_width = res.x;
g_Viewport.xc_height = res.y; g_Viewport.xc_height = res.y;

View File

@ -164,9 +164,8 @@ public:
static void SetViewPointMatrix(const zeus::CTransform& xf); static void SetViewPointMatrix(const zeus::CTransform& xf);
static void SetViewMatrix(); static void SetViewMatrix();
static void SetModelMatrix(const zeus::CTransform& xf); static void SetModelMatrix(const zeus::CTransform& xf);
static zeus::CMatrix4f CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar, static zeus::CMatrix4f CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar);
bool forRenderer); static zeus::CMatrix4f GetPerspectiveProjectionMatrix();
static zeus::CMatrix4f GetPerspectiveProjectionMatrix(bool forRenderer);
static const CProjectionState& GetProjectionState(); static const CProjectionState& GetProjectionState();
static void SetProjectionState(const CProjectionState&); static void SetProjectionState(const CProjectionState&);
static void SetPerspective(float fovy, float aspect, float znear, float zfar); 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 zeus::CVector2i ProjectPoint(const zeus::CVector3f& point);
static SClipScreenRect ClipScreenRectFromMS(const zeus::CVector3f& p1, const zeus::CVector3f& p2); static SClipScreenRect ClipScreenRectFromMS(const zeus::CVector3f& p1, const zeus::CVector3f& p2);
static SClipScreenRect ClipScreenRectFromVS(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 SetViewportResolution(const zeus::CVector2i& res);
static void SetViewport(int leftOff, int bottomOff, int width, int height); static void SetViewport(int leftOff, int bottomOff, int width, int height);

View File

@ -86,8 +86,8 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo
return; return;
float adjWidth = width / 480.f; float adjWidth = width / 480.f;
float w; float w = 0.f;
zeus::CVector3f projPt = CGraphics::ProjectModelPointToViewportSpace(position, w); zeus::CVector3f projPt = {}; // CGraphics::ProjectModelPointToViewportSpace(position, w);
if (m_mode == EPrimitiveMode::LineLoop) { if (m_mode == EPrimitiveMode::LineLoop) {
if (m_nextVert == 0) { if (m_nextVert == 0) {

View File

@ -68,7 +68,7 @@ void CAABoxShader::setAABB(const zeus::CAABox& aabb) {
void CAABoxShader::draw(const zeus::CColor& color) { void CAABoxShader::draw(const zeus::CColor& color) {
SCOPED_GRAPHICS_DEBUG_GROUP("CAABoxShader::draw", zeus::skMagenta); 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_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(Uniform)); // m_uniBuf->load(&m_uniform, sizeof(Uniform));
// //

View File

@ -73,7 +73,7 @@ void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const
// m_vbo->load(verts, sizeof(Vert) * numVerts); // 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_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); // m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// //

View File

@ -20,7 +20,7 @@ void CEnergyBarShader::Shutdown() {
} }
void CEnergyBarShader::updateModelMatrix() { 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<Vertex>& verts0, const zeus::CColor& color1, void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector<Vertex>& verts0, const zeus::CColor& color1,

View File

@ -35,7 +35,7 @@ namespace metaforce {
//} //}
void CFogVolumePlaneShader::addFan(const zeus::CVector3f* verts, int numVerts) { 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]); zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]);
if (!m_verts.empty()) { if (!m_verts.empty()) {
m_verts.push_back(m_verts.back()); m_verts.push_back(m_verts.back());

View File

@ -31,7 +31,7 @@ CMapSurfaceShader::CMapSurfaceShader(aurora::ArrayRef<zeus::CVector3f> vbo,
void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) { void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) {
SCOPED_GRAPHICS_DEBUG_GROUP("CMapSurfaceShader::draw", zeus::skMagenta); 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)); // m_uniBuf->load(&uniform, sizeof(Uniform));
// CGraphics::SetShaderDataBinding(m_dataBind); // CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArrayIndexed(start, count); // CGraphics::DrawArrayIndexed(start, count);

View File

@ -42,7 +42,7 @@ void CRadarPaintShader::draw(const std::vector<Instance>& instances, const CText
// } BooTrace); // } 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)); // m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f));
size_t mapSz = sizeof(Instance) * instances.size(); size_t mapSz = sizeof(Instance) * instances.size();

View File

@ -263,7 +263,7 @@ void CTexturedQuadFilter::drawVerts(const zeus::CColor& color, std::array<Vert,
// m_vbo->load(verts.data(), sizeof(Vert) * verts.size()); // m_vbo->load(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_color = color;
m_uniform.m_lod = lod; m_uniform.m_lod = lod;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); // m_uniBuf->load(&m_uniform, sizeof(m_uniform));

View File

@ -55,7 +55,7 @@ void CWorldShadowShader::drawBase(float extent) {
}}; }};
// m_vbo->load(verts.data(), sizeof(verts)); // 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_uniform.m_color = zeus::skWhite;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); // m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// //

View File

@ -18,8 +18,8 @@ zeus::CVector3f CGuiCamera::ConvertToScreenSpace(const zeus::CVector3f& vec) con
if (local.isZero()) if (local.isZero())
return {-1.f, -1.f, 1.f}; return {-1.f, -1.f, 1.f};
zeus::CMatrix4f mat = CGraphics::CalculatePerspectiveMatrix(m_proj.xbc_fov, m_proj.xc0_aspect, m_proj.xc4_znear, zeus::CMatrix4f mat =
m_proj.xc8_zfar, false); 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()); local = zeus::CVector3f(local.x(), local.z(), -local.y());
return mat.multiplyOneOverW(local); return mat.multiplyOneOverW(local);
} }

View File

@ -149,7 +149,7 @@ void CGuiFrame::Draw(const CGuiWidgetDrawParms& parms) const {
CGuiWidget* CGuiFrame::BestCursorHit(const zeus::CVector2f& point, const CGuiWidgetDrawParms& parms) const { CGuiWidget* CGuiFrame::BestCursorHit(const zeus::CVector2f& point, const CGuiWidgetDrawParms& parms) const {
x14_camera->Draw(parms); 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; CGuiWidget* ret = nullptr;
for (const auto& widget : x2c_widgets) for (const auto& widget : x2c_widgets)
if (widget->GetMouseActive() && widget->TestCursorHit(vp, point)) if (widget->GetMouseActive() && widget->TestCursorHit(vp, point))

View File

@ -88,7 +88,7 @@ void CDecal::RenderQuad(CQuadDecal& decal, const SQuadDescr& desc) const {
CGraphics::SetModelMatrix(modXf); CGraphics::SetModelMatrix(modXf);
SParticleUniforms uniformData = { 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)); // decal.m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms));
bool redToAlpha = sMoveRedToAlphaBuffer && desc.x18_ADD && desc.x14_TEX; bool redToAlpha = sMoveRedToAlphaBuffer && desc.x18_ADD && desc.x14_TEX;

View File

@ -943,7 +943,7 @@ void CElementGen::RenderModels(const CActorLights* actorLights) {
break; 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)); // m_uniformBufPmus->load(&uniformData, sizeof(SParticleUniforms));
// //
@ -1259,7 +1259,7 @@ void CElementGen::RenderParticles() {
CTexture* cachedTex = nullptr; CTexture* cachedTex = nullptr;
SParticleUniforms uniformData = { 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) { if (texr) {
CParticle& target = x30_particles[0]; CParticle& target = x30_particles[0];
@ -1661,7 +1661,7 @@ void CElementGen::RenderParticlesIndirectTexture() {
CGraphics::SetModelMatrix(systemViewPointMatrix); CGraphics::SetModelMatrix(systemViewPointMatrix);
SParticleUniforms uniformData = { 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)); // m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms));
CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0); CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);

View File

@ -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)); // m_uniformBuf->load(&mvp, sizeof(zeus::CMatrix4f));
// if (m_cachedVerts.size()) { // if (m_cachedVerts.size()) {
// m_vertBuf->load(m_cachedVerts.data(), m_cachedVerts.size() * sizeof(CParticleSwooshShaders::Vert)); // m_vertBuf->load(m_cachedVerts.data(), m_cachedVerts.size() * sizeof(CParticleSwooshShaders::Vert));

View File

@ -376,7 +376,7 @@ static zeus::CColor GetFlakeColor(const zeus::CMatrix4f& mvp, const CEnvFxShader
void CEnvFxManagerGrid::RenderSnowParticles(const zeus::CTransform& camXf) { void CEnvFxManagerGrid::RenderSnowParticles(const zeus::CTransform& camXf) {
const zeus::CVector3f xVec = 0.2f * camXf.basis[0]; const zeus::CVector3f xVec = 0.2f * camXf.basis[0];
const zeus::CVector3f zVec = 0.2f * camXf.basis[2]; 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(); // auto* bufOut = m_instBuf.access();
// for (const auto& particle : x1c_particles) { // for (const auto& particle : x1c_particles) {
// bufOut->positions[0] = particle.toVec3f(); // bufOut->positions[0] = particle.toVec3f();
@ -413,7 +413,7 @@ void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) {
void CEnvFxManagerGrid::RenderUnderwaterParticles(const zeus::CTransform& camXf) { void CEnvFxManagerGrid::RenderUnderwaterParticles(const zeus::CTransform& camXf) {
const zeus::CVector3f xVec = 0.5f * camXf.basis[0]; const zeus::CVector3f xVec = 0.5f * camXf.basis[0];
const zeus::CVector3f zVec = 0.5f * camXf.basis[2]; 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(); // auto* bufOut = m_instBuf.access();
// for (const auto& particle : x1c_particles) { // for (const auto& particle : x1c_particles) {
// bufOut->positions[0] = particle.toVec3f(); // 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) { if (!x1c_particles.empty() && x14_block.first) {
CGraphics::SetModelMatrix(xf * zeus::CTransform::Translate(x4_position.toVec2f() / 256.f)); CGraphics::SetModelMatrix(xf * zeus::CTransform::Translate(x4_position.toVec2f() / 256.f));
parent.m_uniformData.mv = CGraphics::g_GXModelView.toMatrix4f(); parent.m_uniformData.mv = CGraphics::g_GXModelView.toMatrix4f();
parent.m_uniformData.proj = CGraphics::GetPerspectiveProjectionMatrix(true); parent.m_uniformData.proj = CGraphics::GetPerspectiveProjectionMatrix(/*true*/);
switch (fxType) { switch (fxType) {
case EEnvFxType::Snow: case EEnvFxType::Snow:
case EEnvFxType::Rain: { case EEnvFxType::Rain: {

View File

@ -167,7 +167,12 @@ void update_model_view(const zeus::CMatrix4f& mv, const zeus::CMatrix4f& mv_inv)
g_mv = mv; g_mv = mv;
g_mvInv = mv_inv; 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 update_fog_state(const metaforce::CFogState& state) noexcept { g_fogState = state; }
void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept { void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept {
g_commands.push_back({CommandType::SetViewport, {.setViewport = {rect, znear, zfar}}}); g_commands.push_back({CommandType::SetViewport, {.setViewport = {rect, znear, zfar}}});