2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-16 03:37:01 +00:00

Windows Fixes; D3D depth support

This commit is contained in:
Jack Andersen
2016-04-02 19:25:34 -10:00
parent dc978a4c79
commit 929f8263fc
17 changed files with 114 additions and 52 deletions

View File

@@ -132,7 +132,8 @@ void CGraphics::SetModelMatrix(const zeus::CTransform& xf)
}
zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect,
float near, float far)
float near, float far,
bool forRenderer)
{
CProjectionState st;
float tfov = std::tan(zeus::degToRad(fovy * 0.5f));
@@ -147,26 +148,86 @@ zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect,
float rpl = st.x8_right + st.x4_left;
float tmb = st.xc_top - st.x10_bottom;
float tpb = st.xc_top + st.x10_bottom;
float nmf = g_Proj.x14_near - g_Proj.x18_far;
float fpn = st.x18_far + st.x14_near;
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 / nmf, 2.f * st.x18_far * st.x14_near / nmf,
0.f, 0.f, -1.f, 0.f);
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::OGL:
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::D3D12:
{
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);
static const zeus::CMatrix4f PlusOneZ(1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 1.f,
0.f, 0.f, 0.f, 1.f);
return PlusOneZ * mat2;
}
}
}
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix()
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer)
{
float rml = g_Proj.x8_right - g_Proj.x4_left;
float rpl = g_Proj.x8_right + g_Proj.x4_left;
float tmb = g_Proj.xc_top - g_Proj.x10_bottom;
float tpb = g_Proj.xc_top + g_Proj.x10_bottom;
float nmf = g_Proj.x14_near - g_Proj.x18_far;
float fpn = g_Proj.x18_far + g_Proj.x14_near;
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 / nmf, 2.f * g_Proj.x18_far * g_Proj.x14_near / nmf,
0.f, 0.f, -1.f, 0.f);
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::OGL:
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::D3D12:
{
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);
static const zeus::CMatrix4f PlusOneZ(1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 1.f,
0.f, 0.f, 0.f, 1.f);
return PlusOneZ * mat2;
}
}
}
const CGraphics::CProjectionState& CGraphics::GetProjectionState()
@@ -225,7 +286,7 @@ void CGraphics::FlushProjection()
zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point)
{
zeus::CVector3f projPt = GetPerspectiveProjectionMatrix().multiplyOneOverW(point);
zeus::CVector3f projPt = GetPerspectiveProjectionMatrix(false).multiplyOneOverW(point);
return {int(projPt.x * g_ViewportResolutionHalf.x) + g_ViewportResolutionHalf.x,
g_ViewportResolution.y - (int(projPt.y * g_ViewportResolutionHalf.y) + g_ViewportResolutionHalf.y)};
}
@@ -293,7 +354,7 @@ SClipScreenRect CGraphics::ClipScreenRectFromVS(const zeus::CVector3f& p1,
zeus::CVector3f CGraphics::ProjectModelPointToViewportSpace(const zeus::CVector3f& point)
{
zeus::CVector3f pt = g_GXModelView * point;
return GetPerspectiveProjectionMatrix().multiplyOneOverW(pt);
return GetPerspectiveProjectionMatrix(false).multiplyOneOverW(pt);
}
void CGraphics::SetViewportResolution(const zeus::CVector2i& res)
@@ -312,6 +373,7 @@ float CGraphics::GetSecondsMod900()
return g_ExternalTimeProvider->x0_currentTime;
}
boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null;
boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr;
boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr;
boo::ITextureR* CGraphics::g_SpareTexture = nullptr;

View File

@@ -199,11 +199,12 @@ public:
static void SetViewMatrix();
static void SetModelMatrix(const zeus::CTransform& xf);
static zeus::CMatrix4f CalculatePerspectiveMatrix(float fovy, float aspect,
float near, float far);
static zeus::CMatrix4f GetPerspectiveProjectionMatrix();
float znear, float zfar,
bool forRenderer);
static zeus::CMatrix4f GetPerspectiveProjectionMatrix(bool forRenderer);
static const CProjectionState& GetProjectionState();
static void SetProjectionState(const CProjectionState&);
static void SetPerspective(float fovy, float aspect, float near, float far);
static void SetPerspective(float fovy, float aspect, float znear, float zfar);
static void SetOrtho(float left, float right,
float top, float bottom,
float znear, float zfar);
@@ -220,6 +221,7 @@ public:
{g_ExternalTimeProvider = provider;}
static float GetSecondsMod900();
static boo::IGraphicsDataFactory::Platform g_BooPlatform;
static boo::IGraphicsDataFactory* g_BooFactory;
static boo::IGraphicsCommandQueue* g_BooMainCommandQueue;
static boo::ITextureR* g_SpareTexture;
@@ -230,6 +232,7 @@ public:
boo::ITextureR* spareTex,
hecl::Runtime::ShaderCacheManager* shadCacheMgr)
{
g_BooPlatform = factory->platform();
g_BooFactory = factory;
g_BooMainCommandQueue = cc;
g_SpareTexture = spareTex;

View File

@@ -23,6 +23,10 @@ struct CModelFlags
u16 m_flags = 0; /* Flags */
zeus::CColor color; /* Set into kcolor slot specified by material */
CModelFlags() = default;
CModelFlags(u8 blendMode, u8 shadIdx, u16 flags, const zeus::CColor& col)
: m_blendMode(blendMode), m_matSetIdx(shadIdx), m_flags(flags), color(col) {}
/* Flags
0x4: render without texture lock
0x8: depth greater

View File

@@ -44,8 +44,8 @@ void CBooModel::BuildGfxToken()
m_gfxToken = CGraphics::CommitResources(
[&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{
m_unskinnedXfBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex,
sizeof(SUnskinnedXf), 1);
m_unskinnedXfBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform,
sizeof(SUnskinnedXf), 1);
boo::IGraphicsBuffer* bufs[] = {m_unskinnedXfBuffer};
m_shaderDataBindings.clear();
m_shaderDataBindings.reserve(x4_matSet->materials.size());
@@ -276,7 +276,7 @@ void CBooModel::UpdateUniformData() const
SUnskinnedXf unskinnedXf;
unskinnedXf.mv = CGraphics::g_GXModelView.toMatrix4f();
unskinnedXf.mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
unskinnedXf.proj = CGraphics::GetPerspectiveProjectionMatrix();
unskinnedXf.proj = CGraphics::GetPerspectiveProjectionMatrix(true);
m_unskinnedXfBuffer->load(&unskinnedXf, sizeof(unskinnedXf));
if (m_uvAnimBuffer)
@@ -376,7 +376,8 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store)
{
hecl::Runtime::ShaderTag tag(mat.heclIr,
hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount,
0, mat.uvAnims.size(), boo::Primitive(hmdlMeta.topology), true, true, true);
0, mat.uvAnims.size(), boo::Primitive(hmdlMeta.topology),
true, true, true);
matSet.m_shaders.push_back(CGraphics::g_ShaderCacheMgr->buildShader(tag, mat.heclIr, "CMDL", ctx));
}
}