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);
|
glEnableVertexAttribArray(5);
|
||||||
glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBitangents));
|
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) {
|
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);
|
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);
|
glBindVertexArray(0);
|
||||||
|
|
|
@ -31,8 +31,8 @@ struct VertexAttributes {
|
||||||
int offTexCoords2 { -1 };
|
int offTexCoords2 { -1 };
|
||||||
int offTangents { -1 };
|
int offTangents { -1 };
|
||||||
int offBitangents { -1 };
|
int offBitangents { -1 };
|
||||||
int offBoneWeights { -1 };
|
|
||||||
int offBoneIndices { -1 };
|
int offBoneIndices { -1 };
|
||||||
|
int offBoneWeights { -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace graphics
|
} // namespace graphics
|
||||||
|
|
|
@ -1033,8 +1033,8 @@ void MdlReader::readSkin(ModelNode &node) {
|
||||||
vector<uint16_t> boneIndices(readUint16Array(16));
|
vector<uint16_t> boneIndices(readUint16Array(16));
|
||||||
ignore(4); // padding
|
ignore(4); // padding
|
||||||
|
|
||||||
node._mesh->mesh->attributes().offBoneWeights = offMdxBoneWeights;
|
|
||||||
node._mesh->mesh->attributes().offBoneIndices = offMdxBoneIndices;
|
node._mesh->mesh->attributes().offBoneIndices = offMdxBoneIndices;
|
||||||
|
node._mesh->mesh->attributes().offBoneWeights = offMdxBoneWeights;
|
||||||
|
|
||||||
unordered_map<uint16_t, uint16_t> nodeIdxByBoneIdx;
|
unordered_map<uint16_t, uint16_t> nodeIdxByBoneIdx;
|
||||||
seek(kMdlDataOffset + offBones);
|
seek(kMdlDataOffset + offBones);
|
||||||
|
|
|
@ -354,8 +354,8 @@ layout(location = 2) in vec2 aTexCoords;
|
||||||
layout(location = 3) in vec2 aLightmapCoords;
|
layout(location = 3) in vec2 aLightmapCoords;
|
||||||
layout(location = 4) in vec3 aTangent;
|
layout(location = 4) in vec3 aTangent;
|
||||||
layout(location = 5) in vec3 aBitangent;
|
layout(location = 5) in vec3 aBitangent;
|
||||||
layout(location = 6) in vec4 aBoneWeights;
|
layout(location = 6) in vec4 aBoneIndices;
|
||||||
layout(location = 7) in vec4 aBoneIndices;
|
layout(location = 7) in vec4 aBoneWeights;
|
||||||
|
|
||||||
out vec3 fragPosition;
|
out vec3 fragPosition;
|
||||||
out vec3 fragNormal;
|
out vec3 fragNormal;
|
||||||
|
@ -368,22 +368,22 @@ void main() {
|
||||||
vec4 P = vec4(0.0);
|
vec4 P = vec4(0.0);
|
||||||
|
|
||||||
if (isFeatureEnabled(FEATURE_SKELETAL)) {
|
if (isFeatureEnabled(FEATURE_SKELETAL)) {
|
||||||
float weight0 = aBoneWeights.x;
|
int index1 = int(aBoneIndices.x);
|
||||||
float weight1 = aBoneWeights.y;
|
int index2 = int(aBoneIndices.y);
|
||||||
float weight2 = aBoneWeights.z;
|
int index3 = int(aBoneIndices.z);
|
||||||
float weight3 = aBoneWeights.w;
|
int index4 = int(aBoneIndices.w);
|
||||||
|
|
||||||
int index0 = int(aBoneIndices.x);
|
float weight1 = aBoneWeights.x;
|
||||||
int index1 = int(aBoneIndices.y);
|
float weight2 = aBoneWeights.y;
|
||||||
int index2 = int(aBoneIndices.z);
|
float weight3 = aBoneWeights.z;
|
||||||
int index3 = int(aBoneIndices.w);
|
float weight4 = aBoneWeights.w;
|
||||||
|
|
||||||
vec4 position = vec4(aPosition, 1.0);
|
vec4 position = vec4(aPosition, 1.0);
|
||||||
|
|
||||||
P += weight0 * uBones[index0] * position;
|
|
||||||
P += weight1 * uBones[index1] * position;
|
P += weight1 * uBones[index1] * position;
|
||||||
P += weight2 * uBones[index2] * position;
|
P += weight2 * uBones[index2] * position;
|
||||||
P += weight3 * uBones[index3] * position;
|
P += weight3 * uBones[index3] * position;
|
||||||
|
P += weight4 * uBones[index4] * position;
|
||||||
|
|
||||||
P = vec4(P.xyz, 1.0);
|
P = vec4(P.xyz, 1.0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue