Switched to 8-bit bone indices, removed material skinning flag
This commit is contained in:
parent
0bd9506a93
commit
5b63556527
|
@ -169,7 +169,7 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
|
||||||
if (VtxDesc & eTex5) ShaderCode << "layout(location = 9) in vec2 RawTex5;\n";
|
if (VtxDesc & eTex5) ShaderCode << "layout(location = 9) in vec2 RawTex5;\n";
|
||||||
if (VtxDesc & eTex6) ShaderCode << "layout(location = 10) in vec2 RawTex6;\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 & 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";
|
if (VtxDesc & eBoneWeights) ShaderCode << "layout(location = 13) in vec4 BoneWeights;\n";
|
||||||
ShaderCode << "\n";
|
ShaderCode << "\n";
|
||||||
|
|
||||||
|
@ -222,7 +222,9 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
|
||||||
<< "uniform int NumLights;\n"
|
<< "uniform int NumLights;\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
if (rkMat.Options() & CMaterial::eSkinningEnabled)
|
bool HasSkinning = (rkMat.VtxDesc().HasAnyFlags(eBoneIndices | eBoneWeights));
|
||||||
|
|
||||||
|
if (HasSkinning)
|
||||||
{
|
{
|
||||||
ShaderCode << "layout(std140) uniform BoneTransformBlock\n"
|
ShaderCode << "layout(std140) uniform BoneTransformBlock\n"
|
||||||
<< "{\n"
|
<< "{\n"
|
||||||
|
@ -243,7 +245,7 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
|
||||||
ShaderCode << "\n";
|
ShaderCode << "\n";
|
||||||
|
|
||||||
// Skinning
|
// Skinning
|
||||||
if (rkMat.Options() & CMaterial::eSkinningEnabled)
|
if (HasSkinning)
|
||||||
{
|
{
|
||||||
ShaderCode << " // Skinning\n"
|
ShaderCode << " // Skinning\n"
|
||||||
<< " vec3 ModelSpacePos = vec3(0,0,0);\n";
|
<< " vec3 ModelSpacePos = vec3(0,0,0);\n";
|
||||||
|
@ -254,7 +256,8 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& rkMat)
|
||||||
ShaderCode << " \n"
|
ShaderCode << " \n"
|
||||||
<< " for (int iBone = 0; iBone < 4; iBone++)\n"
|
<< " for (int iBone = 0; iBone < 4; iBone++)\n"
|
||||||
<< " {\n"
|
<< " {\n"
|
||||||
<< " int BoneIdx = BoneIndices[iBone];\n"
|
<< " int Shift = (8 * iBone);\n"
|
||||||
|
<< " int BoneIdx = (BoneIndices >> Shift) & 0xFF;\n"
|
||||||
<< " float Weight = BoneWeights[iBone];\n"
|
<< " float Weight = BoneWeights[iBone];\n"
|
||||||
<< " \n"
|
<< " \n"
|
||||||
<< " if (BoneIdx > 0)\n"
|
<< " if (BoneIdx > 0)\n"
|
||||||
|
|
|
@ -275,7 +275,7 @@ GLuint CVertexBuffer::CreateVAO()
|
||||||
else if (iAttrib == 12)
|
else if (iAttrib == 12)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mAttribBuffers[iAttrib]);
|
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);
|
glEnableVertexAttribArray(iAttrib);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,7 @@ public:
|
||||||
eLightmap = 0x800,
|
eLightmap = 0x800,
|
||||||
eShortTexCoord = 0x2000,
|
eShortTexCoord = 0x2000,
|
||||||
eAllMP1Settings = 0x2FF8,
|
eAllMP1Settings = 0x2FF8,
|
||||||
eDrawWhiteAmbientDKCR = 0x80000,
|
eDrawWhiteAmbientDKCR = 0x80000
|
||||||
eSkinningEnabled = 0x80000000
|
|
||||||
};
|
};
|
||||||
DECLARE_FLAGS(EMaterialOption, FMaterialOptions)
|
DECLARE_FLAGS(EMaterialOption, FMaterialOptions)
|
||||||
|
|
||||||
|
|
|
@ -470,8 +470,6 @@ CModel* CModelLoader::LoadCMDL(IInputStream& rCMDL)
|
||||||
for (u32 iMat = 0; iMat < Loader.mMaterials[iSet]->NumMaterials(); iMat++)
|
for (u32 iMat = 0; iMat < Loader.mMaterials[iSet]->NumMaterials(); iMat++)
|
||||||
{
|
{
|
||||||
CMaterial *pMat = Loader.mMaterials[iSet]->MaterialByIndex(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));
|
pMat->SetVertexDescription(pMat->VtxDesc() | FVertexDescription(eBoneIndices | eBoneWeights));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <Math/CVector3f.h>
|
#include <Math/CVector3f.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
typedef std::array<u32, 4> TBoneIndices;
|
typedef std::array<u8, 4> TBoneIndices;
|
||||||
typedef std::array<float, 4> TBoneWeights;
|
typedef std::array<float, 4> TBoneWeights;
|
||||||
|
|
||||||
class CVertex
|
class CVertex
|
||||||
|
|
Loading…
Reference in New Issue