Jump to content

  • Log In with Google      Sign In   
  • Create Account

[Optimising] Bone based Animation


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
5 replies to this topic

#1 gnomgrol   Members   -  Reputation: 622

Like
0Likes
Like

Posted 25 July 2014 - 09:40 AM

Well met!

 

I recently started to optimise my Engine. Using VS2012 Performance analysing tool, I quickly found the biggest bottlenecks.

 

By far the biggest one are my animations. I already managed to go up from 100Fps with 1 simple animated model to 150Fps with 50. While that is not bad, I still need it to get better. 

I fixed everything I could, but I don't know how to continue. The major performance-eaters are 

 D3DXQuaternionInverse

and

 D3DXQuaternionMultiply

which are an essential part of the computation that bone-based animations need, right?

Is there a way to work around those or are there cheaper ways to compute bb animations?

 

Those two take around 50%, the other 50% are beeing lost to stuff like

tempVert->pos.x += ( tempJoint->pos.x + rotatedPoint.x ) * tempWeight->bias;
// or
tempVert->normal.x -= rotatedPoint2.x * tempWeight->bias;
// or
currentSubset->vertices[i]->normal = -tempVert->normal;

( All CPU % in %-of-the-full-time in an uncapped application )

With 5% of the complete CPU time each. I don't understand why those are so very expensive.

Stuff like sqrt, sin and maybe even / are concidered expensive, but why are the basic math operations also a problem?

I am adding the full code of the function in question below, adding the % of CPU to the end of each line which is over 0.1%.

I tried to make it as readable as possible, but the Copy-paste into this forum still screws it up, I'm sorry.

 

Spoiler

 

 

I am new to profiling and optimising, so any tips are welcome! 

Thanks for your time!

 



Sponsor:

#2 Samith   Members   -  Reputation: 2273

Like
3Likes
Like

Posted 25 July 2014 - 10:03 AM


Stuff like sqrt, sin and maybe even / are concidered expensive, but why are the basic math operations also a problem?

 

Probably because you're doing TONS of those basic math operations.

 

Why are you doing all the per vertex skinning on the CPU? This is something that can easily be done entirely on the GPU (which will do many verts in parallel, taking advantage of the easy parallelism of the problem).



#3 gnomgrol   Members   -  Reputation: 622

Like
0Likes
Like

Posted 25 July 2014 - 11:22 AM

I suppose that would be a good idea. I never did that because I somehow assumed that pushing "all that stuff" to the GPU would create as much traffic as this eats away CPU.

 

So, how do I go about it. I update only the bones on the CPU, then I push those to the GPU (per model in a constant buffer) and just add weight-information to each vertex.

Can I do the computation on the Vertex-Shader or should I use a computation shader? 



#4 Samith   Members   -  Reputation: 2273

Like
1Likes
Like

Posted 25 July 2014 - 11:30 AM


I suppose that would be a good idea. I never did that because I somehow assumed that pushing "all that stuff" to the GPU would create as much traffic as this eats away CPU.

 

All you have to do is send the bone transformations to the GPU, which is going to be significantly less data than having to send an entire mesh worth of skinned verts each frame (assuming your meshes have more than a small handful of verts).

 


So, how do I go about it. I update only the bones on the CPU, then I push those to the GPU (per model in a constant buffer) and just add weight-information to each vertex.
Can I do the computation on the Vertex-Shader or should I use a computation shader? 

 

That's exactly right. Add weight/index info to each vert, then send bone information to the vertex shader via a constant buffer. It'll be FAR more natural to do this in the vertex shader, rather than a compute shader. Do your bone transformations on each vert, then do the regular model-view-projection transformation just like normal.



#5 L. Spiro   Crossbones+   -  Reputation: 14219

Like
4Likes
Like

Posted 25 July 2014 - 12:17 PM

which are an essential part of the computation that bone-based animations need, right?

Exactly the opposite. Quaternions are among the worst ways to handle animations of any kind and should be avoided. All transforms should be done with matrices. The matrices should be constructed based off the 3 primitive elements of position, scale, and rotation. Animation tracks should modify each property of these elements independently. I have already discussed this in detail many times.
http://www.gamedev.net/topic/654326-skeletal-animation-system/?view=findpost&p=5139983
http://www.gamedev.net/topic/654326-skeletal-animation-system/?view=findpost&p=5140082

Briefly, a track modifies a single property of a single element of a matrix.
POSITION.Y = 1 track.
ROTATION.X = 1 track.
ROTATION.XYZ = 3 tracks.

After a track has been updated and its interpolated value used to modify a single property, the matrix is rebuilt. See links above. This is faster and more accurate than quaternion math.

Matrices are built for each bone.

For each draw call, the bone matrices that affect the current mesh are uploaded to the shader and skinning is performed in the vertex shader. The max number of influences per vertex is usually 4.


Between dropping the use of quaternions entirely and moving skinning to the shaders, you basically have to rewrite your animation code from scratch.
You can find shader samples for this in the DirectX samples that ship with the SDK.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#6 gnomgrol   Members   -  Reputation: 622

Like
0Likes
Like

Posted 25 July 2014 - 12:34 PM

Thanks a bunch Spiro, that is extremly helpfull! I'll rewrite everything using the model you mention in your other posts.

There is a good number of tutorials that use quaternions or suggest them.

That is not the first time something like that occurs. I have found a lot of tutorials that use the worst method possible. Really gotta be careful on who I listen to :/


Edited by gnomgrol, 25 July 2014 - 12:40 PM.





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