Skip to content

Commit

Permalink
Merge pull request #80652 from Benedani/3.x_fix_gles2_skinning
Browse files Browse the repository at this point in the history
[3.x] GLES2: Make GPU skinning more consistent with GLES3
  • Loading branch information
akien-mga committed Aug 16, 2023
2 parents dcb097c + a66e8a2 commit 98976f9
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions drivers/gles2/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,44 @@ void main() {
#else
// look up transform from the "pose texture"
{
for (int i = 0; i < 4; i++) {
ivec2 tex_ofs = ivec2(int(bone_ids[i]) * 3, 0);

highp mat4 b = mat4(
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(0, 0)),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(2, 0)),
vec4(0.0, 0.0, 0.0, 1.0));

bone_transform += transpose(b) * bone_weights[i];
}
ivec4 bone_indicesi = ivec4(bone_ids); // cast to signed int

ivec2 tex_ofs = ivec2(bone_indicesi.x * 3, 0);
bone_transform = mat4(
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(2, 0)),
vec4(0.0, 0.0, 0.0, 1.0)) *
bone_weights.x;

tex_ofs = ivec2(bone_indicesi.y * 3, 0);

bone_transform += mat4(
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(2, 0)),
vec4(0.0, 0.0, 0.0, 1.0)) *
bone_weights.y;

tex_ofs = ivec2(bone_indicesi.z * 3, 0);

bone_transform += mat4(
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(2, 0)),
vec4(0.0, 0.0, 0.0, 1.0)) *
bone_weights.z;

tex_ofs = ivec2(bone_indicesi.w * 3, 0);

bone_transform += mat4(
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
texel2DFetch(bone_transforms, skeleton_texture_size, tex_ofs + ivec2(2, 0)),
vec4(0.0, 0.0, 0.0, 1.0)) *
bone_weights.w;

bone_transform = transpose(bone_transform);
}

#endif
Expand Down

0 comments on commit 98976f9

Please sign in to comment.