increasing performance drawing thousands of cubes
Posted: Wed Jan 08, 2020 10:00 pm
So I tried drawing 4000 cubes in irrlicht using addCubeSceneNode and drawAll and it reduced the performance by a lot from lik 100 fps to 20 - 40
I tried googling it and it was pretty hard to find stuff but i found something stating that every meshbuffer would have it's own draw call and i could
improve the performance by combining the everything into one meshbuffer couldn't really find anything explaining how to do it
but after a lot of trial and error i managed to get it to work like this:
unfortunately this made the performance a lot worse even with only 400 cubes it was significantly worse only like 10 to 20 fps
I don't know if i did something wrong or if this is just stupid and using the previous method was the best performance i can expect.
I don't really know what i'm doing since im still not that familiar with the engine or 3d rendering any help would be appreciated.
sorry for any typos my screen is beyond repair so i can't really always see what im typing.
I tried googling it and it was pretty hard to find stuff but i found something stating that every meshbuffer would have it's own draw call and i could
improve the performance by combining the everything into one meshbuffer couldn't really find anything explaining how to do it
but after a lot of trial and error i managed to get it to work like this:
Code: Select all
irr::scene::SMesh* tmesh2 = new irr::scene::SMesh();
IMeshSceneNode* node2 = smgr_->addCubeSceneNode();
SMeshBuffer* newMeshBuffer2 = new SMeshBuffer();
for (size_t i = 0; i < meshBufferCount; i++)
{
SMeshBuffer* meshBuffer = (SMeshBuffer*)node2->getMesh()->getMeshBuffer(i);
for (size_t k = 0; k < 400; k++)
{
for (size_t j = 0; j < meshBuffer->getVertexCount(); j++)
{
S3DVertex& vertex = meshBuffer->Vertices[j];
vertex.Pos = vector3df(vertex.Pos.X + 100, vertex.Pos.Y + 10, vertex.Pos.Z + 10);
}
newMeshBuffer2->append(meshBuffer->getVertices(), meshBuffer->getVertexCount(), meshBuffer->getIndices(), meshBuffer->getIndexCount());
tmesh2->addMeshBuffer(newMeshBuffer2);
}
}
IMeshSceneNode* newNode2 = smgr_->addMeshSceneNode(tmesh2);
newNode2->setMaterialFlag(EMF_LIGHTING, false);
newNode2->setMaterialTexture(0, driver_->getTexture("resources/hoplitecard.jpg"));
node2->remove();
I don't know if i did something wrong or if this is just stupid and using the previous method was the best performance i can expect.
I don't really know what i'm doing since im still not that familiar with the engine or 3d rendering any help would be appreciated.
sorry for any typos my screen is beyond repair so i can't really always see what im typing.