From a66e8a29a71f87b182485b3a5dcd00f37638cd57 Mon Sep 17 00:00:00 2001 From: The Benedani <18270989+Benedani@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:19:22 +0200 Subject: [PATCH] GLES2: Make GPU skinning more consistent --- drivers/gles2/shaders/scene.glsl | 49 +++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl index a41cda80e1f7..2775f2c34151 100644 --- a/drivers/gles2/shaders/scene.glsl +++ b/drivers/gles2/shaders/scene.glsl @@ -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