LWJGL
May 23, 2013, 20:42:14 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Slow vertex shader (skeletal animation)  (Read 1119 times)
isaacwaller
Newbie
*
Posts: 5


« on: April 02, 2012, 13:47:34 »

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:

Code:
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:
Code:
    int boneMatrixesName = ARBShaderObjects.glGetUniformLocationARB(mProgramShader, "boneMatrixes");

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

Commenting out the
Code:
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!
Logged
CodeBunny
Nerdus Imperius
*****
Posts: 561



WWW
« Reply #1 on: April 03, 2012, 05:13:14 »

How complex are the models? Is that a limiting factor?
Logged
isaacwaller
Newbie
*
Posts: 5


« Reply #2 on: April 03, 2012, 09:21:44 »

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.
Logged
spasi
Nerdus Imperius
*****
Posts: 752



WWW
« Reply #3 on: April 03, 2012, 09:46:52 »

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.
Logged
isaacwaller
Newbie
*
Posts: 5


« Reply #4 on: April 03, 2012, 10:50:24 »

Thanks for the suggestion. I changed the code to use a custom vertex attribute, but I don't see any performance increase.
Logged
isaacwaller
Newbie
*
Posts: 5


« Reply #5 on: April 03, 2012, 10:56:52 »

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:

Code:
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?
Logged
isaacwaller
Newbie
*
Posts: 5


« Reply #6 on: April 03, 2012, 11:25:42 »

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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!