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

@ -154,6 +154,7 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
{
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
m_tagToPath.reserve(cacheReader.getRootNode()->m_mapChildren.size());
size_t loadIdx = 0;
for (const auto& child : cacheReader.getRootNode()->m_mapChildren)
{
unsigned long id = strtoul(child.first.c_str(), nullptr, 16);
@ -161,7 +162,10 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
hecl::ProjectPath path(m_proj->getProjectWorkingPath(),
child.second->m_seqChildren.at(1)->m_scalarString);
m_tagToPath[SObjectTag(type, id)] = path;
fprintf(stderr, "\r %" PRISize " / %" PRISize, loadIdx++,
cacheReader.getRootNode()->m_mapChildren.size());
}
fprintf(stderr, "\n");
}
fclose(cacheFile);
Log.report(logvisor::Info, _S("Cache index of '%s' loaded; %d tags"),

View File

@ -10,6 +10,7 @@
#include "Runtime/Graphics/CLineRenderer.hpp"
#include "Runtime/Graphics/CMoviePlayer.hpp"
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Particle/CGenDescription.hpp"
namespace urde
{

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,28 +148,88 @@ 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;
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 / nmf, 2.f * st.x18_far * st.x14_near / nmf,
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn,
0.f, 0.f, -1.f, 0.f);
}
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix()
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(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;
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 / nmf, 2.f * g_Proj.x18_far * g_Proj.x14_near / nmf,
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()
{
return g_Proj;
@ -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,7 +44,7 @@ void CBooModel::BuildGfxToken()
m_gfxToken = CGraphics::CommitResources(
[&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{
m_unskinnedXfBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex,
m_unskinnedXfBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform,
sizeof(SUnskinnedXf), 1);
boo::IGraphicsBuffer* bufs[] = {m_unskinnedXfBuffer};
m_shaderDataBindings.clear();
@ -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));
}
}

View File

@ -31,7 +31,8 @@ zeus::CVector3f CGuiCamera::ConvertToScreenSpace(const zeus::CVector3f& vec) con
return {-1.f, -1.f, 1.f};
zeus::CMatrix4f mat = CGraphics::CalculatePerspectiveMatrix(xfc_fov, x100_aspect,
x104_znear, x108_zfar);
x104_znear, x108_zfar,
false);
return mat.multiplyOneOverW(local);
}

View File

@ -65,51 +65,31 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
{
case EGuiModelDrawFlags::Shadeless:
{
CModelFlags flags;
flags.m_blendMode = 0;
flags.m_matSetIdx = 0;
flags.m_flags = 3;
flags.color = zeus::CColor::skWhite;
CModelFlags flags(0, 0, 3, zeus::CColor::skWhite);
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::Opaque:
{
CModelFlags flags;
flags.m_blendMode = 1;
flags.m_matSetIdx = 0;
flags.m_flags = 3;
flags.color = moduCol;
CModelFlags flags(1, 0, 3, moduCol);
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::Alpha:
{
CModelFlags flags;
flags.m_blendMode = 4;
flags.m_matSetIdx = 0;
flags.m_flags = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
flags.color = moduCol;
CModelFlags flags(4, 0, (xf7_24_depthWrite << 1) | xf6_31_depthTest, moduCol);
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::Additive:
{
CModelFlags flags;
flags.m_blendMode = 3;
flags.m_matSetIdx = 0;
flags.m_flags = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
flags.color = moduCol;
CModelFlags flags(3, 0, (xf7_24_depthWrite << 1) | xf6_31_depthTest, moduCol);
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::AlphaAdditiveOverdraw:
{
CModelFlags flags;
flags.m_blendMode = 4;
flags.m_matSetIdx = 0;
flags.m_flags = xf6_31_depthTest;
flags.color = moduCol;
CModelFlags flags(4, 0, xf6_31_depthTest, moduCol);
model->Draw(flags);
flags.m_blendMode = 5;

View File

@ -14,7 +14,7 @@ namespace urde
{
class CGuiObject;
class CVParamTransfer;
class SObjectTag;
struct SObjectTag;
class IFactory;
class CSimplePool;
class CGuiWidget;

View File

@ -153,7 +153,7 @@ void CTextRenderBuffer::Render(const zeus::CColor& col, float time) const
{
((CTextRenderBuffer*)this)->CommitResources();
BooUniform uniforms = {CGraphics::GetPerspectiveProjectionMatrix() *
BooUniform uniforms = {CGraphics::GetPerspectiveProjectionMatrix(true) *
CGraphics::g_GXModelView.toMatrix4f(), col};
m_uniBuf->load(&uniforms, sizeof(uniforms));

View File

@ -20,6 +20,7 @@
#include "Particle/CElementGen.hpp"
#include "Character/CAnimData.hpp"
#include "Particle/CDecalManager.hpp"
#include "Particle/CGenDescription.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "Audio/CAudioSys.hpp"
#include "Input/CInputGenerator.hpp"

View File

@ -3,6 +3,7 @@
#include "CParticleGlobals.hpp"
#include "CRandom16.hpp"
#include "zeus/Math.hpp"
#include "CGenDescription.hpp"
/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Color_Elements */

View File

@ -1598,7 +1598,7 @@ void CElementGen::RenderParticles()
SParticleUniforms uniformData =
{
CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(),
CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(),
{1.f, 1.f, 1.f, 1.f}
};
@ -1933,7 +1933,7 @@ void CElementGen::RenderParticlesIndirectTexture()
SParticleUniforms uniformData =
{
CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(),
CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(),
{1.f, 1.f, 1.f, 1.f}
};
m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms));

View File

@ -2,6 +2,8 @@
#include "CParticleGlobals.hpp"
#include "CRandom16.hpp"
#include "CElementGen.hpp"
#include "CGenDescription.hpp"
/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Int_Elements */
namespace urde

View File

@ -4,6 +4,7 @@
#include "CElementGen.hpp"
#include "Graphics/CTexture.hpp"
#include "zeus/Math.hpp"
#include "CGenDescription.hpp"
/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Real_Elements */

View File

@ -3,6 +3,7 @@
#include "CRandom16.hpp"
#include "CElementGen.hpp"
#include "zeus/Math.hpp"
#include "CGenDescription.hpp"
/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Vector_Elements */

2
hecl

@ -1 +1 @@
Subproject commit fd9dd2662baa04ae31b8caa525327abe5087ebae
Subproject commit 15a3b271e8c642f6983d897c397ea31e689d9071