c++openglglslcolladaskeletal-mesh

How to transfer skeleton weights in vertex shaders?


I made a c++ collada reader but i draw a 3K animated mesh in 4ms using the opengl direct mode . That's too slow.

So i decided to use a vertex shader .In a skeleton , each vertex have a weight (zero or more) for each bone. For a 3K mesh with 40 bones, you have 120 000 weights for the whole object.

The only problem is in GLSL you can't declare uniform arrays with big sizes.

For example this will compile ( vertex shader):

///////////////////////////////////////////

uniform float weights [10] ;

void main (void)

{
 float test= weights[0];

  gl_Position = ftransform();

}

/// but not this :

uniform float weights [120000] ;

void main (void)

{
  float test= weights[0];

  gl_Position = ftransform();

}

//////////////////////////////////////////

I have seen in some pages i could use glVertexAttribPointer() to set attributes for each vertex. This will be done if i had between 1 and 4 bones (i could use vecX attributes), but GLSL( in my case 1.20) don't accecpt attributes arrays.


Solution

  • As mentionned by keltar and Andon M. Coleman , you should use vec4 attributes. In some cases some vertices have more than 4 bones controling them. What you could do is just consider the bones with the bigest weights.