Mesh Combiner

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Mesh Combiner

Post 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.

Screenshots:

Using scene nodes:

Image

Using mesh combiner:
Image

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:
Image

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.
Last edited by Lonesome Ducky on Wed Oct 12, 2011 8:26 pm, edited 2 times in total.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Wow, that's really nice and pretty well thought out.
I'm gonna try it soon. :) Thanks.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post 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
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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.
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

wow great performance boost! i'll sure be using this in my game. 8)
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post 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!
Image
Image
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

yeah with this thing irrlicht will be really LIGHTNING FAST
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post 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.
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

Post by pc0de »

Good work Lonesome Ducky and thanks for doing this!
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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:

Image

Mesh Combiner:
Image

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.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post 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.
Image
Image
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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!
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

Post 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();
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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.
Post Reply