Login | Register 

2D Fire

Helpful techniques for working with TouchDesigner. Answers only, no questions.

2D Fire

Postby prema » Sun Jun 18, 2017 3:26 am

Hi all,

I've been trying to extend Kurt Kaminski's amazing 2D fluid example:
to behave/look more like fire, by implementing a few concepts from Houdini's Pyro Solver:
* Disturbance
* Turbulence
* Cooling rate
* Drag

2d_fire.jpg (51.63 KiB) Viewed 1306 times

Disturbance/Turbulence ended up being a collection of finely tuned noises, masked by the speed of the surrounding velocity field to add back onto the velocities. This creates lots of lovely break-up and flow patterns - there's plenty of opportunity to get creative here.

Cooling rate and drag keeps the sim under control, after having injected a lot of temperature to add more dynamic interest. I've also added another image input to the buoyancy operator, to allow for varying buoyancy across the image, which adds additional swirling motion.

For the fire-look, I crunched the levels of the temperature output to give me as much contrast as possible and then ran the result through a series of modular filters. You want to apply a linear colour-space workflow here when dealing with very high luma values. Finally I've used tone-mapping to get the result back into a sRGB-friendly colour-space and tweaked to taste, until I recovered a pleasing looking range.

After having played with a bunch of simple shapes as density/temperature input, I've explored driving the whole thing with a video, by running an edge detection filter to extract contrast areas from the video:

At that stage things are really starting to come alive :D

The input temperature/density values are very touchy and dependent on the input. For the sake of sharing something more sane, I've cleaned up my mess and tried to prepare an interactive example which turned into its own side-project:

Move the mouse around to control where to emit from (and advect things, it'll pick up the mouse's velocity), the fuel will spread and propagate using a modified dilation operator. Have a play with the parms of the 'FUEL_SOURCE' component:

* Fuel - amount of fuel injected into the sim
* Spread - amount/speed of propagation
* Cooling Rate - globally calming things down
* Cooling Noise - patchy reduction of emission areas

Sorry, this turned into way more text than I hoped :P
Some stuff in the example I've borrowed/extended from other sources, I hope I've credited everyone accordingly - let me know if I forgot anything.
Huge thanks to Kurt again for sharing his original example! :D

Lastly, this project is a bit of a beast - I'm getting around 50fps@1280x720 on my GTX1080, any ideas for optimisation are greatly appreciated :)
(2.02 MiB) Downloaded 173 times
Posts: 2
Joined: Fri Sep 25, 2009 10:41 pm

Re: 2D Fire

Postby raganmd » Sun Jun 18, 2017 1:20 pm


Found a few things worth optimizing:

This op is costing like 12ms for some reason. Replaced with a fit TOP doing the same thing. The fit TOP costs about 0.01 ms in comparison.

Remove the vector array ref in the GLSL TOP. Those arrays can be real handy, but they can also be expensive. The TOP was cooking at about 12ms, just removing the array refs from the TOP (it's already commented out in the shader) dropped the cost on this TOP down to 0.02ms.

50 passes weighs in at 2ms on my gtx 980, knocking this down to 1 pass cuts the cpu cost down to 0.1ms. So far this change is what's made for the biggest speed improvement I've seen.

Starting out I was seeing 25 fps performance on a 980, after the above changes I'm up to 45.
Posts: 951
Joined: Thu Mar 28, 2013 5:21 am
Location: San Francisco, CA

Re: 2D Fire

Postby CutMod » Mon Jun 19, 2017 12:46 am

Wow! :o This is so cool! I was impressed with the video you posted a few months ago on Vimeo, and am very happy/grateful that you posted an example file.
I'm having a lot of fun flailing the mouse around and will probably attach fuel source to Kinect hand tracking next... or maybe HTC Vive controller render-pick? :geek:
Thanks for sharing!
Posts: 123
Joined: Thu Jul 03, 2014 10:44 am
Location: Los Angeles

Re: 2D Fire

Postby prema » Wed Jun 21, 2017 11:11 am

Thanks guys, glad you find it useful :)

Appreciate the optimization suggestions, nice find!
I keep forgetting about the fit TOP...thanks for the reminder. Turns out, the 'Quality Resize' option on the Resolution TOP slows things down a fair bit alone.

True, the Jacobi iterations is in fact the slowest part of the whole thing, but it also makes the fluid look more interesting/swirly by doing a more 'accurate' pressure solve (at least that's my understanding). I guess it's a good trade-off, seeing how it still produces nice results at much lower interations with everything else that's going on.

Yes, hooking up a Kinect would be so much fun! I'd love to see what you come up with :)
Posts: 2
Joined: Fri Sep 25, 2009 10:41 pm

Return to Techniques

Who is online

Users browsing this forum: No registered users and 2 guests