Vivace implementation for fast cloths and soft bodies simulation

The current implementation of the current algorithm that, I think, it’s the “Fast Simulation of Mass-Spring Systems”

I’d like to propose the idea of using its successors, like the Projective Dynamics framework or, for an eventual future, the more general and sophisticated Quasi-newton methods for hyperelastic material

This new implementation should be way more stable than the current one and it will avoid the explosions seen when the iteration count is too slow and, also, the simulation, through the algorithm Vivace, can be speed up considerably using multicore CPUs or even GPUs, by one or more order of magnitude.

On top of this a simple modification of the collision detection and reaction (as described in the Nucleus paper and by Provot), using continuous detection directly on the vertices and the faces of the dynamic objects and the collides may lead to a simple but effective two way coupling between all rigid and soft bodies, still reusing a big part of the current collision detection implementation

But there is more, this framework would unify all the soft bodies simulations in a single framework: cloths, soft bodies and hair simulation!

Lemme know what you think :slight_smile:

Currently I’m working on a C++ implementation of the Projective Dynamics framework as DLL for unity, but I wouldn’t mind to find a way, once it works properly, to insert it in the current cloth modifier

Reference material for the proposed implementation:

Hyperelastic materials simulation:

9 Likes

Better and faster cloth simulation would definitely be good for Blender, we can use help with improving our physics systems in general. The tricky part is always going from the initial implementation to one that is production ready and can replace the existing solver.

One thing that’s not entirely clear to me with projective dynamics is if it can handle the various spring types that are needed for realistic cloth, and if it can efficiently simulate inextensible cloth. At a quick glance I didn’t see these types of cloth simulations in the links, but that doesn’t mean it’s not possible.

Blender’s cloth simulations is quite a bit older than the paper you linked, see here for what it is based on:

1 Like

Ah, that implementation is way older than I imagined

Yes, PD can definitely handle the same springs type used in the current implementation of blender, the main difference is that they’ll become constraints, like:

  • Spring constraints: given two vertex and an edge, the length of the edge has to be preserved
  • Bending constraints: given two triangles with a common edge, the angle between the triangles has to be preserved
  • Collision constraints
  • Tetrahedral constraints: given 4 vertices in a Tetrahedral, the volume has to be preserved (this for the soft bodies)
  • Custom constraints: almost anything you can think of (whole volume, area per triangle, position per vertex and so on)

PD and almost everything that comes after are extensions in a way or in the other of the Position Based Dynamics framework, which assumes infinitely stiff materials, PD extends it to the Hook’s law (but, still, inextensible clothes are possible), then all the quasi-newton methods extends it even further to hyperelastic material

The nice part of all of this is that the simulation is intrinsically stable other than quick so, eventually, it would be even having a new workflow for physically based animations

Good idea. I’ve been playing around with a few ways recently of adding volumetric behaviour and self collision to characters. As a result I’ve started to research physics sims as well (mostly pbd at this stage). I think there is a lot of potential for something like this as a flexible softbody system in blender.

@TTNK I have been very frustrated by the slow soft body simulations in Blender as my entire work depends on it. I’ve thought about switching to some other physics engines but each have their own issues (some are fast, but very unreal, some are particle-based which is not suitable for our task etc). Are you planning to implement the new soft body system for sure? Although I don’t know that much on how these stuff are implemented but I would love to give help! Please keep us posted! A faster physics simulation is definitely needed in Blender.

@TTNK @brecht I think the Projective Dynamic approach is the way to go. I did some more research and found a couple of very interesting, follow-up papers. It’s amazing that the progress in the past couple of years is enabling people to do soft body physics simulations much closer to real-time, or some cases in real-time!

Projective Dynamics is an alternative to Newtonian dynamics but does not have damping. In this work, they add damping to it. Here’s the link to their project which includes a nice video demonstrating their work.

In another work, they proposed something called “FEPR” (Fast Energy Projection) which stabilizes simulations and energy fluctuations. They explicitly say that this method can be integrated with “standard collision handling techniques” which is necessary! They have a nice video for this one as well:

They also have another relevant work.

As the authors say, another limitation of Projective Dynamics is that it only supports some basic material. I don’t know what the mean clearly by that but it might mean that Projective Dynamics might only work with some range of elasticity/spring parameters. They seem to resolve this in their new work.

A consideration is how realistic are the soft body physics that they show compared to real-world physics? I wish it was possible to somehow match their results with real-world soft body physics. In some cases they show that their method is able to achieve almost exactly what the “exact solution” achieves but it might turn out that the physics simulations shown in their methods are pretty off of real-world physics, which still might be okay for the purpose of making a funny animation.

1 Like

Currently I’m working in my free time on a C++ library for Unity that I’m trying to make as agnostic as possible from the data structure used and, more or less, I can say so far that the Position Based Dynamics is now part of my knowledge, next step would be implementing the Projective Dynamics framework and make it work properly, which is kinda happening, but with a lot of pain, luckily I have all the playlist of Physically based animation courses on this channel helping me https://www.youtube.com/user/kavanl1/playlists
but, still it’s a pain without a more proper background

A little note, all of this are particle based simulations for soft bodies, basically they are moving systems made of masses and springs

And they keep adding breakthroughs every 6 months or so :smiley:

A couple of notes to add to what you said:

  • Projective Dynamics HAS damping, due to the integration method used, the Implicit Euler, which is damped, in the two first papers you show the researchers used the Implicit Midpoind, which is not damped, but it can explode sometimes, those paper avoid the explosions

  • With basic materials they intend simple springs based on Hook’s law, which is usually good enough, but, for instance, flesh doesn’t follow that low, they are so called hyperelastic materials, the stretching is not proportional to the force, ADMM and L-BFGS address this problem with a new formulation

In theory the best solution would be, in my opinion, the parallelized implementation of the Quasi Newton Method for hyperelastic materials, which should be, I think, an actual FEM simulation on steroids, so, not only you’ll have plausible motions in real time, but, increasing the precision, you should have the equivalent of a physically accurate physic simulation, basically you should be able to make a valid crash test inside blender :smiley:

On a closer future, though, I’d bet my money and my time on the Vivace paper for PBD and PD, that will give extremely fast and intrinsically stable simulation on GPU and multicore CPUs, at the price of not having a complete framework for a wide range of materials, but, at least, it will be easier to implement in a way shorter time, even with my current knowledge on mechanical dynamics

(Of course, I wouldn’t mind some help to speed up the building of the C++ library and to substitute the current soft bodies and cloth and hair simulation with this framework in a separate branch of blender :slight_smile: )

1 Like

After reading your post I realized that I hadn’t fully understood some of these papers as my knowledge of physics simulators is not good enough. It looks like you know what you’re doing :smiley: and I look forward to that branch! Thanks for doing this!

1 Like

@TTNK I assume if we get to a blender implementation you will fork your unity library and we can try and get something that is tightly integrated with blender?

Also I don’t know whether you have seen it, but one of the authors of the ADMM paper has sample code on github: https://github.com/mattoverby/admm-elastic. It also appears to have an implementation (or at least some code for) spline based materials http://run.usc.edu/isotropicMaterialEditor/ which look really interesting for modelling differrent/more sophisticated elastic materials.

If this ends up happening I guess we will need to look at how we can manage volumetric meshes in blender as well.

1 Like

I truly hope so, because, as always, the more I know, the less I understand :smiley:

But, thank to that guy on youtube and his whole courses on physically based animation, it’s quite easy to have a decent grasp on the whole topic

Sure thing as soon as I can make it work at least decently

Yes, I already saw that code, but it’s quite a mess and I’d prefer to start from scratch, also because, as already said by its author, it’s not exactly optimized for speed.
For now, though, I’m moving toward the Vivace algorithm, just to have the maximum robustness and speed, and also because I’ve finally understood it completely. True that it won’t be as generic as one of the latest methods, but, at least, they all share the same underlying idea

For the volumetric meshes in blender, it shouldn’t be too hard, a voronoi tessellation generated with CGAL will make the job incredibly easy

Here’s an implementation of L-BFGS in C++. Might be handy :slightly_smiling_face:

That will be useful for when I’ll have a better grasp on variation integrator, very useful :smiley:

But, while waiting for that, this guy seems to have already done the simpler Position Based Dynamic framework, it just need an extension for the collision handling https://github.com/korzen/PositionBasedDynamics-ElasticRod

There is also https://github.com/InteractiveComputerGraphics/PositionBasedDynamics for a fairly complete implementation heaps of different constraints. It also includes fluid and rigid body implementations.

@TTNK @Jack_Simpson Here’s an implementation of Projective Dynamics in C++ by a former master’s student at Penn State.

Ironically that is exactly what I’m trying to do as first iteration right now, with only a tiny difference, this library seems to work, with all the features already implemented, even the parallel computation described in the Vivace paper seems present. This library is already ready to be used in blender fro cloths, soft bodies and even hair

Heh, its a pity that one is only PBD rather than projective dynamics. But yeah, its a great source of examples at very least. In conjunction with the PDB overview at http://interactive-graphics.de/index.php/research/89-position-based-simulation-methods-in-computer-graphics, it covers pretty much everything you’ll need to know about PBD with the exception of the XPDB (http://mmacklin.com/xpbd.pdf) which gives better approximation of soft constraints (in my experiments so far it still seems somewhat sensitive to constraint steps, although I’m not quite sure whether I’ve got it quite right either).

Actually this library can go a step beyond XPBD thank to this Muller’s paper (Strain-based Dynamics) implemented into the library, but, in case, XPBD just requires another variable in the constraint definition (already present in one of the library forks)

Really, the only thing that this library lacks are the faster convergence of Projective Dynamics and the hyperelastic material simulation that come with more sophisticated algorithm.

Basically this library is ready to substitute the current softbodies/cloth/hair simulation (even collision detection) for 2.8 release of blender in a plug-and-play manner and in matter of days if you knows the structure of the current implementation (input/output/collision management)

Cool, I didn’t look through the forks, I’ll have poke through it at some point.
(I assume its https://github.com/nervoussystem/PositionBasedDynamics/tree/xpbd or is there another as well?)

XPDB is trying to solve a different problem than strain based dynamics I think? XPBD is primarily an attempt to alleviate issues with increase constraint solver iteration count effectively leading to increased stiffness of constraints.