perf: Compute bone matrices on CPU, not in vertex shader
This commit is contained in:
parent
8b3b940748
commit
0ef7d158fe
2 changed files with 11 additions and 10 deletions
|
@ -384,7 +384,7 @@ out vec2 fragLightmapCoords;
|
||||||
out mat3 fragTanSpace;
|
out mat3 fragTanSpace;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 newPosition = vec3(0.0);
|
vec4 P = vec4(0.0);
|
||||||
|
|
||||||
if (isFeatureEnabled(FEATURE_SKELETAL)) {
|
if (isFeatureEnabled(FEATURE_SKELETAL)) {
|
||||||
float weight0 = aBoneWeights.x;
|
float weight0 = aBoneWeights.x;
|
||||||
|
@ -397,19 +397,20 @@ void main() {
|
||||||
int index2 = int(aBoneIndices.z);
|
int index2 = int(aBoneIndices.z);
|
||||||
int index3 = int(aBoneIndices.w);
|
int index3 = int(aBoneIndices.w);
|
||||||
|
|
||||||
vec4 position4 = vec4(aPosition, 1.0);
|
vec4 position = vec4(aPosition, 1.0);
|
||||||
|
|
||||||
newPosition += weight0 * (uAbsTransformInv * uBones[index0] * uAbsTransform * position4).xyz;
|
P += weight0 * uBones[index0] * position;
|
||||||
newPosition += weight1 * (uAbsTransformInv * uBones[index1] * uAbsTransform * position4).xyz;
|
P += weight1 * uBones[index1] * position;
|
||||||
newPosition += weight2 * (uAbsTransformInv * uBones[index2] * uAbsTransform * position4).xyz;
|
P += weight2 * uBones[index2] * position;
|
||||||
newPosition += weight3 * (uAbsTransformInv * uBones[index3] * uAbsTransform * position4).xyz;
|
P += weight3 * uBones[index3] * position;
|
||||||
|
|
||||||
|
P = vec4(P.xyz, 1.0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
newPosition = aPosition;
|
P = vec4(aPosition, 1.0);
|
||||||
}
|
}
|
||||||
vec4 newPosition4 = vec4(newPosition, 1.0);
|
|
||||||
|
|
||||||
fragPosition = vec3(uModel * newPosition4);
|
fragPosition = vec3(uModel * P);
|
||||||
fragNormal = mat3(transpose(inverse(uModel))) * aNormal;
|
fragNormal = mat3(transpose(inverse(uModel))) * aNormal;
|
||||||
fragTexCoords = aTexCoords;
|
fragTexCoords = aTexCoords;
|
||||||
fragLightmapCoords = aLightmapCoords;
|
fragLightmapCoords = aLightmapCoords;
|
||||||
|
|
|
@ -178,7 +178,7 @@ void ModelNodeSceneNode::renderSingle(bool shadowPass) const {
|
||||||
|
|
||||||
ModelNodeSceneNode *bone = _modelSceneNode->getModelNodeByIndex(nodeIdx);
|
ModelNodeSceneNode *bone = _modelSceneNode->getModelNodeByIndex(nodeIdx);
|
||||||
if (bone) {
|
if (bone) {
|
||||||
locals.skeletal->bones[boneIdx] = bone->boneTransform();
|
locals.skeletal->bones[boneIdx] = _modelNode->absoluteTransformInverse() * bone->boneTransform() * _modelNode->absoluteTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue