low fps when create many cubes

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
frc
Posts: 3
Joined: Fri Aug 12, 2011 9:53 pm

low fps when create many cubes

Post by frc »

first, i tried create cubes using addCubeSceneNode:

Code: Select all

 
        // creating block
        ISceneNode * block  = smgr->addCubeSceneNode(
                size, // size
                0, // dad
                id, // id
                pos, // pos
                core::vector3df(0, 0, 0), // rot
                core::vector3df(1.0f, 1.0f, 1.0f) // scale
        );
 
        // settings
        block->setMaterialTexture(0, driver->getTexture("media/block_default.jpg"));
        block->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
        block->setMaterialFlag(video::EMF_LIGHTING, false);
works fine, but when i create more cubes like this, fps down..

Code: Select all

        for(int x=0; x<=100; x++){
                        for(int z=0; z<=100; z++){
                                create_block(driver, smgr, 1, block_id, v3f(x,0,z));
                                block_id++;
                        }
                }

also i tried create the cubes using this, but still same poop:

Code: Select all

 
SMesh* createCubeMesh(const v3f& size)
{
        f32 sX =size.X;
        f32 sY =size.Y;
        f32 sZ =size.Z;
 
    SMeshBuffer* buffer =new SMeshBuffer;
 
    // Create indices
    const u16 u[36] = {   0,2,1,   0,3,2,   1,5,4,   1,2,5,   4,6,7,   4,5,6,
        7,3,0,   7,6,3,   9,5,2,   9,8,5,   0,11,10,   0,10,7};
 
    buffer->Indices.set_used(36);
 
   for (u32 i=0; i<36; ++i)
      buffer->Indices[i] = u[i];
 
   // Create vertices
   SColor clr(255,255,255,255);
 
   buffer->Vertices.reallocate(12);
 
   buffer->Vertices.push_back(S3DVertex(-sX/2,-sY/2,-sZ/2, -1,-1,-1, clr, 0, sX/sY)); //0
   buffer->Vertices.push_back(S3DVertex(sX/2,-sY/2,-sZ/2,  1,-1,-1, clr, sY/sX, sX/sX)); //1
   buffer->Vertices.push_back(S3DVertex(sX/2,sY/2,-sZ/2,  1, 1,-1, clr, sY/sX, 0)); //2
   buffer->Vertices.push_back(S3DVertex(-sX/2,sY/2,-sZ/2, -1, 1,-1, clr, 0, 0)); //3
   buffer->Vertices.push_back(S3DVertex(sX/2,-sY/2,sZ/2,  1,-1, 1, clr, 0,sX/sY )); //4
   buffer->Vertices.push_back(S3DVertex(sX/2,sY/2,sZ/2,  1, 1, 1, clr, 0, 0)); //5
   buffer->Vertices.push_back(S3DVertex(-sX/2,sY/2,sZ/2, -1, 1, 1, clr, sY/sX, 0)); //6
   buffer->Vertices.push_back(S3DVertex(-sX/2,-sY/2,sZ/2, -1,-1, 1, clr, sY/sX, sX/sY)); //7
   buffer->Vertices.push_back(S3DVertex(-sX/2,sY/2,sZ/2, -1, 1, 1, clr, 0, sX/sY)); //8
   buffer->Vertices.push_back(S3DVertex(-sX/2,sY/2,-sZ/2, -1, 1,-1, clr, sY/sX, sX/sY)); //9
   buffer->Vertices.push_back(S3DVertex(sX/2,-sY/2,sZ/2,  1,-1, 1, clr, sY/sX, 0)); //10
   buffer->Vertices.push_back(S3DVertex(sX/2,-sY/2,-sZ/2,  1,-1,-1, clr, 0, 0)); //11
 
   // Recalculate bounding box
   buffer->BoundingBox.reset(0,0,0);
 
   for (u32 i=0; i<12; ++i)
   {
 
      buffer->BoundingBox.addInternalPoint(buffer->Vertices[i].Pos);
   };
 
   SMesh* mesh =new SMesh;
   SMaterial mat;
   buffer->Material =mat;
   mesh->addMeshBuffer(buffer);
   buffer->drop();
 
   mesh->recalculateBoundingBox();
 
    return mesh;
};
 
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: low fps when create many cubes

Post by Radikalizm »

Right now, with both the implementations you tried you're generating a huge amount of draw calls which slow down the rendering progress (1 mesh buffer = 1 draw call)
You should take a look at mesh batching (check this thread: http://irrlicht.sourceforge.net/forum/v ... =6&t=39598 ) to reduce your draw calls

Are you trying to do a minecraft clone?

And by the way, irrlicht already provides its own implementation for creating cubes ;)
frc
Posts: 3
Joined: Fri Aug 12, 2011 9:53 pm

Re: low fps when create many cubes

Post by frc »

yea, i am making something like minecraft, but not all... :)

and i put the mesh combiner to the code, resulted on this:

no mesh combiner:
Image

with mesh combiner:
Image
i dont know yet why the cubes are losing details.. :?

more later i will try use ISceneManager::addCubeSceneNode too...
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: low fps when create many cubes

Post by Radikalizm »

Read through the mesh combiner thread, the issue is probably discussed over there already

And here's a piece of advice: everyone and their mother wants to make a minecraft clone these days because it looks like a simple game; I can very much assure you that minecraft is everything but simple, creating terrain like in minecraft is not a matter of slapping a bunch of cubes together and calling it a day, it requires some decent knowledge of rendering optimizations, memory optimizations, noise functions (I believe minecraft uses perlin noise to generate its worlds), and more

You'll notice very soon that the issue of creating, managing, expanding and storing your entire game world will be very hard to overcome, and I would advise you to start off simpler than that if you don't have the experience or knowledge to pull these things off
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Re: low fps when create many cubes

Post by Lonesome Ducky »

This is a known problem with texture atlases of any kind (which the mesh combiner uses). A few pages into the topic, you can find the update version of the combiner that attempts to fix this. If that doesn't work, you'll have to group the cubes by texture so this doesn't happen.
frc
Posts: 3
Joined: Fri Aug 12, 2011 9:53 pm

Re: low fps when create many cubes

Post by frc »

@Radikalizm
thanks for the advice.. I've thought about it, but i dont need map generation in realtime..
you think it is still too complicated? thank you again.

@Lonesome Ducky
ok, thanks =]
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Re: low fps when create many cubes

Post by Sylence »

frc wrote:dont need map generation in realtime..
It's not the real-time that is difficult but the getting-it-to-work ;)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Granyte
Posts: 849
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: low fps when create many cubes

Post by Granyte »

there is a noise algorithm adapted for irrlicht somewhere in the forum and it would be actualy quite easy to implement in a minecraft type of game at least easiyer then what i'm trying to implement it into XD
Post Reply