# How do I make the joints and weights skinned with the variables I'm using?

For some time now I have been trying to do skeleton animation using Rust and OpenGL(specifically the gl library), I loaded the animation information correctly(with the gltf library), the bone ids and the influence weights, however I was unable to apply the animation to the 100% correct model.

The screenshot below is the furthest I could get from making the animation look correct, the problem is that if you get close... You can see that between the transition from bone to bone, the joints with a greater deformation prevent the lighting is perfect on the character's skin, creating a slight doll-like sensation in which the joints highlight the skeleton:

This happens because the code I used in the shader is basically this where I only use the first transformation in the model:

// Animation
vec4 tp = vec4(pos,1);
tp = CORRECAO[int(ossosid[0])]*tp;
tp = (ANIMACAO[int(ossosid[0])]*tp);
tp.xyz += ANIMACAO2[int(ossosid[0])];
// Forget that part, that's just because the animation is scaled to appear on the screen...
// It's not part of the animation calculation.
pos = tp.xyz/50;


When I try to follow examples in which I use influence weights... It's not working, more specifically I can give code examples and show how it's not working:

When I try to switch to calculation:

vec4 tp = vec4(pos,1);
tp = CORRECAO[int(ossosid[0])]*tp;
tp = (ANIMACAO[int(ossosid[0])]*tp)*pesos[0] + (ANIMACAO[int(ossosid[1])]*tp)*pesos[1];
tp.xyz += ANIMACAO2[int(ossosid[0])]*pesos[0] + ANIMACAO2[int(ossosid[1])]*pesos[1];
pos = tp.xyz/50;


Totally distorted when:

Using:

vec4 tp = vec4(pos,1);
vec4 tp0 = CORRECAO[int(ossosid[0])]*tp;
tp0 = (ANIMACAO[int(ossosid[0])]*tp0)*pesos[0];
tp0.xyz += ANIMACAO2[int(ossosid[0])];
vec4 tp1 = CORRECAO[int(ossosid[1])]*tp;
tp1 = (ANIMACAO[int(ossosid[1])]*tp1)*pesos[1];
tp1.xyz += ANIMACAO2[int(ossosid[1])];
pos = tp0.xyz+tp1.xyz;
pos = pos.xyz/50;


Another:

vec4 tp = vec4(pos,1);
tp = (CORRECAO[int(ossosid[0])]*tp)*pesos[0];
tp = (ANIMACAO[int(ossosid[0])]*tp);
tp.xyz += ANIMACAO2[int(ossosid[0])]*pesos[0];
tp = (CORRECAO[int(ossosid[1])]*tp)*pesos[1];
tp = (ANIMACAO[int(ossosid[1])]*tp);
tp.xyz += ANIMACAO2[int(ossosid[1])]*pesos[1];
pos = tp.xyz/50;


Just one more:

vec4 tp = vec4(pos,1);
tp = (CORRECAO[int(ossosid[0])]*tp);
tp = (ANIMACAO[int(ossosid[0])]*tp)*pesos[0]+(ANIMACAO[int(ossosid[1])]*tp)*pesos[1];
tp.xyz += ANIMACAO2[int(ossosid[0])];
pos = tp.xyz/50;


In other words... I can't make elbows, knees, shoulders, leg connections and hips as smooth as I can do everything else... Specifically, know that: CORRECAO is the inverse bind matrix, ANIMACAO is the variable that rotates the point and ANIMACAO2 is the position of the point in the animation.

My question is how do I make the joints on the model look smooth? How do I apply this in the vertex shader?

P.S.: The animated model is here: link

vec4 tp = vec4(0);
vec4 tp1 = (CORRECAO[int(ossosid[0])]*vec4(pos,1));
tp1 = (ANIMACAO[int(ossosid[0])]*tp1);
tp1.xyz += ANIMACAO2[int(ossosid[0])];
tp += tp1*pesos[0];
tp1 = (CORRECAO[int(ossosid[1])]*vec4(pos,1));
tp1 = (ANIMACAO[int(ossosid[1])]*tp1);
tp1.xyz += ANIMACAO2[int(ossosid[1])];
tp += tp1*pesos[1];
tp1 = (CORRECAO[int(ossosid[2])]*vec4(pos,1));
tp1 = (ANIMACAO[int(ossosid[2])]*tp1);
tp1.xyz += ANIMACAO2[int(ossosid[2])];
tp += tp1*pesos[2];
tp1 = (CORRECAO[int(ossosid[3])]*vec4(pos,1));
tp1 = (ANIMACAO[int(ossosid[3])]*tp1);
tp1.xyz += ANIMACAO2[int(ossosid[3])];
tp += tp1*pesos[3];
pos = tp.xyz/100;