2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-01 13:33:32 +00:00

Add missing Post Transform matrix to UV Animations

This commit is contained in:
Phillip Stephens 2016-07-07 20:23:58 -07:00
parent 952b96fa79
commit 746e7d9ff3

View File

@ -17,7 +17,7 @@ static rstl::optional_object<CModelShaders> g_ModelShaders;
CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader, CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo, boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
size_t weightVecCount, size_t skinBankCount, const zeus::CAABox& aabb) size_t weightVecCount, size_t skinBankCount, const zeus::CAABox& aabb)
: x0_surfaces(surfaces), x4_matSet(&shader.m_matSet), m_pipelines(&shader.m_shaders), : x0_surfaces(surfaces), x4_matSet(&shader.m_matSet), m_pipelines(&shader.m_shaders),
m_vtxFmt(vtxFmt), x8_vbo(vbo), xc_ibo(ibo), m_weightVecCount(weightVecCount), m_vtxFmt(vtxFmt), x8_vbo(vbo), xc_ibo(ibo), m_weightVecCount(weightVecCount),
m_skinBankCount(skinBankCount), x1c_textures(&shader.x0_textures), x20_aabb(aabb), m_skinBankCount(skinBankCount), x1c_textures(&shader.x0_textures), x20_aabb(aabb),
x40_24_texturesLoaded(false), x40_25_(0) x40_24_texturesLoaded(false), x40_25_(0)
@ -86,7 +86,7 @@ void CBooModel::BuildGfxToken()
/* Animated UV transform matrices */ /* Animated UV transform matrices */
for (const MaterialSet::Material& mat : x4_matSet->materials) for (const MaterialSet::Material& mat : x4_matSet->materials)
{ {
size_t thisSz = ROUND_UP_256(mat.uvAnims.size() * sizeof(zeus::CMatrix4f)); size_t thisSz = ROUND_UP_256(mat.uvAnims.size() * (sizeof(zeus::CMatrix4f) * 2));
uvOffs.push_back(uniBufSize); uvOffs.push_back(uniBufSize);
uvSizes.push_back(thisSz); uvSizes.push_back(thisSz);
uniBufSize += thisSz; uniBufSize += thisSz;
@ -322,6 +322,7 @@ void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) c
void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimation& anim) void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimation& anim)
{ {
zeus::CMatrix4f& matrixOut = reinterpret_cast<zeus::CMatrix4f&>(*bufOut); zeus::CMatrix4f& matrixOut = reinterpret_cast<zeus::CMatrix4f&>(*bufOut);
zeus::CMatrix4f& postMtxOut = reinterpret_cast<zeus::CMatrix4f&>(*(bufOut + sizeof(zeus::CMatrix4f)));
switch (anim.mode) switch (anim.mode)
{ {
case UVAnimation::Mode::MvInvNoTranslation: case UVAnimation::Mode::MvInvNoTranslation:
@ -329,11 +330,19 @@ void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimati
matrixOut = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation( matrixOut = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(
CGraphics::g_GXModelMatrix).toMatrix4f(); CGraphics::g_GXModelMatrix).toMatrix4f();
matrixOut.vec[3].zeroOut(); matrixOut.vec[3].zeroOut();
postMtxOut = zeus::CTransform(zeus::CMatrix3f(0.5, 0.0, 0.0,
0.0, 0.5, 0.0,
0.0, 0.0, 0.0),
zeus::CVector3f(0.5, 0.5, 1.0)).toMatrix4f();
break; break;
} }
case UVAnimation::Mode::MvInv: case UVAnimation::Mode::MvInv:
{ {
matrixOut = (CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix).toMatrix4f(); matrixOut = (CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix).toMatrix4f();
postMtxOut = zeus::CTransform(zeus::CMatrix3f(0.5, 0.0, 0.0,
0.0, 0.5, 0.0,
0.0, 0.0, 0.0),
zeus::CVector3f(0.5, 0.5, 1.0)).toMatrix4f();
break; break;
} }
case UVAnimation::Mode::Scroll: case UVAnimation::Mode::Scroll:
@ -374,14 +383,33 @@ void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimati
matrixOut.vec[2].y = 0.5f; matrixOut.vec[2].y = 0.5f;
matrixOut.vec[3].x = CGraphics::g_GXModelMatrix.origin.x * 0.5f; matrixOut.vec[3].x = CGraphics::g_GXModelMatrix.origin.x * 0.5f;
matrixOut.vec[3].y = CGraphics::g_GXModelMatrix.origin.y * 0.5f; matrixOut.vec[3].y = CGraphics::g_GXModelMatrix.origin.y * 0.5f;
postMtxOut = zeus::CTransform(zeus::CMatrix3f(0.5, 0.0, 0.0,
0.0, 0.0, 0.5,
0.0, 0.0, 0.0),
zeus::CVector3f(CGraphics::g_GXModelMatrix.origin.x * 0.50000001,
CGraphics::g_GXModelMatrix.origin.x * 0.50000001,
1.0)).toMatrix4f();
break; break;
} }
case UVAnimation::Mode::WhoMustNotBeNamed: case UVAnimation::Mode::WhoMustNotBeNamed:
{ {
zeus::CTransform texmtx = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix; zeus::CTransform texmtx = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix;
texmtx.origin.zeroOut(); texmtx.origin.zeroOut();
/* TODO: Finish */
matrixOut = texmtx.toMatrix4f(); matrixOut = texmtx.toMatrix4f();
const zeus::CVector3f& viewOrigin = CGraphics::g_ViewMatrix.origin;
float xy = (viewOrigin.x + viewOrigin.y) * 0.025f * anim.vals[1];
xy = (xy - (int)xy);
float z = (viewOrigin.z) * 0.05f * anim.vals[1];
z = (z - (int)z);
float halfA = anim.vals[0] * 0.5f;
postMtxOut = zeus::CTransform(zeus::CMatrix3f(halfA, 0.0, 0.0,
0.0, 0.0, halfA,
0.0, 0.0, 0.0),
zeus::CVector3f(xy, z, 1.0)).toMatrix4f();
break; break;
} }
default: break; default: break;
@ -562,11 +590,11 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* stor
0, mat.uvAnims.size(), boo::Primitive(hmdlMeta.topology), 0, mat.uvAnims.size(), boo::Primitive(hmdlMeta.topology),
true, true, true); true, true, true);
matSet.m_shaders.push_back(g_ModelShaders->buildExtendedShader(tag, mat.heclIr, "CMDL", ctx)); matSet.m_shaders.push_back(g_ModelShaders->buildExtendedShader(tag, mat.heclIr, "CMDL", ctx));
} }
} }
return true; return true;
}); });
u32 surfCount = hecl::SBig(*reinterpret_cast<const u32*>(surfInfo)); u32 surfCount = hecl::SBig(*reinterpret_cast<const u32*>(surfInfo));
x8_surfaces.reserve(surfCount); x8_surfaces.reserve(surfCount);
@ -665,7 +693,7 @@ CModelShaders::GetShaderExtensions(boo::IGraphicsDataFactory::Platform plat)
CModelShaders::CModelShaders(const hecl::Runtime::FileStoreManager& storeMgr, CModelShaders::CModelShaders(const hecl::Runtime::FileStoreManager& storeMgr,
boo::IGraphicsDataFactory* gfxFactory) boo::IGraphicsDataFactory* gfxFactory)
: m_shaderCache(storeMgr, gfxFactory, GetShaderExtensions(gfxFactory->platform())) {} : m_shaderCache(storeMgr, gfxFactory, GetShaderExtensions(gfxFactory->platform())) {}
void CModelShaders::Initialize(const hecl::Runtime::FileStoreManager& storeMgr, void CModelShaders::Initialize(const hecl::Runtime::FileStoreManager& storeMgr,
boo::IGraphicsDataFactory* gfxFactory) boo::IGraphicsDataFactory* gfxFactory)