Jump to content

  • Log In with Google      Sign In   
  • Create Account

Vertex Weight / Skinning Calculations - GPU or CPU?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 06 March 2013 - 11:59 PM

Hello, I'm a self taught programmer and I'm currently working on my own game engine built from the ground up using LWJGL. I'm currently having a pretty big performance problem with animations. I have written my own format for skeletal meshes and animations that I export from 3DS Max and then import at load time. The information is stored in a simple array of bones, vertexes and, triangles and rendered by OGL. For animation I use quaternions for the rotation values of each bone.

 

On each update I move and rotate the bones to the next place they need to be in the animation and then calculate the movement and rotation for each vertex based on their weight. 

- I use doubles for almost all my location and rotation values in the engine.

- I am doing the vertex calculations on the CPU with my own Math classes and what not.

- I am currently only using a single thread for the model updates.

- In java I am using the built in Math.sin, Math.cos, Math.tan for a lot of calculations.

 

As it stands the models animate fine but it takes too long to do the calculation for the animations. I get noticeable slow downs after I have about 20,000 vertexes being updated on every game step.

 

Should I try using floats? Should I try using the OpenGL GPU skinning api? Should I try splitting the calculations out to seperate threads? Should I find a faster math Library for java?

 

All advice is welcome. :)

I can post the actual code for my vertex weights if it would help as well.



Sponsor:

#2 TheChubu   Crossbones+   -  Reputation: 4761

Like
0Likes
Like

Posted 07 March 2013 - 01:12 AM

I don't think you'll find a faster lang.Math library implementation. I've even read that Android's lang.Math library, which uses floats instead of doubles, is slower. And the JDK implementation is written in C++ last time I checked.

 

A completely (un) educated guess of mine would be to see if you have GPU to spare. If you have, do the skinning on the GPU, if you don't, profile (VisualVM, free profiler for Java for example) and see if you can optimize the slowest parts of the skinning process.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#3 Ashaman73   Crossbones+   -  Reputation: 7991

Like
0Likes
Like

Posted 07 March 2013 - 01:15 AM

- I use doubles for almost all my location and rotation values in the engine.

- I am doing the vertex calculations on the CPU with my own Math classes and what not.

- I am currently only using a single thread for the model updates.

- In java I am using the built in Math.sin, Math.cos, Math.tan for a lot of calculations.

This are all more or less all reasons for a slow down. Use the GPU for skinning, though bone calculations can be left on the CPU for now.



#4 C0lumbo   Crossbones+   -  Reputation: 2497

Like
0Likes
Like

Posted 07 March 2013 - 05:00 AM

Multithreading should be a really big win for you assuming you're targeting machines with multiple cores. If it were C++, I'd say you should always use floats instead of doubles, I don't know about Java. Hardware skinning (using the GPU) is a trade-off - it will speed things up on the CPU and slow things down on the GPU, so it depends on your game's balance.

 

Another thing to consider is lodding. Can you switch to lower detailed models for distant skins? Can you reduce the number of weights per vertex for lower lod models? Can you get away with calculating the normal based on only the largest bone weight instead of all of them?



#5 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 07 March 2013 - 04:33 PM

GPU usage right now in my engine is very low. I have not put in any kind of post processing or shading so far. Just standard diffuse texture rendering. I have also not implemented lighting in any way yet. 

 

I don't know how heavy the GPU usage will be once I get those things added in and I have no idea what kind of improvement in performance it would grant me. I would love some statistics on that if anyone has done some research on it.

 

I was thinking maybe I could move the vertex weight updates out to there own thread that runs alongside physics and game world updates. Should I put each model skin update on it's own thread or just have a single thread dedicated to handling those?

 

The LOD idea is great. I can't believe I haven't even thought about that yet. I can easily add that though so it's good that you mentioned it :D



#6 Schrompf   Prime Members   -  Reputation: 954

Like
0Likes
Like

Posted 07 March 2013 - 06:35 PM

Put the skinning on the GPU. Todays gamer GPUs have such an incredible amount of computing power specialized for exactly this kind of calculations that you wouldn't be able to measure a difference even when your GPU is fully loaded. 


----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

#7 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 07 March 2013 - 07:18 PM

Put the skinning on the GPU. Todays gamer GPUs have such an incredible amount of computing power specialized for exactly this kind of calculations that you wouldn't be able to measure a difference even when your GPU is fully loaded. 


Alright, I'm going to branch my CPU skinning and implement a GPU skinning and do some speed comparisons.


Edited by newObjekt, 07 March 2013 - 07:18 PM.


#8 mhagain   Crossbones+   -  Reputation: 8277

Like
0Likes
Like

Posted 07 March 2013 - 07:35 PM

Yeah, definitely go with GPU.

 

  • As you add more functionality elsewhere the CPU load is also going to increase.
  • Even if you thread it you've still got a max of 8 or so threads on current hardware; Even low-end GPUs have hundreds.  And the threading is free, with no messy code required on your part.
  • Even if you use SSE instructions, GPUs are still better optimized for this kind of calculation.  Also free, with no messy code required on your part.
  • Even if none of the above matter to you, you've still got a heavy upload of the transformed positions to do; using the GPU you only need a much lighter upload of bone matrices.
  • As you add more animated models to the scene that heavy upload is only going to get worse; using the GPU the upload will remain considerably lighter.
  • A GPU method allows for cool things such as different models sharing the same skeleton with much less overhead.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#9 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 07 March 2013 - 08:44 PM

Alright so I've done some research on GPU skinning and to be honest I am beyond lost.

 

Simply put I have this format in my engine

 

Bone

position(x,y,z) //original position

positionOffset(x,y,z) //distance moved (used in the animation)

rotationOffset(x,y,z,w) //rotation quaternion(used in animation)

 

Vertex

position(x,y,z) //position of vertex

weights[ ](bone, weight) //array of weights, each weight contains a bone and a weight

 

When I need to do skinning I just loop through every vertex in the model and use the vertex.weights to move and rotate the vertex.

 

How the balls do I accomplish this on the GPU using OpenGL?


Edited by newObjekt, 07 March 2013 - 08:47 PM.


#10 Schrompf   Prime Members   -  Reputation: 954

Like
0Likes
Like

Posted 08 March 2013 - 05:07 AM

What keeps you from doing exactly the same in the shader? And don't tell me you're using the fixed function pipeline, I'm out then.

 

To stay in your terms: you usually combine the bone's bind transformation (the original position and rotation) in relation to the mesh, plus the current rotation offset and position offset, all into one transformation matrix. You end up with an array of matrices which you upload to the shader. You enhance your vertex structure to contain a number of bone indices (normally 4, because the fit nicely into an input register) and an equal count of weights that specify how much the vertex is influenced by that bone. So every vertex in your mesh says: I'm affected by bone 13, 25 and 5, with a weight of 0.3, 0.25 and 0.45, respectively. The shader now simply transforms the vertex by each bone matrix, accumulating the result weighted by the corresponding vertex weight, and you're done.


----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

#11 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 09 March 2013 - 01:19 PM

What keeps you from doing exactly the same in the shader? And don't tell me you're using the fixed function pipeline, I'm out then.

 

To stay in your terms: you usually combine the bone's bind transformation (the original position and rotation) in relation to the mesh, plus the current rotation offset and position offset, all into one transformation matrix. You end up with an array of matrices which you upload to the shader. You enhance your vertex structure to contain a number of bone indices (normally 4, because the fit nicely into an input register) and an equal count of weights that specify how much the vertex is influenced by that bone. So every vertex in your mesh says: I'm affected by bone 13, 25 and 5, with a weight of 0.3, 0.25 and 0.45, respectively. The shader now simply transforms the vertex by each bone matrix, accumulating the result weighted by the corresponding vertex weight, and you're done.

Yeah this is basically what I read about but I could find any explanation on how to do it in code. 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS