Simulating 1M particles on GPU compute shader threads in HLSL:
struct Particle { float3 position; float3 velocity; float life; };
RWStructuredBuffer<Particle> Particles : register(u0);
[numthreads(256, 1, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
if (id.x >= 1000000) return;
Particle p = Particles[id.x];
p.velocity += float3(0, -9.81, 0) * 0.016;
p.position += p.velocity * 0.016;
p.life -= 0.016;
Particles[id.x] = p;
}Dispatched via Dispatch(1000000 / 256 + 1, 1, 1). Simulates 1,000,000 particles in < 0.4 milliseconds on modern GPUs!