Biggest game dev breakthrough of the decade - AVBD - when is it coming to Unity?

How refreshing to have something non-AI related to be amazed at!

If you’ve not heard of it, here’s the “2-minute” paper: AVBD

There’s also a browser demo of it, though it’s currently down (presumably it’s been hit by massive load).

The demo source can be built and run locally very easily - took me a few mins (had to install cmake, and download SDL etc).

So, when is it coming to Unity?

I’ve actually already ported the demo to C# and have it working, but the performance is not great because I’ve not added multi-threading or GFX support.

If you don’t see it on Unity’s roadmap, this is your opportunity to implement a great version of it yourself, publish it on the asset store and make millions of … well, millions of something.

Yen perhaps?

I’m afraid that opportunity is already taken:

This is also a vertex (points) based physics simulation. It may not be the exact same thing but it exists, works and isn’t just a white paper with artificial demos. You can use it right now. I love these for anything that needs cloth, rope, softness and fluids. :wink:

I have used Obi extensively. It is fantastic. However, I don’t think it’s the same thing.

Obi models everything as particles.

AVBD allows more conventional modelling of polygon-based shapes.

So, if anything, I would imagine it would be more straightforward to modify conventional physics engines to use AVBD then it would to modify Obi.

Nevertheless, I imagine that AVBD could be used to enhance Obi performance. Though it may be that it’s already doing something similar that hasn’t quite been formalised in the same way, given how well Obi performs.

Like I mentioned, I have ported the C++ demo of AVBD to C# successfully; however, performance is greatly limited by the fact that the demo is single-threaded (and C++ does perform a lot better than my C# port - maybe 2-3x as fast).

I suspect that taking the demo, parallelising it, and then turning it into a feature-complete engine/library would be orders of magnitude more work than taking an existing engine (e.g. the one that comes with Unity), and modifying it to use the new approach.

Hence asking when it will come to Unity. :slight_smile:

I also quickly threw it into Unity, its not working 100% though, mainly sometimes the bodies go through the ground, also the motor scene is borked.

avbd_2d_demo_port

Maybe somebody can see where I messed it up. Was thinking of trying to stick it in a compute shader next.

This is true, both approaches (XPBD and the new AVBD) are supposed to do the same thing, both are particle based simulations for physics. However, AVBD seems to solve one of the biggest issue in softbody simulations, which is stretch of constraints on low iteration count. This means more stable physics at lower computational costs.

Taking this basic solver algorithm and building a full physics engine around this takes years for multiple engineers. See PhysX 5.

I was able to port it to Unity successfully (all the scenes seem to work correctly); however, this was basically just directly converting the C++ code to C#, and therefore it uses its own structs (e.g. Foat2x2) instead of those that come with Unity.Mathematics (e.g. float2x2 - note the lower case).

I want to also migrate it to using Unity.Mathematics, so that I can then use Burst and get some decent performance; however, my first attempt borked it in a way similar to what you described: objects falling through the ground etc.

On closer inspection, the complication is that the example’s matrices are row-major, whereas Unity.Mathetmatics uses column major matrices. I hoped this was as simple as a different internal representation of the data; however, it appears that some things are actually different (e.g. multiplying a 2x2 matrix by a float2 means something different depending on which scheme you’re using).

Is it possible that this could be a similar issue to what you’ve encountered?

Anyway, I’ve reverted to my original working port, and am attempting again. This time, I’m adding a bunch of unit tests. Fingers crossed that it will work this time.

super interesting! Looking forward to testing your implementation when it’s ready (in case you want to make it public at some point) :slight_smile:

If C# in Unity already only works 2-3 times slower, a Burst version should easily surpass the C++ even without perfect multithreading usage o:

Definitely looks impressive from that video. Said video also mentions execution on GPUs, which may be even better but of course often also trickier to develop.

Hi! Jose here, Obi’s author.

Obi uses XPBD. It’s just that Obi restricts itself to ellipsoidal particles, but nothing prevents it from using rigidbodies instead - in fact it already performs its own rigidbody simulation to interact with Unity rigidbodies.

I’ve also implemented AVBD (in a toy sandbox written in Processing) for testing purposes. (X)PBD and (A)VBD are close cousins: both are position based methods, and both can work on vertices/particles (mathematically they’re the exact same thing, a position in space) as well as rigidbodies (position + orientation, regardless of whether their collision geometry is determined by polygons, SDFs, or analytic shapes). I’ll call all of these these things “bodies” for simplicity.

Both methods work by adjusting body positions/orientations, instead of linear/angular velocities like traditional solvers. There’s quite a few differences between both, but one of the most significant ones is that (X)PBD is a dual method, while (A)VBD is a primal one. What does this mean? it has to do with the relationship between bodies and constraints (equations that relate bodies to each other). PBD does this:

for each constraint
   for each body affected by the constraint
      CalculateAndApplyCorrectionToBody();

While VBD does this:

for each body
   for each constraint affecting the body 
      CalculateAndApplyCorrectionToBody();

(This is very dumbed down but will suffice). When you parallelize the outer loop of both methods, XPBD may have multiple constraints that affect the same body, resulting in race conditions. To avoid them, it’s necessary to either:

  1. Use atomics to apply corrections.
  2. Store corrections and only apply them once the loop is done (Jacobi style solver, not desirable because of slow convergence/stretching)
  3. Group constraints that do not share bodies so we can do all constraints in each group in parallel - but groups are processed sequentially, so the fewer groups we end up with the better. (Gauss-seidel style solver, using graph coloring)

Out of these, the third option is usually the best since it results in stiffer constraints and doesn’t require thread synchronization. AVBD however has it easier here, since each body calculates and applies its own corrections. So if we go for option #3 in AVBD, we don’t need to group constraints based on which bodies they share: instead we need to group bodies based on which constraints they share. And not because threads would step on each other’s toes - they wouldn’t-, but because we want bodies to use the most up-to-date neighbor data to speed up convergence. In graph theory, the former is called a dual graph, and the latter a primal graph. Coloring (grouping by adjacency) the primal graph results in fewer groups/colors than coloring its dual, so we get better parallelism.

However, this doesn’t apply in all cases. For instance, 1-dimensional objects like ropes yield linear primal graphs, which can be colored using only 2 colors just like their dual counterpart. 2D objects such as cloth tend to yield a small number of colors for both the primal and dual graphs. So in these cases, both methods perform similarly (if correctly implemented). Volumetric softbodies (tetrahedra-based ones) and large rigidbody simulations with lots of collisions tend to be where AVBD can reap most benefits, as they have the most edges in the primal graph.

So is VBD a breaktrough? Imho, time will tell. Compared to PBD, it has strengths (better high mass ratio resilience, better parallelism in some cases) and weaknesses (higher cost if poorly parallelized/not parallelized, more cumbersome to implement, fiddly parameters, when it breaks it breaks way worse). Overall both methods serve the exact same use cases, and both can simulate softbodies and rigidbodies. From a theoretical standpoint AVBD seems to be the better option. However, there’s a lot of literature on XPBD, it’s been implemented in lots of software (Houdini, RealFlow, Maya, etc) and battle tested to the point of becoming an industry standard, so we’ll have to wait for AVBD to reach a similar status.

However, AVBD seems to solve one of the biggest issue in softbody simulations, which is stretch of constraints on low iteration count.

AVBD exhibits less stretching in case of large mass ratios, but when object masses are similar convergence speed - and hence stretching - is comparable to XPBD. On the other hand, AVBD has convergence issues with large stiffness ratios: it’s a “pick your poison” situation. Would not be a stretch (pun intended) to think of them as both sides of the same coin.

You can improve AVBD’s convergence speed and resilience against large stiffness ratios using warmstarting (see the AVDB paper), and you can improve XPBD’s convergence speed and resilience against large mass ratios using substeps instead of iterations (the difference this makes is staggering!). As a side note, this is what the Temporal Gauss Seidel (TGS) solver in PhysX does: use substepping instead of iterations.

Not really. Conventional physics engines (PhysX, Havok, Bullet, Box2D) tend to be impulse/velocity-based, so you’d have to basically rewrite the entire thing. Only the collision detection stuff would be left untouched.

Obi is position-based, so a bit closer to AVBD than traditional engines. Some data shuffling and rewriting constraint functions would turn it into AVDB, but based on my experience with AVBD I’m keeping it XPBD for the time being. Could also add other collision geometry for particles besides ellipsoids to take it a step closer to a “fully fledged” (whatever that means) engine - but that has absolutely nothing to do with the simulation method used, be it AVBD or XPBD.

Note that what makes a rigidbody engine a rigidbody engine is not the shape of the bodies it simulates - it could only simulate spheres and still be a rigidbody engine. It’s the fact that rigidbodies have rotational information: an arbitrary center of mass, an inertia tensor, angular velocity, etc. which vertices/particles generally do not. The shape of the bodies and the kind of collision detection you use are completely orthogonal to the simulation method - you could use AVDB, XPBD, ADMM, Sequential Impulses, or any other method you choose then pair it with collision detection based on spheres, boxes, convex polytopes or arbitrary shapes (triangle meshes or sdfs).