Switched to 8-bit bone indices, removed material skinning flag

This commit is contained in:
parax0 2016-04-27 21:33:45 -06:00
parent 0bd9506a93
commit 5b63556527
5 changed files with 10 additions and 10 deletions

View File

@ -169,7 +169,7 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
if (VtxDesc & eTex5) ShaderCode << "layout(location = 9) in vec2 RawTex5;\n";
if (VtxDesc & eTex6) ShaderCode << "layout(location = 10) in vec2 RawTex6;\n";
if (VtxDesc & eTex7) ShaderCode << "layout(location = 11) in vec2 RawTex7;\n";
if (VtxDesc & eBoneIndices) ShaderCode << "layout(location = 12) in ivec4 BoneIndices;\n";
if (VtxDesc & eBoneIndices) ShaderCode << "layout(location = 12) in int BoneIndices;\n";
if (VtxDesc & eBoneWeights) ShaderCode << "layout(location = 13) in vec4 BoneWeights;\n";
ShaderCode << "\n";
@ -222,7 +222,9 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
<< "uniform int NumLights;\n"
<< "\n";
if (rkMat.Options() & CMaterial::eSkinningEnabled)
bool HasSkinning = (rkMat.VtxDesc().HasAnyFlags(eBoneIndices | eBoneWeights));
if (HasSkinning)
{
ShaderCode << "layout(std140) uniform BoneTransformBlock\n"
<< "{\n"
@ -243,7 +245,7 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
ShaderCode << "\n";
// Skinning
if (rkMat.Options() & CMaterial::eSkinningEnabled)
if (HasSkinning)
{
ShaderCode << " // Skinning\n"
<< " vec3 ModelSpacePos = vec3(0,0,0);\n";
@ -254,7 +256,8 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
ShaderCode << " \n"
<< " for (int iBone = 0; iBone < 4; iBone++)\n"
<< " {\n"
<< " int BoneIdx = BoneIndices[iBone];\n"
<< " int Shift = (8 * iBone);\n"
<< " int BoneIdx = (BoneIndices >> Shift) & 0xFF;\n"
<< " float Weight = BoneWeights[iBone];\n"
<< " \n"
<< " if (BoneIdx > 0)\n"

View File

@ -275,7 +275,7 @@ GLuint CVertexBuffer::CreateVAO()
else if (iAttrib == 12)
{
glBindBuffer(GL_ARRAY_BUFFER, mAttribBuffers[iAttrib]);
glVertexAttribIPointer(iAttrib, 4, GL_UNSIGNED_INT, sizeof(TBoneIndices), (void*) 0);
glVertexAttribIPointer(iAttrib, 1, GL_UNSIGNED_INT, sizeof(TBoneIndices), (void*) 0);
glEnableVertexAttribArray(iAttrib);
}

View File

@ -37,8 +37,7 @@ public:
eLightmap = 0x800,
eShortTexCoord = 0x2000,
eAllMP1Settings = 0x2FF8,
eDrawWhiteAmbientDKCR = 0x80000,
eSkinningEnabled = 0x80000000
eDrawWhiteAmbientDKCR = 0x80000
};
DECLARE_FLAGS(EMaterialOption, FMaterialOptions)

View File

@ -470,8 +470,6 @@ CModel* CModelLoader::LoadCMDL(IInputStream& rCMDL)
for (u32 iMat = 0; iMat < Loader.mMaterials[iSet]->NumMaterials(); iMat++)
{
CMaterial *pMat = Loader.mMaterials[iSet]->MaterialByIndex(iMat);
CMaterial::FMaterialOptions Options = pMat->Options();
pMat->SetOptions(Options | CMaterial::eSkinningEnabled);
pMat->SetVertexDescription(pMat->VtxDesc() | FVertexDescription(eBoneIndices | eBoneWeights));
}
}

View File

@ -6,7 +6,7 @@
#include <Math/CVector3f.h>
#include <array>
typedef std::array<u32, 4> TBoneIndices;
typedef std::array<u8, 4> TBoneIndices;
typedef std::array<float, 4> TBoneWeights;
class CVertex