Slow vertex shader (skeletal animation)

Started by isaacwaller, April 02, 2012, 20:47:34

Previous topic - Next topic

isaacwaller

Hi,

I'm having issues with my skeletal animation vertex shader. When animating about 32 models at once I can only get 60 fps, and on low end computers I get even less. Vertex shader below:

uniform mat4 boneMatrixes[128];

void main(){
  
  vec4 a = gl_Vertex;
  
  // Apply bone transformation
  a = boneMatrixes[int(gl_Normal.x)] * gl_Vertex;

  gl_Position = gl_ModelViewProjectionMatrix * a;
  gl_TexCoord[0] = gl_MultiTexCoord0;
  
}


Parameters are bound like:
    int boneMatrixesName = ARBShaderObjects.glGetUniformLocationARB(mProgramShader, "boneMatrixes");

    // matrixFloatBuffer is a FloatBuffer of size 128 * 16
    ARBShaderObjects.glUniformMatrix4ARB(boneMatrixesName, false, matrixFloatBuffer);


Commenting out the
a = boneMatrixes[int(gl_Normal.x)] * gl_Vertex;
line increases performance by about 500%. How can I increase performance for this vertex shader? It looks as simple and fast as possible. Any help would be much appreciated!

CodeBunny

How complex are the models? Is that a limiting factor?

isaacwaller

Using a less complex model slightly increases FPS but not by very much, I think the issue is more with the shader and not with the amount of geometry passing through it.

spasi

Try using a custom attribute for the bone index, instead of gl_Normal.x. It should be declared as an integer in the shader, but you may use the short type in your VBO.

isaacwaller

Thanks for the suggestion. I changed the code to use a custom vertex attribute, but I don't see any performance increase.

isaacwaller

I have changed the code so only the required amount of bones are transferred to the vertex shader. This means on static models with only 1 bone there is only 1 matrix being transferred, example:

ARBShaderObjects.glUniformMatrix4ARB(boneMatrixesName, false, (FLOATBUFFER OF LENGTH / SIZE 16));


However, performance is still terrible! Even though I am only transferring a single matrix in a floatbuffer, I only get around 200 fps. Commenting out the line in the vertex shader increases performance to over 5000FPS / second (this is with the small, static model with about 20 vertexes.) This is very strange! Does anyone have any ideas on what could be causing the slowdown?

isaacwaller

I have found that using a constant as the array index while accessing boneMatrixes brings performance up to the same level that I get when the whole line is commented out. Is the problem that I should not be using a vertex attribute as an array index? I can't think of any other way to do it.