diff --git a/src/Core/OpenGL/CShaderGenerator.cpp b/src/Core/OpenGL/CShaderGenerator.cpp index 1de69944..227d37a8 100644 --- a/src/Core/OpenGL/CShaderGenerator.cpp +++ b/src/Core/OpenGL/CShaderGenerator.cpp @@ -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" diff --git a/src/Core/OpenGL/CVertexBuffer.cpp b/src/Core/OpenGL/CVertexBuffer.cpp index 9469b698..7640c1b9 100644 --- a/src/Core/OpenGL/CVertexBuffer.cpp +++ b/src/Core/OpenGL/CVertexBuffer.cpp @@ -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); } diff --git a/src/Core/Resource/CMaterial.h b/src/Core/Resource/CMaterial.h index 627cfbdb..2769bc50 100644 --- a/src/Core/Resource/CMaterial.h +++ b/src/Core/Resource/CMaterial.h @@ -37,8 +37,7 @@ public: eLightmap = 0x800, eShortTexCoord = 0x2000, eAllMP1Settings = 0x2FF8, - eDrawWhiteAmbientDKCR = 0x80000, - eSkinningEnabled = 0x80000000 + eDrawWhiteAmbientDKCR = 0x80000 }; DECLARE_FLAGS(EMaterialOption, FMaterialOptions) diff --git a/src/Core/Resource/Factory/CModelLoader.cpp b/src/Core/Resource/Factory/CModelLoader.cpp index 1e7dfe52..a85e5513 100644 --- a/src/Core/Resource/Factory/CModelLoader.cpp +++ b/src/Core/Resource/Factory/CModelLoader.cpp @@ -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)); } } diff --git a/src/Core/Resource/Model/CVertex.h b/src/Core/Resource/Model/CVertex.h index 75199f1b..ee221828 100644 --- a/src/Core/Resource/Model/CVertex.h +++ b/src/Core/Resource/Model/CVertex.h @@ -6,7 +6,7 @@ #include #include -typedef std::array TBoneIndices; +typedef std::array TBoneIndices; typedef std::array TBoneWeights; class CVertex