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
1 changed files with 61 additions and 33 deletions

View File

@ -17,7 +17,7 @@ static rstl::optional_object<CModelShaders> g_ModelShaders;
CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
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_skinBankCount(skinBankCount), x1c_textures(&shader.x0_textures), x20_aabb(aabb),
x40_24_texturesLoaded(false), x40_25_(0)
@ -86,7 +86,7 @@ void CBooModel::BuildGfxToken()
/* Animated UV transform matrices */
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);
uvSizes.push_back(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)
{
zeus::CMatrix4f& matrixOut = reinterpret_cast<zeus::CMatrix4f&>(*bufOut);
zeus::CMatrix4f& postMtxOut = reinterpret_cast<zeus::CMatrix4f&>(*(bufOut + sizeof(zeus::CMatrix4f)));
switch (anim.mode)
{
case UVAnimation::Mode::MvInvNoTranslation:
@ -329,11 +330,19 @@ void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimati
matrixOut = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(
CGraphics::g_GXModelMatrix).toMatrix4f();
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;
}
case UVAnimation::Mode::MvInv:
{
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;
}
case UVAnimation::Mode::Scroll:
@ -374,14 +383,33 @@ void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimati
matrixOut.vec[2].y = 0.5f;
matrixOut.vec[3].x = CGraphics::g_GXModelMatrix.origin.x * 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;
}
case UVAnimation::Mode::WhoMustNotBeNamed:
{
zeus::CTransform texmtx = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix;
texmtx.origin.zeroOut();
/* TODO: Finish */
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;
}
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),
true, true, true);
matSet.m_shaders.push_back(g_ModelShaders->buildExtendedShader(tag, mat.heclIr, "CMDL", ctx));
}
}
}
}
return true;
});
});
u32 surfCount = hecl::SBig(*reinterpret_cast<const u32*>(surfInfo));
x8_surfaces.reserve(surfCount);
@ -665,7 +693,7 @@ CModelShaders::GetShaderExtensions(boo::IGraphicsDataFactory::Platform plat)
CModelShaders::CModelShaders(const hecl::Runtime::FileStoreManager& storeMgr,
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,
boo::IGraphicsDataFactory* gfxFactory)