Falling Sand Simulation using SDL3 GPU with compute shaders
Install the Vulkan SDK for glslc
git clone https://github.com/jsoulier/falling_sand --recurse-submodules
cd falling_sand
mkdir build
cd build
cmake ..
cmake --build . --parallel 8 --config Release
cd bin
./falling_sand.exe
git clone https://github.com/jsoulier/falling_sand --recurse-submodules
cd falling_sand
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel 8
cd bin
./falling_sand
Note
The algorithm is extremely inefficient. It brute-force calculates everything each frame. That said, I can easily get 16 million particles (4000x4000) simulating at 60 fps on my RTX 4050
- Clear the write texture
- Divide the area into 3x3 cells (so that there's no race conditions)
- Dispatch 9 times (for each cell within the 3x3 cells) and simulate each particle
- Swap the read and write texture
- Apply a blur (not really a blur) to fill in gaps between particles
- Youtube Video by MARF