Multithreaded Particles

Jul 23 2023
Multithreading/Unity (HLSL, C#)

Multithreading experiments in Unity in HLSL, based heavily on Sebastian Lague’s code. This is a work in progress - I hope to add touch interactibility soon. Made for the Valegos Computational Science Center.

The following experiments show simulations with only 10,000 agents. With a maximum of 16 thread groups, and a group size limit of 65,536 (2^16), a total of 1,048,576 (2^20) agents can be simulated without any issues on a mac with an M1 chip. Running the program on any modern graphics card should be able to run 16,000,000 agents without a problem (after increasing thread groups to 256).

Github Link


Particles move around with constant speed and direction while “painting” the screen, only changing direction when the edge of the screen is hit. 

The following simulations only differ by how the 10,000 simulated particles are spawned.

Random:





Random Full Circle





Outwards Full Circle:






Inwards Full Circle:





Inwards Circle (the antialiasing causes some interesting patterns):