Page 1 of 9

Mesh Combiner

PostPosted: Mon Aug 16, 2010 11:04 pm
by Lonesome Ducky
I thought of putting this code snippets, but at more than 700 lines of code, I think this is a better spot :)

This is a mesh combiner I made. Not only does it combine the meshes, but it combines their textures so the whole group can be drawn in one call. This speeds up drawing immensely in some cases, and I have the code and a test case included.

Things to note: It only support S3DVertex as of yet, but I plan on adding the other two types soon. It also does not support animation, and that will come later if ever. Also, as with any use of a texture atlas TILING TEXTURES ARE BROKEN BY THIS.


Using scene nodes:


Using mesh combiner:

Keep in mind that the tiles have separate textures and they are being combined by the mesh combiner. It even corrects the uv's!

Two help against bleeding of separate textures in mipmaps, the mesh combiner gives two methods. One, is too expand the texture according to the padding amount (this is a texture atlas for the tiles created by the class): Image

The second method is to tile it according to the texture padding:

This eliminates most (but not all) problems associated with mipmapping.

Comparison with 100x100 tiles with 4 textures:
Scene nodes: 41 fps
Mesh Combiner: 796 fps

The code and a comparison program can be downloaded here.
EDIT: Update link

Combining mesh scene nodes applies their transformations to the mesh and then combines it. It also corrects the normals and uv's so it looks exactly the same as the separate meshes. Also, feel free to add as many meshes as you need. If the 16 bit index limit is reached, a new mesh buffer is added, so you can add as much as you like.

Please tell me what you think and about any problems you encounter.

PostPosted: Mon Aug 16, 2010 11:26 pm
by Bate
Wow, that's really nice and pretty well thought out.
I'm gonna try it soon. :) Thanks.

PostPosted: Tue Aug 17, 2010 12:37 am
by BlindSide
Bate wrote:Wow, that's really nice and pretty well thought out.

This, I'm linking everyone who complains about bad performance with 1000 draw calls to this thread from now on :P

PostPosted: Tue Aug 17, 2010 1:50 am
by Lonesome Ducky
Thanks guys. I'm also thinking about adding a function that only combines textures, then fixes the coordinates of any meshes using one of those textures. This way, you could get speedup in any program on both static and animated meshes. It's not as fast as rendering all geometry in one go, but it should save the time it takes to switch textures.

PostPosted: Tue Aug 17, 2010 6:01 am
by Virion
wow great performance boost! i'll sure be using this in my game. 8)

PostPosted: Tue Aug 17, 2010 7:20 am
by Lonesome Ducky
Virion wrote:wow great performance boost! i'll sure be using this in my game. 8)
That's good to hear :) Just note though, the most speed is gained when tons of meshes are combined. If only a few are, the speedup isn't huge. But in this cases with 10,000 nodes, the speedup was enormous.

PostPosted: Tue Aug 17, 2010 11:24 am
by B@z
omg it really has great performance speedup!
w/o using it i got 15 fps, with using i got 1028 O.o this IS really something.
ill try to integrate it on my previous project lets see how much will it be better :3

thanks for sharing it!

PostPosted: Tue Aug 17, 2010 11:47 am
by Virion
yeah with this thing irrlicht will be really LIGHTNING FAST

PostPosted: Tue Aug 17, 2010 12:05 pm
by slavik262
This is an excellent piece of work. Nicely done. I should really post my texture atlas generator soon - it's like the second part of your work (it combines textures), but the mesh implementation is left up to you. It works really nicely with tiled textures, and it uses a binary tree algorithm to pack the atlas in as little space as possible.

PostPosted: Tue Aug 17, 2010 1:23 pm
by pc0de
Good work Lonesome Ducky and thanks for doing this!

PostPosted: Tue Aug 17, 2010 3:17 pm
by Lonesome Ducky
To test out rotation+translation and correction of normals, I made a block of 300 dwarves, ninjas, and chess pieces :lol:

Scene Nodes:


Mesh Combiner:

25 fps vs 176. Not the same magnitude of speed up as the first, but this is because it using fewer nodes. And, as you can see, transformation is applied correctly and normals are also recalculated correctly.

EDIT: If you look closely at the windows it seems I keep picking the wrong renders :lol: But both directx versions and opengl run at roughly the same speed on my computer, so the comparison should still be valid.

PostPosted: Tue Aug 17, 2010 7:39 pm
by B@z
i catched an error.
there was a warning that 2 default constructor declared. didnt know why but i found that u give default parameters for the 3 parameter constructor. So if i use: new CMeshCombiner() <- then it wont know which constructor should it use ^^

And i tried it out in my project, but didnt give me performance boost, so i guess its a different problem in my game.

PostPosted: Tue Aug 17, 2010 8:13 pm
by Lonesome Ducky
Yeah, it's only really helpful when you have 1000+ nodes. As for the default constructors, I must have overlooked it, thanks!

PostPosted: Tue Aug 24, 2010 9:06 pm
by Alucard344
First of all, i want to say that this is very nice. it really speeds up everything. but i am getting a problem. what i want to do is draw a lot of cube. With a millions of them it crash. i am not sure why..
800 000 cube is fine and fps is very good.
any idea why it would crash at 1 million?

in your example project i have used this instead of your mesh

Code: Select all
IMeshSceneNode* tile = smgr->addCubeSceneNode();

PostPosted: Wed Aug 25, 2010 2:58 am
by Lonesome Ducky
It's quite possible that irrlicht itself cannot handle that many scene nodes. Or it may be that the program runs out of memory. If you could, please send me your code through a pm or something and I'll try to help more.