How to optimize my minecraft clone #3

My github repository with the code is this:

DrFrankxio/hritik-s-minecraft

And the trouble is that it runs laggy when i increase the fps or render distance to 10. Any solution? Thanks anyway!

It’s not viable to use geometries for minecraft-like games. What you need is (1) divide world into chunks of blocks (blocks as data, not blocks are 3D objects), then (2) use a meshing algorithm on dirty (ie. modified) chunks to render them into 3D geometries (don’t to meshing on every frame, only when a chunk is modified.)

Long story short - minecraft worlds are not built with blocks, rather geometries generated from block data, that finally will look like the blue one here:

2 Likes

Its applicable to this code?:

DrFrankxio/hritik-s-minecraft

I have another example, but player cant put or break blocks, and the physics doesnt work…

It’s applicable to building a minecraft game. Your code uses blocks (and waaaay too many materials) without doing any kind of meshing - so in the end you’re rendering 100x times more triangles than necessary (since meshing merges planar vertices into planes and makes sure internal walls of blocks are not actually created in the geometries.)

Be sure to (1) use meshing, and (2) use as few materials as possible - theoretically speaking, you should be able to render the entire world with a single material / draw call (that’ll require merging all textures into a single texture atlas), although using single material for each block type should be ok (you’ll get a few more draw calls, but as long as you’re doing meshing, that won’t be that performance-killing.)

I suspect better method is rendering only the surfaces of all blocks as the mesh. Or not?

With that we can only render the surface, doesnt affect the hidden blocks. Its is sucesfull with the opaque blocks, but another trouble is for rendering the non-opaque blocks…

  1. Yup, that’s exactly what meshing is.
  2. Rendering transparent stuff works similarly to how deferred rendering does it. Separate opaque and transparent blocks into two “worlds” and mesh them separately. Then, first you render the opaque world, and on that opaque world (without clearing the frame) render the semi-transparent world (11:58 for example, works the same in minecraft and in GTA pretty much.)
1 Like

U have the optimized code here, but with a counterpart: The world is finite:
DrFrankxio/industrias-carmelo-v0.20

Solved, the link of the clonable game is here:

MinecraftClone/README.md at main · Atlas8t/MinecraftClone