Why do I get lower FPS with fewer meshes?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
howtoinstall
Posts: 3
Joined: Tue Aug 20, 2019 4:02 pm

Why do I get lower FPS with fewer meshes?

Post by howtoinstall »

I am creating a voxel game (everything is a 10x10x10 cube) but realized quickly that there is no good way to apply a specific texture on ONE side of a cube mesh created by

Code: Select all

sceneManager->addCubeSceneNode(x);
so what I did instead was create a cube out of 6 different plane meshes created by

Code: Select all

 
irr::scene::IMesh* plane= geomentryCreator->createPlaneMesh(irr::core::dimension2d<irr::f32>(1, 1), irr::core::dimension2d<irr::u32>(10, 10));
sceneManager->addMeshSceneNode(plane);
// I create 5 more planes below in my code and rotate them correctly
 
Before the change to plane meshes I got an average of 160 FPS with 100 x 100 cubes = 10 000 cubes (10K meshes). Now when I create 40 x 40 cubes using planes = 9 600 faces ( 9.6K Meshes) I get about 4 FPS. I optimized the cube rendering by removing sides that are directly in contact with other meshes, reducing the number of sides to about 3 200, then I further optimized this by removing plane meshes that are below the player, since they are not visible, reducing the number of plane meshes to 1 600. With about 1 600 plane meshes loaded instead of 10 000 cube meshes I get 40 FPS.

Why do I get 40 FPS when loading about 1 600 plane meshes but I get 160 FPS when loading in 10 000 cube meshes?

I am on Windows 8 using Irrlicht 1.8.3

Edit: I remove the plane meshes that are not visible since they are in direct contact with another wall (plane mesh) from another cube by doing this:

Code: Select all

 
planeMesh->remove();
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Why do I get lower FPS with fewer meshes?

Post by CuteAlien »

Can you show full code? But basically - if you try to do something like Minecraft search a bit around in the forum. There was some library to help doing that I think.
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
howtoinstall
Posts: 3
Joined: Tue Aug 20, 2019 4:02 pm

Re: Why do I get lower FPS with fewer meshes?

Post by howtoinstall »

The full code is like 2 000+ lines of code, so I cannot. There are threads on minecraft but everything is very vague about how to do stuff, the answers AND questions are very diffuse and complex.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Why do I get lower FPS with fewer meshes?

Post by CuteAlien »

I was thinking about polxvox: http://www.volumesoffun.com/polyvox-about/
But I never worked with it myself, so not sure how well it integrates with Irrlicht.

And I'm not sure how I can help you if I don't have code to reproduce the problem. If you are on Windows you can run "Very Sleepy" (http://www.codersnotes.com/sleepy/) on it which is likely the easiest profiler to use. It should show you were the time gets lost. To get best results compile as release with optimization, but with debug information enabled.
On Linux there's also some profiling tools, the simplest probably using valgrind with callgrind.
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
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Why do I get lower FPS with fewer meshes?

Post by devsh »

Its because now you're switching between 6 different textures and before you only had 1.

Most reasonably optimized games keep the number of meshes < 2000

You should merge all your mesh data that uses the same texture together, if you can use a texture atlas then you can have all data in one mesh.
Post Reply