Posted September 10, 2025 by Yunasawa
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.
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
m = 1101000100111110
m >> 1 = 0110100010011111
~(m >> 1) = 1001011101100000
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.