Million Particles
You'll keep a swarm of particles entirely on the GPU, updated by a compute shader or transform feedback, so a million of them move at sixty frames a second without the CPU touching one.
About
A CPU can move a million particles per frame if you're careful, but copying them to the GPU every frame throws that away. The trick is to keep the particles on the GPU and update them there, with a compute shader on OpenGL 4.3, Vulkan, Metal or WebGPU, or with transform feedback on older OpenGL and WebGL 2, which is what a Mac's OpenGL supports. Along the way you meet storage buffers, workgroups, and the one rule that matters: the GPU is fast when every thread does the same thing.
At a glance
- Per requirement
- 35 XP
- Completion bonus
- 300 XP
- Requirements
- 6
- Takes
- Two to three weeks
- Skill level
- Advanced (years of practice)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Draw ten thousand particles updated on the CPU and uploaded each frame, timed. Give them simple gravity and a bounce off the floor. Print the frame time, then raise the count until it drops below 60 frames a second. Take a screenshot with the count and the frame time on screen. Photo
-
2
Move the update to the GPU and keep the buffer there. Write the position and velocity update in a compute shader or a transform feedback vertex shader. No per-frame buffer upload after setup. Take a screenshot of the shader that does the update. Photo
-
3
Reach a million particles at 60 frames a second. Draw them as points or small instanced quads. The frame time counter must be on screen. Film ten seconds with the count and the time visible. Video
-
4
Add an attractor you drag with the mouse. Pass the mouse position as a uniform and pull the particles toward it. Film yourself steering the cloud. Video
-
5
Spawn and kill particles on the GPU without the CPU counting them. Give each particle a lifetime and reuse dead ones, with an atomic counter or a ring buffer, so the CPU never reads the list back. Film a continuous fountain running for thirty seconds with a stable frame time. Video
-
6
Work out the memory bandwidth your swarm uses and compare it to the card's limit. Count the bytes per particle you read and write each frame, multiply by the particle count and by sixty, and you have gigabytes per second. Look up the memory bandwidth of your GPU and work out what fraction you're using, which tells you whether the next speedup comes from fewer bytes or fewer threads. Take a photo of the arithmetic with the GPU named, and write one line on which number surprised you. Photo