Swap bone indices and bone weights vertex attributes
This commit is contained in:
parent
640b5a3c8e
commit
4a2c507c0f
4 changed files with 18 additions and 18 deletions
|
@ -95,13 +95,13 @@ void Mesh::init() {
|
|||
glEnableVertexAttribArray(5);
|
||||
glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBitangents));
|
||||
}
|
||||
if (_attributes.offBoneWeights != -1) {
|
||||
glEnableVertexAttribArray(6);
|
||||
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBoneWeights));
|
||||
}
|
||||
if (_attributes.offBoneIndices != -1) {
|
||||
glEnableVertexAttribArray(6);
|
||||
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBoneIndices));
|
||||
}
|
||||
if (_attributes.offBoneWeights != -1) {
|
||||
glEnableVertexAttribArray(7);
|
||||
glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBoneIndices));
|
||||
glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBoneWeights));
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1033,8 +1033,8 @@ void MdlReader::readSkin(ModelNode &node) {
|
|||
vector<uint16_t> 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<uint16_t, uint16_t> nodeIdxByBoneIdx;
|
||||
seek(kMdlDataOffset + offBones);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue