0 votes

I was wondering if anyone knew the difference in performance between using say 8 large meshes vs using many multimeshs to make up the same geometry.

Say for example the landscape in minecraft or cubeworld. A voxel based geometry. Consider the options of a large mesh representing a chunk or many a multimesh of a square face used to make up the same geometry of the larger mesh. Which would have better performance? if any.
Also I assume either way for collisionshapes: having collisionshapes the size of the chunk would work better, as opposed to many collision shapes (static of course)
But I'm especially curious about the rendering of the world.
I know theres the C++ voxel that does a good job of voxel terrain however would be interested in getting it to work (nicely) through GDscript.

Thanks :)

in Engine by (14 points)
recategorized by

1 Answer

+1 vote

For a world like Minecraft where the large majority of cubes are static, in the few tests I've done, batched cubes will beat multimeshes... IF their hidden faces are culled, and even more if greedy meshing is applied to merge common faces.

Having many Multimeshes on screen will have trouble hiding occluded faces and cause overdraw. Vertex count will also be higher.

The advantage of Multimesh however, is being able to modify or move every cube much faster, because on the other hand, a batched mesh will need to be entirely rebuilt (at least in Godot). It's also easier to modify with a script, while a batched mesh will require a fast language like C++ or a compute shader.

In both cases, it's also a good idea to chunk the world at least by 32x32x32 to take advantage of frustum culling.

One thing I didnt try however: using multimesh, but exploiting the Color component to store which side to occlude. Then in the vertex shader, discard vertices belonging to a side of the mesh. Sort of a hybrid approach. Random thought tho :p

by (27,593 points)

How would you occlude a face of a Mesh that is a part of a MultiMesh? From what I know (and very little at that), a MultiMesh will only show one variant of a single Mesh in various positions depending on how you configure the MultiMesh. So if the Mesh being shown by the MultiMesh is a cube, it will render all six sides of the cube. Is there some way to change that, so only some cubes in the MultiMesh will have all six sides, while others have a different number of faces shown?

Honestly I have no idea if this is a good approach. But if you want to try that, read about shaders (here: https://docs.godotengine.org/en/stable/tutorials/shading/index.html, or here https://thebookofshaders.com/, or any good tutorial).
The way you can hide cube faces with a shader is by exploiting the fact each side of a cube uses independent vertices. They are not actually shared, because each face has different normals. So if all 4 vertices of a face are discarded, that specific face will disappear.
"Discarding" a vertex can be done by either giving it a NaN position (which is a hack). But it can also be done by forcing it to a position of zero, which will make all triangles of the face degenerate. Their edges will be all in one place, so they won't produce any pixel to draw.
In multimeshes, each instance can have extra data, not just a transform. You can add custom data per instance, as a ""Color"" (https://docs.godotengine.org/en/stable/classes/class_multimesh.html#enum-multimesh-customdataformat). This custom data is of course not necessarily color. It can be exploited to hold the information about which sides should be discarded. So somehow, in the vertex shader, you can check INSTANCE_CUSTOM, check the vertex normal, and do the discarding based on that (I dont have code for that cuz I'm litterally imagining the technique as I write, and it's late xD).
Of course, the vertex shader cannot know by itself its neighbor cubes. So in this approach you still need to figure out on the CPU which sides of each cube should be occluded. The point is that instead of generating a mesh vertex by vertex using GDScript, you generate instances and simply tell them how they should look like.

It all depends on what you really want to do though. For minecraft terrain, batched greedy cubes would do the job really well.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.