Home
/
Indie Game Developers
/
Re: cOg Mission
/
I Added Millions of Quantum Particles in Unity. They Only Exist When You Look at Them.

I Added Millions of Quantum Particles in Unity. They Only Exist When You Look at Them.

Published
Length
This is the story of implementing what I've learned into a gridless, interactive, world-building sandbox game called Minor Deity. Minor Deity on Steam: https://store.steampowered.com/app/3876240/Minor_Deity/ Minor Deity Discord Server: https://discord.gg/2NEb4HxwhF There are millions of particles in this world: flames, embers, ashes, smoke, dust, leaves and mist. But right now, almost none of them exist. Because these are quantum particles - they only exist when you look at them. They simply pop into and out of existence at exactly the right time, looking like they’d always been there. And when they pop out of existence, we don’t simply hide them off-screen. We actually don’t have to keep track of them, simulate them or allocate memory or other resources to them at all. Until the next time we look where they’re supposed to be, and there they’ll be. Like magic. Actually, no. Like quantum. So, how do we create these quantum particles? Let’s take a small step back to clarify our starting point. In the video in the top right, I explained how I developed my own particle system for performance reasons, allowing us to create and simulate tens of thousands of particles across the map, cull them in a performant way, and send only the visible ones to the GPU to be rendered. We also needed to employ some tricks when sorting the semi-transparent particles to ensure the order in which they are rendered doesn’t change and cause flickering. This is already a very performant system, because the culling can happen very quickly, since we cull by underlying hex rather than individual particle. And to save more CPU capacity, we don’t actually simulate the particles that are out of view other than letting their lifetimes progress and removing them when their time has run out. So, we minimize the resources spent on particles that are out of view. But we still need to keep their current position and other state variables in memory, and having huge arrays of such data slows down the calculations applied to that memory. This puts a practical limit on how many particles we can have spread across the map. But what if we could completely remove the dependence on saving the current state of the particles? What if the only memory we needed was for those particles that would currently be in view and close enough to the camera? This means our previous global limits on particle numbers would become our new in-view limits on quantum particles, which allows us to have millions of quantum particles spread across the map, as long as we don’t display more than the limit at once. And I found a way to do just that. 00:00 Quantum Particles 00:48 How We Got Here 01:42 Completely Ignoring Particles Paths 03:28 Sampling 3D Noise 04:41 Our New Approach 06:10 Solving New Problems 07:38 How Much Does It Cost? 09:06 Rule-Based Particles 10:15 Outro