Skip to main content

Nvidia Flex

Ω Nvidia introduced a fancy new technology called Flex back in 2013-2014.  It is a position based constrained particle simulation library that takes advantage of GPU calculations, and it blew our minds back then (at least mine) - all those pretty water simulations running real-time... I personally thought this tech will make it's way into production software pretty fast and save us all from heavy slow water and softbody simulations.
And it did not happen.
And i completely forgot about flex until just recently. I stumbled upon this pedrocabrera's videos and remembered about the existence of flex. Looks like with years it got some improvement but overall remained the same GPU particle based simulation library for mostly real-time applications.
By coincidence i just started learning HDK, so that was a nice testing opportunity, since Pedro decided for some reason to make a Softimage (R.I.P.) integration.

So here are a couple of my thoughts on this library and why it will not replace any existing production solver:
  1. It is bound to GPU. worse - to D3D or CUDA, so either only Windows OS, or only Nvidia hardware
  2. It is not designed to be deterministic - so each run of the same sim with exactly the same parameters will yield different results (cuz who cares in games)
  3. It is designed to work best with preliminary allocated fixed memory blocks of hardware-optimized data layout that stay on GPU as long as possible and even rendered by D3D from the same GPU memory excluding all data transfer costs. All this does not work particularly well with general geometry approach that one would expect from such software as Houdini. So mapping of data structures to and from houdini eats up some part of the whole performance.
  4. It is not designed to work with changing/adaptive timestep or iterations count, moreover the behavior of the sim is highly dependent on the specific timestep and iterations count numbers and will change drastically with the change of those parameters. So you cannot for example setup sim on low iterations/timestep and then crank them up to some production scene settings - you will end up with something behaving completely different. So you have to figure out your timestep and iterations before tweaking other parameters.

So overall it's a very capricious library that is not very intuitive to work with. well, at least it's fast to iterate over different settings...

So far I managed to implement Flex's particles, fluids, phases, springs, rigid shape matching constraints and mesh collision objects. But there are yet some design choices to be made how to translate Flex's inflatable constraints to houdini geometry representation in a way that makes sense.

So here's the whole project with already compiled windows dll: https://github.com/pedohorse/Houdini-NvFlex
Feel free to play with it if you want, I will continue slowly developing it, but i still consider it just a learning project, not something intended for production, but that's just my point of view.
Some convenient HDAs are available now that help create particle representation of the objects that can be fed to flex object.
You may find examples that will help you understand how to work with this solver.
Refer to Nvidia's manual to understand the solver's parameters and constants (also i explained phase constants in comments in the fountain.hip example)

Note that there are some hardware limitations. for example for my laptop if i try to allocate more than 1.3M particles - flex just crashes and switches to invalid state. all sims behave improper (mostly explode) until you restart houdini. (just be sure to resave your scene with less amount of particles. maybe those limitations do not exist on pascal and further chip architectures, unfortunately i had no hardware to test it.
So long story short: you need a high end Nvidia gaming video card to be able to use flex.

Here're some examples of what it can do, simulated on my laptop's 960M (simulation times are under images):

from 0 to 900000+ particles. sim: 7min 39sec.


up to 48000+ points with spring constraints. sim: 2min 18sec.
NvFlex springs


up to 120000+ particles. sim: 2min 40sec
drops


400000+ particles. sim: 2min 41sec
nvf1



messy cloth + soft body:



12k cloth triangles and a little softbody box. drag+lift. sim: 29s