How to render many objects with good performance ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bot7

I am working on a game where you can build Lego bricks but its realy lagy because of the little cylinders on top of the brick. How can I optimize it for better performance ? I downloaded demos for Multimeshs but I have no idea how to get a better performance.

:bust_in_silhouette: Reply From: DaddyMonster

For sure, multimesh is a big option for improving performance but you have to do it right, it comes with an overhead so misusing it can easily cost you performance.

You’ve not given a lot of detail on what your project consists of so there’s a limit to how specific my recommendation can be. But, to give you an idea, my game has a comically small spherical world with 10,000 radius, 1.2bn sq units, so I need 45 million objs to make it look remotely full and I get 120 fps with Godot. Plus, I only think about optimisation when I have to, generally it’s much better to think about getting the functionality in place / development done quickly than sweating the optimal solution at every corner. Trick is, you put a few things in place to limit rendering far away and work around that. You only need stuff near the camera. The rest of the world can go to hell.

Ok, so you’ve got lego galore I assume. The drawback with multimesh is that it doesn’t cull objects behind you like an instancemesh will. That means that you’re paying for every obj in the scene, even though the rendering is optimised. Much better not to render than to render optimally. So, loop some multimeshes and make “chunks”, toggling their visibility when they’re not needed and let the engine decide if the remaining one’s are visible. Are you calculating position of every block on the fly? Why not make a “lego terrain generator” and do that beforehand and just loop through the file on startup? Thousand times quicker.

Another amazing option is particles. They don’t have to move, they can just hold objs and you can hand the processing over to your gpu - a device designed to deal with large numbers at once.

Another thing to do is lod, do you need to render a million verts in the far distance? Probably not. Just mark the high def one not visible and put a low poly one in its stead.

I can only talk in general because your question wasn’t specific and optimisation is a very game specific thing. What works for Civ5 doesn’t work for GTA5. The general rule is: pay for what you need and no more. Use the tools Godot gives you optimally and any game can run fine.

I must say, this is a genuinely great advice!

LoneDespair | 2021-02-27 03:35

The LOD part is also quite important. Triangles that are smaller than a pixel on screen have to go through a slower code part on the GPU, which is why they tend to slow things down.

Calinou | 2021-02-27 18:16

Thanks for your great answer. I will try to implement a part of your solutuions.

Bot7 | 2021-03-01 09:47