1
\$\begingroup\$

I'm working on skeletal animation and so far I've got the skeleton drawn with interpolated animation working (just on the cpu still). I was thinking about changing my file format for my skeleton and animations to have fully calculated matrices stored.

Right now I calculate my matrices recursively by multiplying the parent's world matrix(absolute matrix) by the childs joint matrix, same thing with each frame of animation. I think it would be a good idea to just export all of this pre-calculated to my model format so I could just send these matrices to the shader for skinning.

Is there any reason I should not do this?

Edit: Calculating the matrices is negligible by itself on a rather small skeleton anyway but is there any reason I should calculate them at run time or just pre-calculate in my file format? I think this sums up my question better.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

This seems like an optimization question. As such the answer, as always is to profile it. If generating the matrices doesn't take too much time on the fly, then it is simply easier to do on the fly, as you don't have to write and export/import of matrices, and add it to your file format.

And perhaps you could simply use other file formats natively and not have to bake your resources.

On the other hand if your application is very very animation intensive, it may be worth it to move the matrix calculation to the baking stage.(Tough I would seriously doubt that.)

In the end this looks like a premature optimization to me. If you are interested, then you should profile it first, and if the results say you spend too much time calculating matrices, then do it.

PS: If you do profile it, don't forget to post the results.


EDIT:

To answer your comments, there is no reason to precalculate the matrices. But I see no problem in doing so. But if you also want to interpolate... It doesn't look straightforward. Maybe you could store a matrix for every frame but that would be quite a lot of data.

Well To expand on this here is some calculation: Assuming 4x4 matrices of float(4byte) data. Lets assume you have 16 bones in your model. And you want 200 animation frames. And you want interpolation so you do 2000 animation frames instead(10 subframes)(Assuming a bad case scenario). This would require 2000kB of memory/disk space.

Thats not a lot.(Except if you are doing skinning on GPU, then if you consider 100 different models, this is 200MB animation data, which is quite significant.) But you could just easily calculate it on the fly with even more accuracy, and don't need to have larger files.

And mainly: write, test and maintain the extra code to do it the other way around.

So the more I think about it the less feasible reasonable it seems.

\$\endgroup\$
12
  • \$\begingroup\$ I guess it's in part optimization question but more so would I run into any issues when trying to skin using these matrices. As far as changing this in my exporter it'd be fairly simple. I will take your advice and profile it but I'd really like to hear from someone who has tackled skeletal animation and may know some reasons this is a good or bad idea. \$\endgroup\$
    – Exempt
    Mar 7, 2015 at 18:47
  • \$\begingroup\$ Calculating the matrices is negligible by itself on a rather small skeleton anyway but is there any reason I should calculate them at run time or just pre-calculate in my file format? \$\endgroup\$
    – Exempt
    Mar 7, 2015 at 21:06
  • \$\begingroup\$ @Exempt Edited answer. Sorry for the wait but had to think it through. \$\endgroup\$
    – akaltar
    Mar 7, 2015 at 21:33
  • \$\begingroup\$ I probably said that a bit weird or something but the interpolation is calculated by using the previous and next frames of animation(to save on the need for hundred of frames) the previous and next frames however need to be calculated everytime we switch from previous to the next frame. I feel likes it's a pointless step but since I lack experience with skinning I'm not sure it will work the way I want it to. \$\endgroup\$
    – Exempt
    Mar 8, 2015 at 2:16
  • \$\begingroup\$ @Exempt But are you interpolating the matrices or the rotation/position keys? I think that interpolating between matrices would have about the same cost as calculating everything on the fly...(tough that is just pure speculation). In the end it just seems pointless. Why should you pre-calculate the matrices? If it takes even a second to implement, but has no positives, you shouldn't do it. \$\endgroup\$
    – akaltar
    Mar 8, 2015 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .