TouchDesigner is well known for always having new features coming out. It’s what it makes it the go-to tool for interactive developers who want support for the latest tools and softwares. nVidia Flex integration has just been added to TouchDesigner and it’s an exciting way to do fluid simulations. But if you’re like most people, it can be a bit tricky to approach, so here’s your quick start guide to nVidia Flex. Let’s go!
What is nVidia Flex?
nVidia Flex is a library from nVidia that allows softwares to create GPU accelerated particle-based fluid simulations. Now that’s a mouthful for sure, let’s break it down really quickly. It’s GPU accelerated which means it’s going to be very fast and can scale incredibly well. If you’ve used Bullet Physics in TouchDesigner you’ll know that it’s flexible and easy to use but because it’s CPU based, it can’t really scale up to thousands and thousands of objects while nVidia Flex can. Flex is also a particle-based fluid simulation, this means that behind the scenes everything is represented as a particle and those particles collide and act like fluids. In this quick example we’ll still be staying in the realm of rendering those particles, but more advanced users can experiment with dynamically creating meshes with the particles.
First Step to using nVidia Flex in TouchDesigner: Setting up the simulation
The first thing we’ll need is an nVidia Flex Solver COMP. This is the brains of our operations. It’s what is going to calculate all the fluidy goodness in our project.
That’s the heavy lifting of integrating Flex Solver! That’s why we love TouchDesigner! But we’re not done yet.
Setting up our actors
Now we want to create something to emit the fluid particles. So we can create an Actor COMP right next to our Flex Solver COMP. The Actor COMP is used to create geometry objects that are going to interact within the Flex simulation (and also inside of Bullet physics simulations):
Inside of the actor let’s create a small polygonal Sphere SOP that will be used to represent our fluid particles in the rendering. We’re setting this to polygon primitive type to reduce some of the processing power required for this example. Don’t forget to turn on the render and display flags on it!
Now we can re-initialize our Actor in it’s parameters so that the Actor COMP can properly represent our sphere:
Now let’s set our actor to emit fluid particles in its Flex parameters and increase it’s Emission size to 5 and 5, which essentially will just shoot them in more directions instead of just shooting them all in a straight line:
Great! So now we can test to see if our simulation is working by going to the Flex Solver COMP and clicking on the Start Sim parameter pulse button:
Low and behold we have fluid!
Add a bounding box
The next thing you’ll want to do is create a bounding box to hold all of fluid sim. This will give the particles an interesting place to interact with each other. I’ll start by creating a second Actor COMP and setting it’s Kinematic State to be Static. This just tells the simulation that this thing is meant to be run into, but doesn’t emit particles or anything like that on it’s own:
Now we’ll go inside of this and create a bounding box. This can be just about anything, but I think a box is simple and has some cool effects. Let’s create a Box SOP, make it of a size of 15, 15, 15 so that it can hold all our simulation. Again, don’t forget to turn on render and display flags on the SOP and re-initialize the Actor!
Now when you go ahead and start the simulation again, you’ll see that in the viewer of actor1 all of our particles are now constrained to living inside of the box we just created:
Setup your render
One of the cool things about the Flex Solver COMPs and Actor COMPs is that they work just like a regular Geometry COMPs in our render setups. So to capture the output of our simulation into a texture, we can setup a normal render setup including a Render TOP, a Camera COMP, and a Light COMP:
Next we’ll want to remove the bounding region from our render, which can easily be done by changing the Geometry parameter of the Render TOP to only select actor1. We’ll also go ahead and add a Phong MAT to our actor1 so we can make it a different colour and we’ll move our camera slightly further back and a little bit lower, to get a better view of our simulation:
Get Our 7 Core TouchDesigner Templates, FREE
We’re making our 7 core project file templates available – for free.
These templates shed light into the most useful and sometimes obtuse features of TouchDesigner.
They’re designed to be immediately applicable for the complete TouchDesigner beginner, while also providing inspiration for the advanced user.
Tweak the fluids!
Now is where the real fun begins. With our simulation all setup, we can dive into playing with the actual parameters of the Flex solver. Some cool things you can do:
- Adjust the Particle Radius, Dissipation, Damping, Viscosity, and all the options on the Properties page of parameters on the Flex Solver COMP to tweak how the particles behave
- Increase the amount of particles on the Actor COMP Flex parameter page
- Increase the Number of Substeps and Number of Iterations on the Solver parameters of the Flex Solver COMP
- Try different bounding boxes (polygonal spheres work very well!)
- Try different emission actors
And the list goes on of things you can try! You can make thick fluids, thin ones, heavy ones, light ones, clumpy ones, smooth ones. All kinds of things! I did a bit of tweaking to the above parameters and got this interesting variation:
nVidia Flex in TouchDesigner: Next steps
Now that you have a little bit of comfort with setting up nVidia Flex, I’d recommend you read the Wiki to get more intricate details about it. There are many great Operator Snippets as well you can access in the top Help menu that have real-time running examples you can learn from.
If you follow this guide, you should be up and running with the new nVidia Flex Solver in TouchDesigner in about 5-10 minutes! From there you should have a little bit of familiarity with the setup so that you can dive into Operator Snippets or other resources that can help take you deeper into the world of particle-based fluid simulations. Enjoy!