diff --git a/src/engine/graphics/mesh/mesh.cpp b/src/engine/graphics/mesh/mesh.cpp index d7c65a9b..6078b2f6 100644 --- a/src/engine/graphics/mesh/mesh.cpp +++ b/src/engine/graphics/mesh/mesh.cpp @@ -95,13 +95,13 @@ void Mesh::init() { glEnableVertexAttribArray(5); glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBitangents)); } - if (_attributes.offBoneWeights != -1) { - glEnableVertexAttribArray(6); - glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBoneWeights)); - } if (_attributes.offBoneIndices != -1) { + glEnableVertexAttribArray(6); + glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBoneIndices)); + } + if (_attributes.offBoneWeights != -1) { glEnableVertexAttribArray(7); - glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBoneIndices)); + glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBoneWeights)); } glBindVertexArray(0); diff --git a/src/engine/graphics/mesh/vertexattributes.h b/src/engine/graphics/mesh/vertexattributes.h index 44f9c5ce..0241daec 100644 --- a/src/engine/graphics/mesh/vertexattributes.h +++ b/src/engine/graphics/mesh/vertexattributes.h @@ -31,8 +31,8 @@ struct VertexAttributes { int offTexCoords2 { -1 }; int offTangents { -1 }; int offBitangents { -1 }; - int offBoneWeights { -1 }; int offBoneIndices { -1 }; + int offBoneWeights { -1 }; }; } // namespace graphics diff --git a/src/engine/graphics/model/mdlreader.cpp b/src/engine/graphics/model/mdlreader.cpp index d2b7bccb..9d432668 100644 --- a/src/engine/graphics/model/mdlreader.cpp +++ b/src/engine/graphics/model/mdlreader.cpp @@ -1033,8 +1033,8 @@ void MdlReader::readSkin(ModelNode &node) { vector boneIndices(readUint16Array(16)); ignore(4); // padding - node._mesh->mesh->attributes().offBoneWeights = offMdxBoneWeights; node._mesh->mesh->attributes().offBoneIndices = offMdxBoneIndices; + node._mesh->mesh->attributes().offBoneWeights = offMdxBoneWeights; unordered_map nodeIdxByBoneIdx; seek(kMdlDataOffset + offBones); diff --git a/src/engine/graphics/shader/shaders_common.cpp b/src/engine/graphics/shader/shaders_common.cpp index 88b425e5..5041db4e 100644 --- a/src/engine/graphics/shader/shaders_common.cpp +++ b/src/engine/graphics/shader/shaders_common.cpp @@ -354,8 +354,8 @@ layout(location = 2) in vec2 aTexCoords; layout(location = 3) in vec2 aLightmapCoords; layout(location = 4) in vec3 aTangent; layout(location = 5) in vec3 aBitangent; -layout(location = 6) in vec4 aBoneWeights; -layout(location = 7) in vec4 aBoneIndices; +layout(location = 6) in vec4 aBoneIndices; +layout(location = 7) in vec4 aBoneWeights; out vec3 fragPosition; out vec3 fragNormal; @@ -368,22 +368,22 @@ void main() { vec4 P = vec4(0.0); if (isFeatureEnabled(FEATURE_SKELETAL)) { - float weight0 = aBoneWeights.x; - float weight1 = aBoneWeights.y; - float weight2 = aBoneWeights.z; - float weight3 = aBoneWeights.w; + int index1 = int(aBoneIndices.x); + int index2 = int(aBoneIndices.y); + int index3 = int(aBoneIndices.z); + int index4 = int(aBoneIndices.w); - int index0 = int(aBoneIndices.x); - int index1 = int(aBoneIndices.y); - int index2 = int(aBoneIndices.z); - int index3 = int(aBoneIndices.w); + float weight1 = aBoneWeights.x; + float weight2 = aBoneWeights.y; + float weight3 = aBoneWeights.z; + float weight4 = aBoneWeights.w; vec4 position = vec4(aPosition, 1.0); - P += weight0 * uBones[index0] * position; P += weight1 * uBones[index1] * position; P += weight2 * uBones[index2] * position; P += weight3 * uBones[index3] * position; + P += weight4 * uBones[index4] * position; P = vec4(P.xyz, 1.0);