Mesh Combiner
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Mesh Combiner
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:
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):
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.
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:
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):
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.
Last edited by Lonesome Ducky on Wed Oct 12, 2011 8:26 pm, edited 2 times in total.
This, I'm linking everyone who complains about bad performance with 1000 draw calls to this thread from now onBate wrote:Wow, that's really nice and pretty well thought out.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
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.
wow great performance boost! i'll sure be using this in my game.
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
yeah with this thing irrlicht will be really LIGHTNING FAST
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
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.
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
To test out rotation+translation and correction of normals, I made a block of 300 dwarves, ninjas, and chess pieces
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 But both directx versions and opengl run at roughly the same speed on my computer, so the comparison should still be valid.
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 But both directx versions and opengl run at roughly the same speed on my computer, so the comparison should still be valid.
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.
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.
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
-
- Posts: 21
- Joined: Wed May 20, 2009 8:17 pm
- Location: Qc, Canada
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
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();
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm