combining nodes to minimize drawcalls

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
Combum
Posts: 9
Joined: Wed Jul 29, 2015 11:33 pm

combining nodes to minimize drawcalls

Post by Combum »

Hello People, I have a question about nodes and how to combine them.

Code: Select all

void World::newWorld(bool moar, scene::ICameraSceneNode* camera, ISceneManager* smgr, IVideoDriver* driver)
{
    vector3df mappos(0,0,0);
 
    IMeshSceneNode* cube[1000];
 
    ITriangleSelector* sel;
 
    IMetaTriangleSelector* meta = smgr->createMetaTriangleSelector();
 
    for (int i = 0; moar; ++i)
    {
        cube[i] = smgr->addCubeSceneNode(100);
        cube[i]->setPosition(mappos);
        cube[i]->setMaterialTexture(0, driver->getTexture("../../../irrlicht-1.8.1/media/wall.jpg"));
        /*smgr->getMeshManipulator()->setVertexColors(cube[i]->getMesh(), SColor(0, 255, 0, 255));*/
        cube[i]->setMaterialFlag(EMF_LIGHTING, false);
 
        scene::ITriangleSelector* selector = smgr->createTriangleSelectorFromBoundingBox(cube[i]);
        
        cube[i]->setTriangleSelector(selector);
        selector->drop();               
 
        meta->addTriangleSelector(cube[i]->getTriangleSelector());
 
        ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(meta, camera, vector3df(30, 50, 30), vector3df(0, -20, 0), vector3df(0, 20, 0));
        camera->addAnimator(anim);
        anim->drop();
        
        //dungeon generator
        if (i < 50)mappos.X += 100;
        else
        moar = false;
    }
}
So basically I have two questions about this:

1. How can I minimize the drawcalls? When I try to draw 250 cubes (1500 faces) I only get 10 fps. Thats a bit too low, I think.
And I know what I am doing wrong, I have to many drawcalls. I plan to combine all cube nodes and then have an octree.
So how can I do that? Please give me an explanation about that.(or a link to a tutorial)

2. I want the floor to be one cube to optimize the game,but how can I change its dimensions? when I want a 1000u long cube, its automaticly 1000 in depth too. Please help :)

Any other Ideas to optimize this?
Thanks for helping :)
Necris
Posts: 8
Joined: Tue Sep 17, 2013 4:31 pm

Re: combining nodes to minimize drawcalls

Post by Necris »

Are you sure, that you are using an OpenGL or an Direct3d Renderer? I had the same Problem, but in my case it was the softwarerenderer, which is not capable of drawing more than a few cubes. I have 2500 cubes and around 100 FPS with OpenGL and 300 FPS with Direct3D.

For the floor you could use the MeshCombiner from this thread: http://irrlicht.sourceforge.net/forum/v ... hp?t=39598
Combum
Posts: 9
Joined: Wed Jul 29, 2015 11:33 pm

Re: combining nodes to minimize drawcalls

Post by Combum »

yes I am using

Code: Select all

IrrlichtDevice *device =
        createDevice(EDT_OPENGL,dimension2d<u32>(1920, 1080), 32,false, false, true, &receiver);
and have no performance problems in other games

Additional Info:

I am using

VS 2013
Irrlicht 1.8.1
Win8.1
GTX 970

My RenderLoop:

Code: Select all

while (device->run())
        {
            if (receiver.IsKeyDown(irr::KEY_ESCAPE))
            {
                device->drop();
                return EXIT_SUCCESS;
            }
 
            driver->beginScene(true, true, SColor(255, 0, 0, 0));
            smgr->drawAll();
            //Draw crosshair
            driver->draw2DRectangle(SColor(255, 33, 0, 127), rect<s32>(1920 / 2 - 2, 1080 / 2 - 2, 1920 / 2 + 4, 1080 / 2 + 4)); //above 
            guienv->drawAll();
            driver->endScene();
 
            int fps = driver->getFPS();
 
            if (lastFPS != fps)
            {
                core::stringw tmp(L"MyGame [");
                tmp += driver->getName();
                tmp += L"] fps: ";
                tmp += fps;
 
                device->setWindowCaption(tmp.c_str());
                lastFPS = fps;
            }
        }
 
        device->drop();
Didnt you mean I could use the Meshcombiner to optimize my fps instead of changing dimensions of a cube?
Because I didnt found a function to do that yet.
Thanks for helping :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: combining nodes to minimize drawcalls

Post by CuteAlien »

irrExt has 2 implementations to merge meshes: https://sourceforge.net/p/irrext/code/H ... ene/IMesh/

You can scale nodes (like cubes) only along one axis with setScale and setting corresponding axis to another value than 1.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: combining nodes to minimize drawcalls

Post by hendu »

Also see createPlaneMesh for the floor.
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: combining nodes to minimize drawcalls

Post by Foaly »

Your problem is not the draw calls.
On your graphics card, you can have many more draw calls per frame.

Your problem is the collision. If you remove the collision response animator, your framerate will be much higher.
The collisions in Irrlicht are not meant to be used for serious stuff and they aren't optimized.
You can either use a real physics engine for collision (like Bullet).

If you don't have to many cubes, you can also try merging them to one mesh and then create an octree scene node with an octree triangle selector, which will also speed up the collision detection.
Combum
Posts: 9
Joined: Wed Jul 29, 2015 11:33 pm

Re: combining nodes to minimize drawcalls

Post by Combum »

Okay, thanks for helping, I will try out those things. :)
Post Reply