High-quality cloth simulation with NVIDIA PhysX FleX (also Softimage ICE)

Posted in Software on 27 August 2016

This is the first post demonstrating what NVIDIA PhysX FleX is capable of when it comes to high-quality simulations. I'm planning to show how it can be used for all kinds of simulations with the upcoming blog posts. Also a cool demonstration video below.

What is FleX?

NVIDIA PhysX FleX logo

FleX is a particle based simulation framework developed by NVIDIA for real-time visual effects. The idea is the following: instead of a having a bunch of solvers for each type of a body (rigid, soft, fluid, cloth e.t.c.) why not create a unified solver based on the concept of using particles (or “molecules” if you prefer) to represent the bodies? Then, make this solver work on modern GPUs to deliver unprecedented simulation speed and you can actually use the result for real-time simulations in games or interactive presentations.

FleX presentation

Now, we all know what “real-time performance” means when it comes to the “offline” CGI... ;)

Faster simulations!

Even though FleX is targeted more towards real-time applications, turns out it’s perfectly capable of producing some very high-quality offline simulations for commercials and even feature films. At least that’s what I think after using it for a month or so.

FleX is currently available for the following platforms:

  • Windows 32/64 bit
  • Linux 64 bit (like Ubuntu 14.04 LTS and Mint 17.2)
  • Android (TegraK1 & TegraX1 devices)
    [FleX on a mobile! Wow!]

To download you just need to join the NVIDIA Developer Program (it’s free) and get your copy of FleX which is currently at version 1.0 and compatible with all NVIDIA devices capable of CUDA 3.0 and up.

After downloading, do spend some time playing with the demos in the /bin/ folder to really get the idea of what the solver is capable of.

Wish to have a piece of cloth deform under the weight of a fluid? Here you go:

FleX unified solver: cloth and liquid

How about a bunch of cloth objects deforming and interacting in real-time?

FleX many cloth objects interacting real-time

Wish to have rigid and soft bodies interact while submerged into liquid and have liquid produce foam? Easy as Pi:

Stable complex FleX simulation

Pretty amazing, huh?

And stable!

FleX is incredibly robust when it comes to all kinds of simulations! In fact, the longer you play with it, the more you start to actually understand how the real world around you works! It’s like having a sort of a unified field solver under your fingertips: it just works and gives perfectly predictable results whatever you throw at it.

The number of particles you can play with in real-time is staggering to say the least. With my GTX 970 with the solver settings of 4 substeps and 2 iterations I could play with over two hundred thousand particles of different types – rigid, soft, fluids of various viscosity e.t.c. – in more or less real-time while also being able to add new objects to the solver and change solver settings on the fly.

Having had enough fun with the demo I decided to take a simple waving flag simulation I did for a client a year ago using Syflex in Softimage:

Softimage Syflex flag animation by CGI Coffee

And recreate it with FleX while also increasing the complexity and the realism of the simulation on the way.

FleX Softimage ICE Integration

Since FleX comes in the form of a freeware library you can use in your projects, I decided to see how well it would perform in the form of a custom ICE node inside Softimage and what kind of results one could achieve in a reasonable amount of time using a more or less modern GPU to solve complex “offline”-style simulations.

From the FleX manual:

The core solver API is written in C-style, and can be considered a low-level wrapper around the solver internals. In contrast to traditional physics APIs, where operations are carried out on one rigid body or constraint at a time, in Flex, all particles and constraints are sent to the solver in one shot, as flat-arrays. This allows Flex to be efficient when dealing with large numbers of constraints and particles, although it means performing incremental updates can be slower.

Since FleX is a truly unified solver – you can have a single object in the scene which has a Simulated ICE tree simulate everything you connect to it in a single unified simulation environment be it meshes or particles – it will simulate as long as you don’t hit the Max Particle limit (which you can also set yourself just as a crash prevention method, you know).

FleX has a very coherent API so creating a basic integration was pretty straightforward and this is what I ended up with (the node is still very basic and is missing lots of standard FleX features exposed as ports, but it was good enough for what I needed it to do):

Softimage ICE NVIDIA FleX node alpha

The old flag mesh looked like this and consisted of about 3600 points:

Syflex flag low-density simulation

With self-collisions enabled at production Syflex precision settings it simulated at about 1 fps which I thought at the time was relatively fast. Boy, oh boy was I wrong!

I also did a couple of tests with Syflex and a much more dense mesh and don't even want to talk about how long the simulation took...

FleX Flag Fiesta

What I ended up with was the following: a flag mesh of 260x400 quads – that's a hundred thousand points (or particles) – simulated at 20 sub-steps and 10 iterations at a rate of ~2 fps on my GTX 970! And that’s with self-collisions! Due to the nature of the solver self-collisions don’t really slow down the simulation much, which is incredible.

Check out the video for the final result. And as a bonus – gaze upon the bane of every cloth simulation solver in the world – a self-colliding twisting and unraveling piece of cloth simulated with FleX as if it was not a big deal at all.

Note the extreme density of the flag mesh and the stability of the resulting simulation:

FleX dense flag simulation

In fact, the flag mesh is so dense you can only see individual quads by getting up-close:

FleX dense flag wireframe

It’s also amazing to see how well FleX can handle very stiff or non-stretching cloth like a bed sheet for example – a feat you need a lot of time and effort to achieve with classic cloth simulation techniques. I tried doing this with several cloth solvers available on the market but none of them come even close to what you can achieve with FleX by tweaking and producing the final simulation in mere minutes.

The twisting cloth uses 80 sub-steps and 15 iterations for added stiffness and stability due to the fact that it’s deforming quite a while and quite quickly too. The twisting cloth also consists of a bit less particles – 26000 – and even with such a ridiculous number of sub-steps simulates at about 2-3 fps on the same GPU. It’s crazy how actual material, lighting set-up and rendering took me more time than I spent to simulate the meshes!

Bottom line

NVIDIA PhysX FleX is perfectly suitable for “offline”-type simulations where it blows most of other solvers out of the water (get it? =) and has completely changed the way I do simulations.

Today I demonstrated FleX cloth dynamics, and next time there will be some cool fluid simulations.

Stay tuned for more and have fun with FleX!