---
id: "margolus-3d-block-cellular-automata"
title: "3D Margolus 2×2×2 Block Cellular Automata"
aliases: [Margolus neighborhood CA, partitioning cellular automata, 3D block cellular automata, mass-conserving voxel falling sand]
domain: "simulation"
stage: "simulation"
realtime: "realtime"
platforms: [webgpu, webgl2, desktop-gpu, cuda, cpu]
year_introduced: 1984
inputs: [voxels]
outputs: [voxels]
style: "both"
dynamic: "dynamic"
cost: "cheap"
authority: "Margolus, 1984"
url: "https://texelatlas.vercel.app/t/margolus-3d-block-cellular-automata/"
sources_verified_at: "2026-11-30"
---
# 3D Margolus 2×2×2 Block Cellular Automata (Margolus, 1984)

> Partition a 3D voxel grid into disjoint 2×2×2 blocks whose origin shifts each substep, letting GPU threads update all blocks in place in parallel while strictly conserving voxel count and avoiding write conflicts.

## Reach for it when

- falling sand or granular voxel sim loses or duplicates particles on gpu
- need race-free parallel 3d cellular automata without atomic locks
- simulate mass-conserving 3d sand piles water percolation and avalanches
- update colliding voxel neighbors cleanly in alternating 2x2x2 blocks
- build a fast real-time 3d falling-sand sandbox in compute shaders

## How it works

Ordinary cellular automata update one cell at a time by reading neighbors, which makes mass-conserving transport (such as falling sand, rubble, or granular collapse) hard to parallelize on GPUs: two grains can simultaneously try to move into the same empty voxel, causing race conditions or lost matter.

The Margolus partitioning scheme eliminates write hazards by decomposing the 3D lattice into non-overlapping $2\times 2\times 2$ blocks. On each step, a single GPU thread owns one 8-voxel block, reads all eight cells, applies a local mass-conserving permutation rule (such as letting sediment drop vertically into empty lower cells, slide diagonally off slopes, or erode when exposed to wind or water jets), and writes all eight voxels back **in place** with zero atomics and zero double-buffering.

To allow matter to travel across block boundaries, the grid partition origin shifts between steps across offsets $(ox, oy, oz) \in \{0, 1\}^3$ (cycling or randomizing parity to prevent directional bias). Because every local rule only permutes states within a disjoint $2\times 2\times 2$ cube, total particle mass is conserved by construction while achieving full hardware parallelism across millions of voxels.

## When to use it

Choose it for real-time 3D granular sand, sandstone erosion, rubble avalanches, or interactive destructible voxel sandboxes where strict mass conservation and race-free GPU compute performance matter.

Prefer [gpu-pipe-model-erosion](gpu-pipe-model-erosion) or [shallow-water-equations](shallow-water-equations) for flowing water with hydrostatic pressure (Margolus voxel water lacks pressure gradients and creeps slowly without forming streams). Prefer [mpm-snow](mpm-snow) or [sph-fluids](sph-fluids) for smooth continuum deformation and free-flowing liquids. Prefer [cellular-automata-cave-generation](cellular-automata-cave-generation) when generating static procedural caverns without conservation laws.

## Cost

cheap — Each thread updates 8 packed voxels in place with no ping-pong buffer copy or atomic contention; a 128^3 grid dispatches only 64^3 block threads per pass in WebGPU compute.

## Failure modes

- No long-range hydrostatic pressure or momentum transmission: bulk liquids creep at most one voxel per step and pile up instead of rushing downhill
- Regular parity cycling can create subtle diagonal bias or checkerboarding unless block shift orders are randomized or well-balanced
- Maximum transport speed is bounded by one voxel per substep, requiring multiple substeps per frame for fast-falling debris
- Fixed-resolution dense 3D voxel buffers scale cubically in memory with world extent

## Dataflow

- Inputs: voxels
- Outputs: voxels
- Platforms: webgpu, webgl2, desktop-gpu, cuda, cpu

## Combines with

- [Voxel grid DDA ray traversal (Amanatides–Woo)](https://texelatlas.vercel.app/t/voxel-grid-dda-traversal.md): Direct 3D DDA ray traversal renders the live voxel storage buffer immediately after each Margolus step without remeshing.
- [GPU Pipe-Model Hydraulic Erosion](https://texelatlas.vercel.app/t/gpu-pipe-model-erosion.md): Virtual-pipe surface water cuts into solid rock voxels and feeds loosened sediment directly into the Margolus falling-block pass.

## Combination ideas

- [Overhang-capable voxel erosion with pipe-model water](https://texelatlas.vercel.app/ideas/margolus-voxel-erosion-pipe-water/)

## Sources

1. [primary] Norman Margolus (1984) Physics-like models of computation. Physica D: Nonlinear Phenomena. https://doi.org/10.1016/0167-2789(84)90252-5 (verified via doi.org on 2026-11-30)
2. [primary] Tommaso Toffoli, Norman Margolus (1987) Cellular Automata Machines. The MIT Press. https://doi.org/10.7551/mitpress/1763.001.0001 (verified via crossref on 2026-11-30)
3. [implementation] ttillberg (2026) ttillberg/codevember-2026. https://github.com/ttillberg/codevember-2026 License: MIT. (verified via github on 2026-11-30)

## Cite this entry

Texel. "3D Margolus 2×2×2 Block Cellular Automata." https://texelatlas.vercel.app/t/margolus-3d-block-cellular-automata/ (accessed 2026-12-01).
