r/FastLED • u/StefanPetrick • May 01 '26
Announcements From zero to fire simulation - building my own model
The learning curve is wild when collaborating with a bunch of AI instances. It feels like having someone infinitly patient with a PhD in math and a PhD in physics around who happens to also be an experienced senior software developer.
I didn’t sleep for too long, but what I’ve learned about simulation approaches in the last few days blows my mind.
I started 2 months ago with simply applying a procedurally generated (Perlin noise) advection field.
Then I figured out how to actually simulate the advection based on a Newtonian fluid.
And now… I’ve started to simulate fire. For now, only a few of its properties, to get familiar with the architecture of a complex simulation pipeline.
I’m simulating a coupled system of flow, heat, and smoke.
the flow moves heat and smoke
the heat creates flow
cooling heat creates smoke
the renderer maps those fields into a flame appearance
It works as follows:
This simulation uses a visually driven coupled field model on a fixed 64x64 grid.
What is stored per cell:
u, v: the two components of the velocity field
temperature: how hot that cell is
smoke: how much smoke / density is in that cell
What happens each step:
The source injects new temperature, smoke, and upward momentum near the bottom. (source term / forcing)
Gravity and especially Buoyancy modify the velocity field. Hotter cells get extra upward force. (buoyancy force model)
The velocity field is diffused, projected, and advected. This is the classic incompressible fluid core: smooth it, enforce near zero divergence, then move the flow through itself. (Eulerian incompressible fluid solver / Stable Fluids style)
temperature and smoke are transported by that velocity field. So heat and smoke get carried by the flow. (semi-Lagrangian advection on an Eulerian grid)
temperature cools down over time. (simple exponential decay / cooling model)
Part of that lost heat is converted into new smoke. This is an important feedback loop: hot flame gradually produces smoke as it cools. (heuristic reaction / transfer model)
Vorticity confinement artificially boosts small vortices so the flow does not become too smooth and dead-looking. (vorticity confinement)
The key feedback loop:
more temperature creates more buoyancy
more buoyancy changes the velocity field
the velocity field transports temperature and smoke
temperature cools and generates smoke
smoke changes the visible shape and softness of the flame in rendering
vortices in the velocity field tear and fold the heat/smoke fields into richer structures
Why it looks good:
The solver transports everything coherently, so shapes do not break up randomly, they deform like flowing material.
temperature and smoke play different visual roles:
temperature gives the bright active flame core
smoke gives softer, darker, trailing regions
Fire color is not simulated directly as RGB fuel chemistry. Instead, it is rendered from the fields:
hot = bright / yellow / white
cooler = orange / red
smoke-heavy = darker / grayer
Vorticity confinement brings back the small flickering tongues and curls that numerical damping would otherwise wash out.
The system is only a rough physical approximation, but it emphasizes exactly the cues our eyes read as fire:
upward rise
turbulent breakup
bright core
unstable edges
smoke appearing as things cool
Recognition & credit: I've learned so much by reading
“Stable Fluids” (1999) by Jos Stam which was published at SIGGRAPH 1999.
https://pages.cs.wisc.edu/~chaol/data/cs777/stam-stable_fluids.pdf
Its impact led to major awards for the author:
2005 – ACM SIGGRAPH Computer Graphics Achievement Award Awarded to Stam for his overall contributions (including Stable Fluids).
2005 & 2008 – Academy Scientific and Technical Awards Often called “Technical Oscars,” recognizing contributions to visual effects and simulation techniques.
Edit: I last tried visualizing fire 7 years ago: https://www.youtube.com/watch?v=SWMu-a9pbyk
Nothing was actually simulated back then—it was just uncoupled layer advection & domain warping stacked together.
Still, it was convincing enough that one user’s neighbor called the firefighters after seeing it through the window, which I considered a great compliment. 😉
I’m curious what this current model might cause...
Edit2: Here is the complete Python code https://gist.github.com/StefanPetrick/e0facb16ce7c74747ee07ff58e22556b
You can run this yourself and play with all the parameters.
I’m confident that after refactoring it in C++, this will run on a Teensy 4. I’m less confident about the ESP32.
But hey, I said the same about the previous smoke model, and u/mindful_stone made it work to prove me wrong which I appreciate deeply!
Edit3: If you’d like to support my work, I’d truly appreciate it. Any donations will go directly toward more AI tokens: paypal.com/donate/?hosted_button_id=YR7Q795MYU9HS
3
u/StefanPetrick May 01 '26 edited May 02 '26
Here I recorded a video of the current UI control in action: https://www.youtube.com/watch?v=464tFGRac4g
This video only begins to scratch the surface.
I will later demonstrate the wide variety of very different fire styles, stages, and conditions that can be modeled with it — all of which look natural and convincing in their own way.
2
u/StefanPetrick May 01 '26 edited May 03 '26
Oh, sweet! I came across an emergent ring of fire: https://youtube.com/shorts/jdytsE-Kj80
2
u/StefanPetrick May 02 '26 edited May 02 '26
Beautiful emergent fractal vortices: https://www.youtube.com/shorts/RKGXx6KS0as
2
u/StefanPetrick May 03 '26
Burning letters. Anything can serve as a fire emitter.
https://youtu.be/FitV-Z711UE
2
u/osenbruggen May 01 '26
really cool :)
2
u/Informal_Sir_9518 May 01 '26
Bravo
2
u/blink015 May 01 '26
Very cool stuff. I've been a fan of the work you've done since the MSGEQ7 days.
2
u/lilvixen May 01 '26
GitHub?
2
u/Evening-Appeal7606 May 01 '26
"The learning curve is wild when collaborating with a bunch of AI instances. It feels like having someone infinitly patient with a PhD in math and a PhD in physics around who happens to also be an experienced senior software developer."
This I found to be very true, but with a caveat: AI-assisted projects feel like you talk to an eccentric (yet, as you noted, highly skilled) uncle - think "Doc Brown" from BTTF. After a while of conversing with it, it starts drifting, losing focus, overriding and down-right negating stuff you previously discussed. It's like having to give your "eccentric uncle" a break once in a while and start a completely new chat to bring it back "on track".
Also: Supremely cool aesthetics with your project, Kudos!
2
u/chemdoc77 May 01 '26
Hi u/StefanPetrick - This is really AWESOME! I am looking forward to seeing flaming kaleidoscopes!
1
u/StefanPetrick May 02 '26 edited May 03 '26
On my journey of exploring what is possible with an Eulerian solver, yesterday I attempted to design a coupled system to simulate lava lamp mechanics.
I didn't manage to separate the bubbles, and the system is also unstable (turning everything into wax or water after a few minutes), not to mention the wrong parameters making the system look and feel unnatural. But again, I learned and understood a lot of new things. This is how far I got: https://youtu.be/hTc6g3C6SCU
1
u/StefanPetrick May 03 '26
Fire around an obstacle: https://www.youtube.com/watch?v=GM1aHFo5S_w