Optimize Animated Submeshes

Hello, this is my first post. I like this engine a lot and well done to the team for making it. I have an optimization problem. I hope someone can help.



I am creating a game where everything uses a single material, vertex colors with no textures. I have an animated human model with over 20 submeshes. When I import the model it creates a node containing all the submeshes. When I want a new human I change the colors of all the submeshes to represent clothes/skin/hair. The results are exactly how I wanted them to look and they animate nicely too.



The problem is each human needs over 20 draw calls and it slows down with many humans on the screen, even with my fast computer and graphics card. I have tried using GeometryBatchFactory.optimize on the humans. They only use one material so the draw calls go down, everything speeds up, but I lose the ability to animate my humans.



I was hoping optimize would work on animated models with submeshes but it doesn’t seem to. I tried taking the animation control out of the old node and putting it in the optimized node but I can’t seem to get it working. All I need is to put the submeshes into one mesh so it can draw it in one go. I don’t need anything complex like joining vertices or altering texture coordinates.



Can anyone help me? Maybe I am missing a method that optimizes animated models. Maybe I messed up moving the animation control. Maybe there is no way to do this in JME yet. I am not sure. I hope someone can help because I don’t want to abandon this project.



Thanks

Here is a bit more information, a picture of 81 business men when optimized but not animated.



http://oi47.tinypic.com/2yz0vb5.jpg



Here is the statistics when they are not optimized.



http://oi49.tinypic.com/k00tfq.jpg



As you can see it makes a big difference.

You just can’t do this. Optimized or batch node = no animation.

Thanks for the reply. I was fearing this. It looks like I will have to use some creative thinking if I am going to solve this problem.

Well ony creative idea would be, to only use one mesh, but store in an additional vertexbuffer wich part of the human it is. (Not sure how to d that in a model programm, but it could be odne programmatically.)



Then give the fragment shader a 1d 1x20 pixel color, and let him get the color relevant for that part of the human. → This could reduce your draw calls to 1 for each human without breaking.



A lighter but not that good solution is to not render all stuff on ditance. like glasses, ect. In your screenshot for the far away humans rendering only the skin color+ the suit color could bring your object count by 10 without being to visible.

@vertex : let back to basic:

If you want 100 meshes with 100 complex diffirent animations, almost CPU cant stand that amount of computing everyframe.

If you want 100 meshes with the same animation or just a little bit different (just different start time), I guess you heard about “hardware skinning” which is not official supported in JME3 yet!


If you still want 100 meshes with 100 complex animations at the same time, think about it several of times, now:
1) Let's think again about your scene and hide some characters because they just cant appear all at the same time...
2) The FPS decreased because of animation computing not because of the mesh or draw call. So, don't use complex animation (which costa lot of computing) for character that far from the POV, that mean you make some level of details for animation its self. This is not easy, you have to re-write some code (I did too) make a simple version AnimControl.

This is my solution for a scene which I need hundreds of demon running in the field in a battle:
I used hardware skinning, the orginal code belong to @chototsu, which left the forum...
I used animation LOD which re-write the AnimControl, which just appropriate in my specific game and situation
I used another cloneControl to Clone in real-time some demon and put it randomly behind...you know, It does extractly the same animation with his "brother" somewhere in the front ...
The combination of these above technique can make a real stunning scene, that's pretty much if you just new to JME but I guess you get some point :p
1 Like

Thanks for the suggestions guys.



@Empire Phoenix

Good suggestion. I was already exploring something along those lines when I posted. It would make things more awkward, but still doable, and very fast.



@atomix

I don’t intend to have anywhere near 100 people on the screen. The camera angle that I intend to use won’t allow the horizon to be seen so I will probably never have more than a few on screen at any time, but I do like to optimize things as much as possible. My model only uses 360 triangles, even with extra triangles to provide millions of clothing combinations, and few bones and a maximum of 2 bones per vertex.

but I do like to optimize things as much as possible

in my opinion, animations are pretty hard to optimize, in term "of being reduced to run faster"...
I think you should try like Phoenix said, "bake" the animations and put it into shader's texture, that also a technique of "hardware skinning" but in your case is not really the solution.

As I did the same technique for face animation, the number of triangles to take the advantage of the technique should be above 2000! In the lower number, nothing really nice happen (no FPS gain, also super hard to control)

In the case you model just 360 triangles, and few bones, why you need that much of optimize?

The only optimization I was asking about was bringing the draw calls from above 20 per human down to 1 per human. I want my game to work on slower computers so that particular optimization is important. I am going to use a vertex buffer to tell what part of the human it is, like EP suggested. I will be changing vertex colors once when the human is created. I agree that no more optimization or special shaders will be necessary.

Actually you could just use vertex coloring directly if I think about it, since you dont use textures that would work, and you dont need to write any shaders or so at all.

Yes, thats the plan.