I’m making a procedural 2d space sim, and I’m generating about 30k voxels for a planet. The look I’m shooting for here is roughly like Terraria, but with these blocks (voxels) acting as planets. I already optimize well by only building what is necessary for the immediate view, but I’m still running into all kinds of problems.
I render one block (voxel) as a quadrilateral, but rotated and modified slightly to bend around the planets radius. 2 triangles per block. If I just use a single mesh and add all the vertices to that mesh, the performance is great.
However, the problem is that these blocks need to be individually textured/styled (think minecraft/terraria, etc). So, I tried making a mesh for each of them, and as you might imagine, the framerate plummeted to like 9 fps.
Then I tried using instanced geometry, where they’re all still their own meshes, but instances of the base mesh for the row that they’re in (because all voxels in one row are identical). Instancing the mesh helped a good deal, but still far worse than the single mesh implementation, and AFAIK doesn’t offer the ability to texture individual instances.
At this point I figured the only thing that seemed to work was the single mesh with all of the vertex data. So I started looking into multi materials. I followed this guide:
and started first with rows of voxels. I created a material and submesh per row. It worked, and the performance was actually decent, so I figured I’d go on to do it per voxels. Creating a submesh per voxel basically crashes the application.
Now I’m wondering if I’m out of options. I could use a single PBR material and UV the voxel geometry to different parts of the texture, but that’s also going to be quite limiting.
Any thoughts/feedback welcome.