Need an Irrlicht Tutorial for performance best optimization

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
Tedi
Posts: 18
Joined: Sun Nov 27, 2011 3:42 pm
Contact:

Need an Irrlicht Tutorial for performance best optimization

Post by Tedi »

Hello,

I am developing Real Library. This is basically an indie game engine.

Every entity is composed of a graphics model and a physics model. The physics model determines the position and rotation and the graphics model follows it.

I load graphic models with two possible ways. And each model is created in its own Node.

1. Static( Environment, Buildings etc ) by using:

Code: Select all

 
            // Useful pointers to graphics device.
            irr::IrrlichtDevice* pGraphicsDevice = GRAPHICSDEVICE.getGraphicsDevice();
            irr::scene::ISceneManager* pSceneManager = pGraphicsDevice->getSceneManager();
 
            // Load mesh.
            irr::scene::IAnimatedMesh* pTempMesh = pSceneManager->getMesh( mesh.GetString() );
            m_node = 0;
            if( pTempMesh )
                m_node = pSceneManager->addOctreeSceneNode( pTempMesh->getMesh(0), 0, -1, 1024 );
 
2. Dynamic (Characters, moving objects, animals, NPCs etc ) by using:

Code: Select all

 
            // Useful pointers to graphics device.
            irr::IrrlichtDevice* pGraphicsDevice = GRAPHICSDEVICE.getGraphicsDevice();
            irr::video::IVideoDriver* pVideoDriver = pGraphicsDevice->getVideoDriver();
            irr::scene::ISceneManager* pSceneManager = pGraphicsDevice->getSceneManager();
 
            // Load mesh.
            irr::scene::IAnimatedMesh* pTempMesh = pSceneManager->getMesh( mesh.GetString() );
            m_node = 0;
            if( pTempMesh )
                m_node = pSceneManager->addAnimatedMeshSceneNode( pTempMesh );
 
The problem is that I get really low FPS when in the miiddle of a crowned environment with lots of geometry around me although I do these in my code for both kinds of models.

Code: Select all

 
            m_node->setMaterialFlag( irr::video::EMF_GOURAUD_SHADING, true );
            m_node->setMaterialFlag( irr::video::EMF_LIGHTING, false );
            m_node->setMaterialFlag( irr::video::EMF_ZBUFFER, true );
            m_node->setMaterialFlag( irr::video::EMF_ZWRITE_ENABLE, true );
            m_node->setMaterialFlag( irr::video::EMF_BACK_FACE_CULLING, true );
            m_node->setMaterialFlag( irr::video::EMF_FRONT_FACE_CULLING, false );
            m_node->setMaterialFlag( irr::video::EMF_ANISOTROPIC_FILTER, true );
            m_node->setMaterialFlag( irr::video::EMF_FOG_ENABLE, false );
            m_node->setMaterialFlag( irr::video::EMF_NORMALIZE_NORMALS, true );
            m_node->setMaterialFlag( irr::video::EMF_TEXTURE_WRAP, false );
            m_node->setMaterialFlag( irr::video::EMF_ANTI_ALIASING, true );
            m_node->setMaterialFlag( irr::video::EMF_COLOR_MASK, true );
            m_node->setMaterialFlag( irr::video::EMF_COLOR_MATERIAL, false );
 
            m_node->setAutomaticCulling( irr::scene::EAC_OCC_QUERY );
 

What are the best practises for getting the best FPS?
Is there any tutorials on that?


In a search in the forum I saw many similar beginner's problems but have found no answer that actually got to understand.
I think a tutorial explaining all these should be included with Irrlicht. I would need so much one.

Thanks!!!!! :D
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by greenya »

In general when optimizing graphics performance you need to draw more in less calls to the driver.

The static should be batched into meshbuffers, so single call draws a lot of triangles at once. This is not how you store the game level, this is something that should be done at loading time or generated each time you save scene in editor. It is easy for us to operate with nodes, because each one is distinct object and we can move, rotate and scale it, we can assign materials to it. But the drawing of 5000+ nodes will end up to low performance no matter how simple they are. Calling 5000 times per frame (!) all the sequence of drawing one node is a lot -- the rendering thread will be busy, but even 5 years old video card chip will be loaded on less than 5% in that scenario. Each node may contain meshbuffers and each one has own material, setting a material is not cheap; if drawing of your scene requires to set material about 10000 times - no matter what, performance will be very bad. The same goes to transformation matrix, each node has it; setting transformation matrix is also pretty costly and should be optimized.

To start optimizing you need to understand where is the bottleneck first. In most cases it is number of calls to video driver.
For example, for you to compare how draw call number can hit the performance you can try to draw 100k triangles using draw3DTrinagle() using loop and draw a model or a mesh buffer with 100kk triangles. The difference will be very huge.
Tedi
Posts: 18
Joined: Sun Nov 27, 2011 3:42 pm
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by Tedi »

I thought that camera had frustrum culling by default but I did this.

Code: Select all

 
m_cameraNode->setFarValue( 4800.0f );
m_cameraNode->setNearValue( 0.01f );
m_cameraNode->setAutomaticCulling( irr::scene::EAC_OCC_QUERY );
 
Last edited by Tedi on Thu Mar 14, 2013 3:35 pm, edited 1 time in total.
Tedi
Posts: 18
Joined: Sun Nov 27, 2011 3:42 pm
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by Tedi »

So my goal should be:

1. Draw more in less calls to the driver.
This is something general. And optimize it in my programming? I started studing OpenGl. I guess it has something to do with rendering pipeline. This is tricky for me.

2. Batch static meshes batched into meshbuffers, generated each time you save scene in editor.
You mean in 3DS Studio Max? I need to study about meshbuffers. Will post when I have.

3. Μinimize Materials
I get it. Less materials more performance. I will try have a single big image instead of many small.

4. Avoid setting transformation matrixes.
I do not touch transformation matrices. Most of the times I only position and rotate 5 objects maximum in my scene using rotate and position methods.

5. Find where is the bottleneck first. In most cases it is number of calls to video driver.
I think I need culling methods.

I am a noob in Graphics rendering but this is what I got so far. Anybody else that could suggest or give feedback?
I am currently studing OpenGl and advanced Irrlicht.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by greenya »

Tedi wrote:You mean in 3DS Studio Max?
Not necessary that one. The level editor has aim to allow easy editing game level elements. And the game has aim to render game level as fast as possible.
Tedi wrote:I get it. Less materials more performance. I will try have a single big image instead of many small.
The aim is to change material less times. You can have only to materials and switch between then before rendering every polygon and this will be very very slow. And yes, if it fits your implementation, then one big image better for performance than a lot smaller, since you don't need to change material.
Tedi wrote:I do not touch transformation matrices. Most of the times I only position and rotate 5 objects maximum in my scene using rotate and position methods.
Every single node has own transformation matrix, and it is set each time its being drawn.
Tedi wrote:5. Find where is the bottleneck first. In most cases it is number of calls to video driver.
I think I need culling methods.
In special cases checking for culling some geometry can take more time than just to draw it straight. You should check you cases and test each one.
Tedi wrote:I am currently studing OpenGl and advanced Irrlicht.
I do recommend to study some OpenGL, it will give better overall understanding graphics rendering stuff.
Tedi
Posts: 18
Joined: Sun Nov 27, 2011 3:42 pm
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by Tedi »

What is the difference between:
  • EAC_OFF
  • EAC_BOX
  • EAC_FRUSTUM_BOX
  • EAC_FRUSTUM_SPHERE
  • EAC_OCC_QUERY
I have 300 fps but when I spawn 20 trees I get 20 fps. FPS gets back at 300 when the camera looks away of the trees.

Also what version of OpenGl does Irrlicht use?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by hendu »

Then your trees are too heavy, heh.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by hybrid »

Irrlicht uses the version of OpenGL you provide. OpenGL apps are compatible with OGL 1.1 up to 4.x. It only depends on which features are used. But that's not the point here.
If you have 20 trees in sight and want to render them at this high detail, you cannot do better with any culling strategy, as culing would mean you don't render some trees. If you want to allow a dynamic reduction of trees or detail, you can think about culling, but even better about level of detail. Provide a number of different tree meshes which you switch through based on the distance of the trees. Also check why your trees have such a huge render time impact. Maybe they are badly designed from the beginning, and you could do much better with a mesh design suited for real-time rendering.
Tedi
Posts: 18
Joined: Sun Nov 27, 2011 3:42 pm
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by Tedi »

Thanks I think I have to code a LOD scene manager here. I will change the code from my first post. By the way could I have done something better. The first post is the way I do it. If I code LOD and design new better trees I will have everything done. Is there anything else? No!!!
Marthog
Posts: 31
Joined: Sun Oct 03, 2010 8:33 pm
Contact:

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by Marthog »

What else than rendering is done in the mainloop?
For example if you load textures and meshes often you could reuse old objects.
Reduce the number of calls of new and delete. These functions are slow and if you set a buffer size before inserting elements, the inserting is much faster.

If you use C++0x or C++11 containers of the stl may be faster, because they use move-operators and e.g. std::unordered_map is normally faster than irr::core::map.
Rust fanboy
MrGuy
Posts: 18
Joined: Mon Oct 29, 2012 11:05 pm

Re: Need an Irrlicht Tutorial for performance best optimizat

Post by MrGuy »

Maybe you could get Hardware isntancing to work somehow. ;)
http://http.developer.nvidia.com/GPUGem ... ter03.html
Post Reply