From 374567ae4b18627f9ab410e7e5a38b1e7aeb04c5 Mon Sep 17 00:00:00 2001 From: Omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 20 Apr 2024 22:02:34 +1000 Subject: it works with negating Y axis of local transform and inverse bind matrix. I have NO IDEA why --- src/renderer/render.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/renderer/render.c') diff --git a/src/renderer/render.c b/src/renderer/render.c index d7e2d48..d9b45cf 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -195,18 +195,24 @@ void draw_skinned_mesh(renderer* ren, mesh* mesh, transform tf, material* mat, m mat4* bone_transforms = malloc(n_bones * sizeof(mat4)); mat4 parent = mat4_ident(); for (int bone_i = 0; bone_i < n_bones; bone_i++) { + joint j = mesh->bones->data[bone_i]; transform tf = mesh->bones->data[bone_i].transform_components; - mat4 local = transform_to_mat(&mesh->bones->data[bone_i].transform_components); - bone_transforms[bone_i] = mat4_mult(parent, local); + tf.position.y = -tf.position.y; + mat4 local = transform_to_mat(&tf); + mat4 inverse = j.inverse_bind_matrix; + inverse.data[13] = -inverse.data[13]; + mat4 intemediate = mat4_mult(local, inverse); + + bone_transforms[bone_i] = intemediate; parent = bone_transforms[bone_i]; } // premultiply the inverses - for (int bone_i = 0; bone_i < n_bones; bone_i++) { - joint j = mesh->bones->data[bone_i]; - // bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); - bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); - } + // for (int bone_i = 0; bone_i < n_bones; bone_i++) { + // joint j = mesh->bones->data[bone_i]; + // // bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); + // bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); + // } glUniformMatrix4fv(glGetUniformLocation(lighting_shader.program_id, "boneMatrices"), n_bones, GL_FALSE, &bone_transforms->data[0]); -- cgit v1.2.3-70-g09d2