Devlog #1.3: Hidden-face Culling


Hidden-face culling is a technique to reduce the number of faces in a voxel mesh by removing those that are completely hidden (adjacent to another voxel). This greatly reduces the total number of vertices and triangles that need to be rendered.

🔶 The Original Approach

When generating the mesh for a voxel, I checked each of its six faces.

  • If a neighboring voxel existed on that side → skip the face.
  • Otherwise → add the face to the mesh.

While logically correct, this required looping through a huge number of voxels and performing random memory access, which quickly led to very poor performance.

🔶 The Optimized Solution – Binary Hidden-Face Culling

To solve this, I found a faster approach using a bitmask. Each voxel is represented as a bit (1 = solid, 0 = transparent/air). By shifting and applying bitwise operations, I can instantly determine which faces are visible without looping neighbor by neighbor. The result is a mask containing only visible faces, calculated in bulk with simple binary math.

🔶 Example: Culling Left Faces

  • Solid voxels: m = 1101000100111110
  • Shift right (neighbor to the left): m >> 1 = 0110100010011111
  • Invert to find air on the left: ~(m >> 1) = 1001011101100000
  • Solid & air-left = visible left faces: m & ~(m >> 1) = 1001000100100000

Similarly, for right faces, you just shift left instead of right. From these masks, you can choose which faces to draw or not.

Leave a comment

Log in with itch.io to leave a comment.