diff options
author | clayjohn <claynjohn@gmail.com> | 2023-01-27 14:55:22 -0800 |
---|---|---|
committer | clayjohn <claynjohn@gmail.com> | 2023-01-27 14:55:22 -0800 |
commit | eb9c2b878a8c86a96a2c5013bf15a915df7e1338 (patch) | |
tree | 8d393ed910193f159e1ac71fe9b8eda365e0dd49 /drivers/gles3/shaders | |
parent | 0f8f0ab126437ed593e6463b85a6ee25af9ee5d4 (diff) |
Automatically transform Skeleton2D calculations so pivots are not needed
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/skeleton.glsl | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/drivers/gles3/shaders/skeleton.glsl b/drivers/gles3/shaders/skeleton.glsl index a1e3c098f4..aad856a5a2 100644 --- a/drivers/gles3/shaders/skeleton.glsl +++ b/drivers/gles3/shaders/skeleton.glsl @@ -87,6 +87,16 @@ uniform highp float blend_weight; uniform lowp float blend_shape_count; #endif +#ifdef USE_SKELETON +uniform mediump vec2 skeleton_transform_x; +uniform mediump vec2 skeleton_transform_y; +uniform mediump vec2 skeleton_transform_offset; + +uniform mediump vec2 inverse_transform_x; +uniform mediump vec2 inverse_transform_y; +uniform mediump vec2 inverse_transform_offset; +#endif + vec2 signNotZero(vec2 v) { return mix(vec2(-1.0), vec2(1.0), greaterThanEqual(v.xy, vec2(0.0))); } @@ -164,10 +174,13 @@ void main() { m += GET_BONE_MATRIX(bones.z, bones_a.z, in_weight_attrib.z); m += GET_BONE_MATRIX(bones.w, bones_a.w, in_weight_attrib.w); + mat4 skeleton_matrix = mat4(vec4(skeleton_transform_x, 0.0, 0.0), vec4(skeleton_transform_y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(skeleton_transform_offset, 0.0, 1.0)); + mat4 inverse_matrix = mat4(vec4(inverse_transform_x, 0.0, 0.0), vec4(inverse_transform_y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(inverse_transform_offset, 0.0, 1.0)); mat4 bone_matrix = mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); - //reverse order because its transposed - out_vertex = (vec4(out_vertex, 0.0, 1.0) * bone_matrix).xy; + bone_matrix = skeleton_matrix * transpose(bone_matrix) * inverse_matrix; + + out_vertex = (bone_matrix * vec4(out_vertex, 0.0, 1.0)).xy; #endif // USE_SKELETON #else // MODE_2D |