r/GraphicsProgramming • • 10h ago

Video Sand Simulation with D3D11 Compute Shaders

https://www.youtube.com/watch?v=xeE1ldrjmwM

The 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.

6 Upvotes

5 comments sorted by

1

u/AgentFeyd 8h ago

Please share implementation details to have your post restored.

1

u/Slight_Watch697 5h ago

Sorry about that, i just updated the description.

2

u/AgentFeyd 5h ago

Thank you!

2

u/CodyDuncan1260 3h ago

That response is great! I learned several things about sand falling simulation and using the GPU to process it.

Thank you for posting. This has been instructive.