r/VoxelGameDev • u/Kitchen_Day_3929 • 20h ago
Article Zero-meshing C++/Vulkan voxel engine: 128³ toroidal macro grid + 8³ sub-voxel bitmasks, two-level DDA, and in-place GPU cellular rubble/fluids
Been building a custom C++23/Vulkan voxel engine from scratch for GIGAH|RUSH 2 (a survival horror sim set in an endless concrete megastructure). Thought the data layout and destruction/fluid coupling might be interesting here.
World layout:
- Active floor is a dense 128³ toroidal grid (2 m macro cells, 256 m wrap period on X/Y/Z).
- Each macro cell stores a 16-bit CellType and an 8³ occupancy bitmask (512 sub-voxels at 0.25 m, packed into 8x uint64_t = 64 bytes/cell).
- Uniform cells allocate nothing per sub-voxel. Only mixed cells (painted concrete, partial carves, fluids/gases/debris) allocate a 1 KiB (512x uint16_t) page from a paged-sparse pool, settling back to uniform when homogeneous.
Rendering (no meshing):
- Deleted greedy meshing early on and switched to a fullscreen two-level Vulkan DDA raymarcher over a GPU VoxelMirror (8³ brick occupancy bits + 16³ summary, 1-byte cell class, masks, and demand-sized pagePool).
- Carving concrete only uploads dirty cell deltas (64 B mask + metadata, plus 1 KiB page if mixed). Zero mesh rebuild stalls. Raymarcher writes gl_FragDepth so rasterized props/characters/Verlet wires occlude normally.
- Toroidal wrapping comes for free in the marcher (rays walk camera-relative distance and bitmask the cell index).
Destruction & GPU cellular automaton:
- Carving is stateless and deterministic: hash(seed, cell, bit) vs material hardness with a 1/4 endurance threshold (no per-voxel HP).
- Disconnected chunks are found by a hierarchical connectivity sweep (per-cell 6-connected load-bearing sub-voxel nodes + face-overlap edges, escalating large components to incremental torus-percolation checks) and converted in place to loose rubble_* materials.
- Liquids, toxic gases, fire/smoke transitions, and falling rubble all run in one 8-phase Margolus cellular automaton (31.25 Hz) operating directly in-place inside VoxelMirror's pagePool, with a fenced ring readback syncing masks back to CPU physics.
If you want to see how it looks in motion, there are screenshots/clips on the Steam page: