drawing optmization?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Stauricus
Posts: 20
Joined: Mon Jun 25, 2012 10:12 pm
Location: Uberlandia, Brazil

drawing optmization?

Post by Stauricus »

hello everybody.

i'm trying to make a simple city generator in Irrlicht. it just make random blocks and streets and puts random buildings in it. now that it's starting to work, i've come across a problem: how to optimize the drawing?

i've made some tests on polycount. the texture and UV is the same in all of them.
in the first and second tests, only 212 nodes. and in the third and fourth, 1908 nodes.

1st- 212nodes * 12tris = 2544 tris. runs at 50fps.with octree, 48~51fps.
2nd-212nodes * 2352tris = 498624 tris. runs at 28fps. with octree, 20fps.
3rd- 1908nodes * 12 tris = 22896 tris. runs at 15~16fps. with octree, same thing.
4th- 1908nodes * 2352 tris = 4487616 tris. runs at 4fps. with octree, 3fps.

my question is why the 3rd test, which have 475728 tris less than the 2nd test, runs at a so low fps? simply adding sceneNodes cause this performance loss? each building is a new node, although the mesh is loaded only once.

here goes a screenshot of what its looking like.
Image

i don't need 2352tris in each building, but something near 1000 would be fantastic. so, i need help on how to optimize the performance. is there any tricks to do it that i'm missing?

any suggestions are really apreciated. thanks in advance :mrgreen:
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: drawing optmization?

Post by serengeor »

More nodes means there will be more draw calls which should be kept low. If static objects share materials and textures it would be ideal to batch them into a single object.
There were lot's of questions like this before, if you need more information search through those.
Working on game: Marrbles (Currently stopped).
Stauricus
Posts: 20
Joined: Mon Jun 25, 2012 10:12 pm
Location: Uberlandia, Brazil

Re: drawing optmization?

Post by Stauricus »

a single object? but i want the program to check which building individually is colliding with a mouse ray. is that possible to be made if i batch everything in a single object?

EDIT: oh sorry, i found a clue here:
http://irrlicht.sourceforge.net/forum/v ... es#p279306
thanks :wink:
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: drawing optmization?

Post by serengeor »

Stauricus wrote:a single object? but i want the program to check which building individually is colliding with a mouse ray. is that possible to be made if i batch everything in a single object?
Doesn't have to be a single object. But object count should be kept as minimal as possible.
And you can use different objects for physics/collision than graphics (if possible of course).
Working on game: Marrbles (Currently stopped).
Stauricus
Posts: 20
Joined: Mon Jun 25, 2012 10:12 pm
Location: Uberlandia, Brazil

Re: drawing optmization?

Post by Stauricus »

ok, got it. but sorry, i'm not being able to do it :?
i've made a single node

Code: Select all

irr::scene::IMeshSceneNode* map_node;
, but how to add meshes to it?
the only functions i found are for adding sceneNodes, but this will not improve anything...
also, should i use meshBuffers to do it? because my models have a single texture UV mapped.

EDIT: and although i'll put many meshes in a single big one, is it possible to keep individual animations (or atleast animations at all)?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: drawing optmization?

Post by serengeor »

Stauricus wrote:ok, got it. but sorry, i'm not being able to do it
i've made a single node
CPP CODE: SELECT ALL
irr::scene::IMeshSceneNode* map_node;
, but how to add meshes to it?
You add as much geometry as possible to single meshbuffer, this way you will only have to make draw calls for one/few meshbuffers. Search for mesh batching for more info.
Stauricus wrote: EDIT: and although i'll put many meshes in a single big one, is it possible to keep individual animations (or atleast animations at all)?
Animated objects should probably be instanced. But I wouldn't bother to do that unless you also have lots of them.
Working on game: Marrbles (Currently stopped).
Stauricus
Posts: 20
Joined: Mon Jun 25, 2012 10:12 pm
Location: Uberlandia, Brazil

Re: drawing optmization?

Post by Stauricus »

well, i coudn't find how to instance objects in irrlicht... do i have to do it directly through opengl?
also, i found CBatchingMesh and MeshCombiner here in the forum. but i wasn't able to understand how it's done... to do it manually do i have to create meshbuffer, then put it together, then create meshes and add it to a node?
i found many and many topics saying to batch meshes in order to get better performance, but none explains how to do it..
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: drawing optmization?

Post by serengeor »

Stauricus wrote:well, i coudn't find how to instance objects in irrlicht... do i have to do it directly through opengl?
I don't think it's in irrlicht core yet, but afaik it's somewhere on forums too. (I think devsh wrote a patch :roll: )
Stauricus wrote:also, i found CBatchingMesh and MeshCombiner here in the forum. but i wasn't able to understand how it's done... to do it manually do i have to create meshbuffer, then put it together, then create meshes and add it to a node?
i found many and many topics saying to batch meshes in order to get better performance, but none explains how to do it..
There's not much to explain really, all you have to do is put the meshes into single meshbuffer. To do that correctly you will need to understand how to make indices correct and transform the vertices.
Try to do this with for example two transformed cube nodes or something similar.
Working on game: Marrbles (Currently stopped).
Stauricus
Posts: 20
Joined: Mon Jun 25, 2012 10:12 pm
Location: Uberlandia, Brazil

Re: drawing optmization?

Post by Stauricus »

well, i'm trying to do it like this:

Code: Select all

irr::scene::IMesh* test_building = smgr->getMesh("building1.obj");
irr::scene::SMesh* test_map;
 
test_map->addMeshBuffer(test_building->getMeshBuffer(irr::u32(0)));
but it get a segfault error at the last line. geez this thing i consufing :P
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: drawing optmization?

Post by serengeor »

Stauricus wrote:well, i'm trying to do it like this:

Code: Select all

irr::scene::IMesh* test_building = smgr->getMesh("building1.obj");
irr::scene::SMesh* test_map;
 
test_map->addMeshBuffer(test_building->getMeshBuffer(irr::u32(0)));
but it get a segfault error at the last line. geez this thing i consufing :P
Uhm, it will be since I see you don't really have good knowledge of c++.

Code: Select all

irr::scene::SMesh* test_map;
You did not create any object, so of course you can't use it.
Working on game: Marrbles (Currently stopped).
Stauricus
Posts: 20
Joined: Mon Jun 25, 2012 10:12 pm
Location: Uberlandia, Brazil

Re: drawing optmization?

Post by Stauricus »

oops, you're right. i forgot to change that.

sure i don't have a good c++ knowledge. that's why i'm still in Irrlicht Begginer's forum AND C++ Begginer's forum.
thanks for the help :)
Post Reply