title: Applying weights to matrixes and vertices (bone rotation)
body: <p>I'm rotating the bones of a skeleton inside a mesh for a low poly 3D figure. On the vertex shader its applied like this.
  <br>glsl:</p>
  
  <pre><code>    vec4 vert1 = (bone_matrix[index1]*vertex_in)*weight;
      vec4 vert2 = (bone_matrix[index2]*vertex_in)*(1-weight);
      gl_Position =  vert1+vert2;
  </code></pre>
  
  <p><code>bone_matrix[index1]</code> is the matrix of one bone and <code>bone_matrix[index2]</code> is the matrix of the other.  <code>weight</code> designates <code>vertex_in</code>'s membership to these bones. The problem is the closer the weight is to .5, the more the diameter of the elbow shrinks when a rotation is applied. I've tested it with around a 10,000 vertex cylinder shape (with a gradient of weights).  The result looked like bending a garden hose.</p>
  
  <p>I got my weighting method from these sources. Its actually the only way I could find:<br>
  <a href="http://www.opengl.org/wiki/Skeletal_Animation" rel="nofollow noreferrer">http://www.opengl.org/wiki/Skeletal_Animation</a><br>
  <a href="http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html" rel="nofollow noreferrer">http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html</a><br>
  <a href="http://blenderecia.orgfree.com/blender/skinning_proposal.pdf" rel="nofollow noreferrer">http://blenderecia.orgfree.com/blender/skinning_proposal.pdf</a></p>
  
  <p><img src="https://i.stack.imgur.com/gYjdM.png" alt="initial_ugly_good"></p>
  
  <p>The left is how the shape starts, the middle is how the above equation rotates it, and the right is my goal. The mid points are weighted <code>0.5</code>. It only gets worse the more bent it is, at 180 degrees it has zero diameter.</p>
  
  <ul>
  <li>I've tried assembling the matrix on the shader, so that I can apply the weights to the rotation instead of the resulting vertices. It looks perfect like the one in picture on the right, but it requires assembling the matrix for every single vertex (expensive)</li>
  <li>I've looked into quaternions, but glsl doesn't natively support them (correct me if I'm wrong) and they're confusing. Is that what I need to do?</li>
  <li>I've considered having three bones per joint, and add a "kneecap" between every bone. This wouldn't eliminate the problem but would mitigate it.</li>
  <li>I'm considering projecting the vertex its original distance from the axis after they're rotated.  This would fail at 180 degrees but would be (relatively) cheap.</li>
  </ul>
  
  <p>So considering the options, or other options that I may not have considered, <strong>How have others avoid this pinching effect?</strong></p>
  
  <p><strong>EDIT:</strong>  I've gotten SLERP to work using quaternions but I opted not to use it as GLSL does not natively support it. I couldn't get the geometric SLERP to work as described by Tom. I got NLERP working for the first 90 degrees, so I added an extra "bone" between each joint. So to bend the forearm 40 degrees I bend the elbow and the forearm by 20 degrees each. This eliminates the pinching effect at the expense of doubling the quantity of bones which is not an ideal solution.</p>