I am attempting to create a voxel game. This game has many parts in one area, therefore performance is heavily impacted. A world that is 64x64 parts big will even feel a loss in FPS.
How do I optimize my game so that the impact on FPS is very small? I was thinking of a chunk loading system, however other solutions will definitely be considered!
Here is an image of a 64x64 world which still suffers a loss in FPS from the parts:
My strong point is not math so right off the bat, I recommend taking anything I say with a tiny grain of salt.
I do know that many many voxel games hide blocks underneath other blocks, You could try using some math regarding camera position in the world to cull out blocks that aren’t rendered on the screen?
Then using a “distance” feature where you break every 32x??x32 set into “chunks” and hide chunks that are far away
I wanna do that chunk idea, but I’m just not sure how to break every 32x??x32 set of blocks into chunks and how to keep track of those chunks, and how to load them.
Unrelated, but to improve FPS you should only display visible blocks. For example, if a block is surrounded by other blocks in all possible directions, don’t create it. If a block is destroyed and the prior block would now be visible, create it. This is how most popular games (Mining Simulator comes to mind here) render blocks on a large scale with minimal FPS issues.
On to your chunk system, there are several ways to go about it. You could generate your terrain in chunks of 32x32 and then group those together, then store them for later use and generate them as needed. Tinker about with it and find out what works best for your specific use case.
I have a chunk loader (And I might dm it to you if you would like tbh). The way we get what chunk the player is in (For example chunk 1, chunk 2, etc…) is by doing this:
function GetChunk(x, z, chunkSize)
local cx = x - (x % chunkSize)
local cz = z - (z % chunkSize)
return cx, cz
end
Then we compare what chunk a block is in and what chunk the player is in to the render distance. So if the render distance is 1 and the player is in chunk2 and a block is in chunk5 we would unload / remove the part.
If you would like more info let me know!Or dm me so I can give you my chunk loader that way you can take a look on how it works!
I don’t have much input on chunk loading, but if you are worried about performance you could also “simplify” the map and combine this with chunk loading.
This would be difficult to code due to all the logic it needs, though I believe the simplifying could really help with your performance issue.