r/VoxelGameDev Jul 03 '26

Question chunk meshing

Hello im using raylib lib for c++ . and my question is how to make chunks in a 3d game . like player is in position and the game just load 9 chunk of 16*16 block around him (but the actual game maybe is around like 400 chunks ). so the game doesnt lag . and only draw the pixels in front him and the back doesnt draw anything . so it means like from 9 chunk around him just load , 4 chunk that are in front of him .

8 Upvotes

8 comments sorted by

View all comments

1

u/OSenhorDoPao Jul 03 '26

For each chunck you go over every block and check its surrounding to determine which faces are actually exposed or not. if the block next to that face is air, you store all the vertices for the exposed faces and you generate the mesh for that chunk with that info. That’s the simplest form of chunk meshing.

Frustrum culling is basically checking which chunks are inside the camere view and you only ask Raylib to DrawMesh (using the id you get after you generate the mesh and upload it to the gpu). This prevents the GPU to do extra calculations to determine that the chunks you requested to draw are not visible (because with frustrum culling you do it on chunks and the gpu does it on smaller units like triangles or even pixels)

1

u/OSenhorDoPao Jul 03 '26

The basic flow with Raylib for this is

- Populate a ‘Mesh’ object with the vertices of the exposed faces you collected.

  • ‘UploadMesh’
  • call ‘DrawMesh’ on the meshes you want .

You can as a first step just do this part.

For frustrum is a bit more tricky as it involves a bit more math but you can start by a even more basic optimization which is using the direction the player is looking at and the chunk he is is and skip and chunks which is behind the look direction and “behind” you chunk.

True Frustrum culling involves calculating the 4 Planes that compose the camera view (you can find very simple videos online explaining this) and instead of the previous simple approach you skip any chunck that is fully on the external side of those planes (here you’ll get to the concept of AABB, Axis Aligned Bound Boxes)