[3.x] GLES2: Make GPU skinning more consistent with GLES3 #80652
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My first contribution here! 👋
Aside from consistency, functionally, this may improve performance, with a single ivec4 cast as opposed to 4 separate int casts for bone_ids, plus calling transpose() 1 time instead of 4.
But this change is mainly motivated by the vec4 indexing in the previous implementation causing the following issue on my Xiaomi Redmi 6A device on WebGL (a desktop and a high-end mobile device, and a native export on the same device worked, so this is entirely a driver+ANGLE issue):
With the GLES3 implementation ported over, the model renders correctly (the issue with her clothes is common in Makehuman, the rendering is technically correct):
The minimal fix for the issue would be changing
bone_transform += transpose(b) * bone_weights[i];
to:
bone_transform += transpose(b) * dot(bone_weights, vec4(i == 0 ? 1.0 : 0.0, i == 1 ? 1.0 : 0.0, i == 2 ? 1.0 : 0.0, i == 3 ? 1.0 : 0.0));
but this would degrade performance, and looks quite ugly.