title: Skeletal Animation ussing ASSIMP and GLSL: bone uniform array size
body: <p>I'm working on an ASSIMP <strong>skeletal animation</strong> loader and renderer and right now all the data is correctly loaded and interpolated at its current timeframe. However, there is still one part that isn't working as it should and that's the vertex shader stage.</p>
  
  <p>Via a <strong>VBO</strong> I pass in two <code>vec4</code>s that contain the bone IDs and the weights for each vertex (up to a maximum of <strong>4</strong> bones/weights per vertex) and the vertex shader has a matrix array of <strong>100</strong> bone transformations (pre-calculated per frame) that are indexed via the bone IDs.</p>
  
  <p>However, it seems that the bones uniform doesn't contain the proper transformations. For debugging purposes I colored the model with the weight values and the bone IDs value and they contain a color (and thus valid values). However, when I transform my vertex via the bone transformation and color the model with the result, the entire model is colored black, meaning the transformation matrices are all <code>0.0</code>. So they're not initialized properly.</p>
  
  <p>I think the problem is with passing the matrices to the uniform array, or perhaps the <strong>maximum size</strong> of uniforms allowed (I also tried setting the number of uniform matrices to 32 (number of bones on current model) but without effect)? </p>
  
  <p>Before passing the information to the shader, the transformation matrices are indeed valid matrices (not identity/empty matrices) so the fault should probably be in the GLSL shader or the passing of the uniforms.</p>
  
  <p><em>The following code is from the vertex shader:</em></p>
  
  <pre><code>#version 330
  layout (location = 0) in vec3 position;
  layout(location = 1) in vec3 normal;
  layout(location = 2) in vec3 tangent;
  layout(location = 3) in vec3 color;
  layout(location = 4) in vec2 texCoord;
  layout(location = 5) in ivec4 boneIDs;
  layout(location = 6) in vec4 weights;
  
  uniform mat4 projection;
  uniform mat4 view;
  uniform mat4 model;
  uniform mat4 bones[100];
  
  out vec2 TexCoord;
  out vec4 colorz;
  
  void main()
  {
      vec4 newPos = vec4(position, 1.0);
      colorz = vec4(0.0, 1.0, 0.0, 1.0);
      if (weights != vec4(0.0, 0.0, 0.0, 0.0))
      {
          mat4 boneTransform = bones[boneIDs[0]] * weights[0];
          boneTransform += bones[boneIDs[1]] * weights[1];
          boneTransform += bones[boneIDs[2]] * weights[2];
          boneTransform += bones[boneIDs[3]] * weights[3];
  
          // newPos = boneTransform * vec4(position, 1.0);
          vec4 test = vec4(1.0);
          colorz = boneTransform * test;
          // newPos = boneTransform * newPos;
      }
  
      TexCoord = texCoord;
      gl_Position = projection * view * model * newPos;
  }
  </code></pre>
  
  <p><em>The following snippet of code pass the matrix data to the GLSL shader:</em></p>
  
  <pre><code>// Sets bone transformation matrices
  void Shader::SetBoneMatrix(GLint index, aiMatrix4x4 matrix)
  {
      glm::mat4 mat = glm::transpose(glm::make_mat4(&amp;matrix.a1));
      glUniformMatrix3fv(boneLocations[index], 1, GL_FALSE, glm::value_ptr(mat));  
  }
  </code></pre>
  
  <p><em>Also the code that gets all the uniform locations of the bones array:</em></p>
  
  <pre><code>for(unsigned int i = 0; i &lt; 100; i++)
  {
      string name = "bones[";
      string number;
      stringstream ss;
      ss &lt;&lt; i;
      ss &gt;&gt; number;
      name += number;
      name += ']';
      boneLocations[i] = glGetUniformLocation(this-&gt;program, name.c_str());
  }
  </code></pre>