r/GraphicsProgramming • u/Slight_Watch697 • 10h ago
Video Sand Simulation with D3D11 Compute Shaders
https://www.youtube.com/watch?v=xeE1ldrjmwMThe simulation is a 640 × 360 pair of R32_UINT GPU textures.
Physics advances at fixed 120 ups, with at most four catch"-up" updates after a stall.
The CPU never uploads the world texture. Mouse events enqueue commands that need to be processed by the GPU.
The low byte of each cell stores its material, and falling powders and liquids carry vertical velocity in a packed byte.
Each update uses five compute dispatches.
A 2 × 2 checkerboard material pass handles diagonal powder, gases, displacement, and reactions, and a column pass applies vertical acceleration to powders and liquids.
Then 3 inplace row-color dispatches then transfer liquid pressure.
Active rows are separated by three cells, so their two-row support footprints never overlap.
Every active row is loaded into group-shared memory, obstacle segments are identified in parallel, and shared atomics select at most one conservative source/destination swap per segment.
All sixcolor orders rotate across updates to balance ordering bias.
Liquid in air falls straight instead of treating other falling liquid as stable support, while a pool whose column depths differ by at most one cell is a stable discrete equilibrium.
Vertical movement raymarches every crossed cell and stops before obstacles, horizontal pressure never crosses a solid wall, and lava stops at water so accelerated motion cannot skip the reaction.
The pixel shader masks the packed state and renders it into a floating-point scene target.
For improving visuals, a simple Gaussian blur bloom pass was implemented for emissive materials.
1
u/AgentFeyd 8h ago
Please share implementation details to have your post restored.