YL2 - Soft body physics odyssey

odesodes Administrator
Hi all!

We hope you're doing great!

After last month's intense work on the character creator, we were quite exhausted and wanted to take some time off. So of course I spent this time creating a custom soft body physics engine, LOL. :)

Before you get your hopes up - no, we still don't have a viable method for soft characters in YL2. But this work goes to show our commitment to getting fat simulation into the app as well as reducing clipping.

Read on to discover what we have tried so far and where we may go in the future.

Soft body dynamics

Soft body dynamics is a huge topic covering the behaviour of so called "soft bodies". Unlike "rigid bodies", soft bodies are able to deform (change their shape) to adapt to external influences. This makes them suitable for simulating cloth, balloons, jelly and rubber. Our hope was that we could try to adapt this technique to work on characters.

Previous work

Soft body physics is something we have touched on before. In our previous attempt at it, we were using a very fake method to achieve this effect:

https://gyazo.com/3da2ad8fe37942de4b6824285000265d

While it may look OK for this very specific scenario, this is not a "proper" soft body system, but rather a simple shader trick. Each vertex has no concept of its neighbors. This means if you were to texture the object, distortion would become very apparent:

(Surface is distorted by this method, which is easily noticeable on a textured surface.Open the link below.)

https://gyazo.com/52e523011ae7b9e43ce740daa1049a44

This method also doesn't handle multiple collisions very well, and can start clipping if too many objects interact with it:

(Multiple intersections not working as one would expect. Notice that the cube doesn't start to "take" until it has already clipped quite a bit through the object. Open the linkbelow.)

https://gyazo.com/afdaf95b5a983de9dc6bf57a6b1d6f0c

It's also challenging to get this technique to work universally on characters. Since we're not relying on physics but tricks, it means we have to do tons of "fake" tweaking to make it look good, and even then there will probably undesirable behaviour in certain circumstances.

Soft body realtime simulation

"Real" soft body dynamics (not the shader trick above) is very computationally heavy, which is why it has previously been the domain of film and other pre-rendered media. However, with modern hardware and greatly parallelized algorithms (often times accelerated by GPUs) this is now becoming feasible to do in real time.

Existing libraries

There are already several external libraries handling soft body dynamics in Unity. Currently, "NVIDIA Flex" and "Obi Soft body" are the two main contenders, but there have been more. Sadly, because of the very difficult and niche nature of soft body physics, the market for it doesn't seem to be the most lucrative. Several soft body libraries have been made for Unity only to be discontinued from what I assume is lack of funding and consumer interest.

Problems with external libraries

While current soft body libraries are very featured and optimized, they have the huge draw back that they're not designed with changing objects in mind. You're only meant to initialize a soft body once and then put into the simulation. That is a big problem for us, since we need to be able to support inflation, which essentially alters the shape of the character and thus would require a reinitialization. While it is possible to reinitialize shapes in these libraries, you're not meant to do it frequently, more as a pre-computation step, so there is a significant hiccup each time you do so. Furthermore, the particles are reset in the process.

Obi also has the drawback that it runs on the CPU, and since we have a custom method for skinning that runs on the GPU, it means we would have to fetch data from the GPU, process it through Obi on CPU, and then push it back to GPU which is a very slow thing to do.

Custom solution

By creating a custom soft body physics engine, we are free to design it with inflation in mind from the very start, so we're able to change shapes in it with virtually no penalty.

For the past couple of months, I've been reading up like crazy on the latest research regarding real time soft body dynamics. After our intense work on the character creator, I felt like I was about to burst unless I got a chance try out my ideas. So with the "time off", it felt like a perfect opportunity to finally have a stab at it.

Custom soft body physics engine - Results

NOTE! We recommend opening the gyazo links below each image for the experience.

Essentially how a modern soft body physics engine work is through so called "constraints". Each constraint has a very specific purpose, such as limiting the distance between particles. The engine then just steps through all the particles, applies the constraints, while also applying things like gravity and checking for collisions.

The core engine and its constraints took about two weeks to implement. We started with simple balls, which is like the "hello world" of soft body physics, before moving on to more complex shapes.

Firstly, we just wanted to get gravity, velocity and collision going:

(A soft body, w/o any constraints, colliding with a sphere.)

https://gyazo.com/9a2afdf5dd28aa29e39074172aaf709c


(Same scenario, but this time a constraint limiting distance between neighboring vertices has been added to the simulation.)

https://gyazo.com/1639f28b9f205fe899758d2455367f02

Each collider shape had to be manually implemented into our custom physics engine. Sphere is the most simple shape, but eventually we managed to get all the math and algorithms to handle box colliders as well:

(Collision against box colliders.)

https://gyazo.com/03f647c02170c10487dbed0de0676f07

Next, we started working on more constraints to better approximate a soft body ball:

(A volume constraint trying to retain the object's initial volume by simulating internal pressure.)

https://gyazo.com/3835cea594b65f3f7ed1ff967b04e2bb


(Volume constraint being applied in slow motion.)

https://gyazo.com/da63011dce8caebfb5612aad1683ba44


(A bending constraint trying to retain each triangle's angle towards neighboring triangles.)

https://gyazo.com/9b78d74ba02b9a53130e498fbba71e99


(Volume constraint + bending constraint working together.)

https://gyazo.com/dec985065be55b2b46f89f142e31dad7

(Volume + bending in slow motion. Unfortunately an older iteration, but couldn't find a more recent recording.)

https://gyazo.com/e4e956cd225acb48fa89519d1e51ebf9


(Volume + bending later iteration performance test.)

https://gyazo.com/1b3e655a9fef6d1be9e11485d4168529


(First test of soft bodies interacting with eachother using sphere proxies.)

https://gyazo.com/ef8486937a92598ae8dc97a14c0fc198


(Later iteration on soft body vs soft body collision. Using different method to better approximate collision.)

https://gyazo.com/e22995dae8bfb66d567212441de79504


(Same as above but placed closer to eachother.)

https://gyazo.com/dc499e5339482d3c0472a41c8ef6152d


(Performance test.)

https://gyazo.com/1b898e6627efba1deab955108cfe7357

Results characters

By the time we had these results, we started feeling ready to try and apply these effects on a character.

(Smashing a cube into the butt cheeks of a simulated soft character.)

https://gyazo.com/bc0d8b2ce54bc385a613d0df6bc96d0a


(There is an invisible collider on her right side, in case you wonder why her right butt cheek is being affected.)

https://gyazo.com/635edbc90011b7aaaebf7ff668abcb4f


https://gyazo.com/6276c7ec78ed00497fbc7f0a271ea4ad


https://gyazo.com/2800aed047043296a22c710d55626f02

Despite the wobbliness, there's something fun and appealing about it. But it's definitely too wobbly to be viable, unfortunately. Of course we are able to make it less wobbly and make it match the skinned position more closely, however, that would also loose its soft behavior, which is why we wanted to do this in the frist place. And this is the core of the problem which we are facing with this tech - how do we actually combine soft body physics with an animated character?

Next, we tested the very scenario that made us go for our own custom implementation in the first place - inflation.

(Belly being inflated while an obstacle is in the way. Open the link below.)

https://gyazo.com/5f1e7665f6d64e4c6372fefe9c15764d


(Smashing a box into an inflated belly. Open the link below.)

https://gyazo.com/7a1ee621ed054765849277b1ffe9a8d8


(Inflated belly reacting to multiple collider influences, and correctly adjusting its shape w/o any clipping. Open the link below.)

https://gyazo.com/025ffe3a93817aa3d0476ea666a88d1d

Even though the tech is far too wobbly to be viable, it was still fun to see it fully realized in regards to inflation.

In case you weren't convinced about the problems with this tech - a final video:

(Things going crazy when trying to match a position. Open the link below.)

https://gyazo.com/b6d3d0d061b9502bb5bdc9329d3779ff

Again, the big question here is how we're supposed to combine this technique with animated characters, because as you can see here, when moving the character around, things get crazy, and it's not simple to solve by just tweaking variables. It may very well be that this tech is fundamentally unsuitable for this type of problem, which is not necessarily that surprising when thinking about it. Essentially what we're doing here is simulating a surface and an internal pressure. But that's not how bodies work. A body is made up of bones and flesh, not a surface inflated by air. So it's not surprising this doesn't behave as flesh and bones.

Perhaps another approach to solve this problem could be to use something like NVIDIA Flex does, with simulations of volume (voxelized shapes) rather than surface. However, then we're back to square one with how we're supposed to reinitialize a voxlized soft body to match a new shape (after inflation is applied) in a fast and efficient manner, not to mention how translation between the old voxelized shape and the new one is supposed to work in order to retain particle state.

Future

Perhaps a future approach could be something more like our original one, with using a simple constraint to offset vertices, but maybe there's a way to do it without causing so much distortion. Or perhaps there's a way to combine these two technologies into a new one.

While this soft body implementation didn't pan out the way we were hoping, I'm still happy I spent this time working on it. I needed to try out these ideas. Now when we know it isn't a viable path, we are free to explore other options. We've learnt a lot from implementing it.

We may also be able to salvage parts of it, or perhaps use it for other things than characters (like cloth).

Summary

This month, we took some time off working on the character editor, and instead went back to exploring soft body physics. We implemented our own soft body physics engine. While the results are quite fun, they aren't what we were looking for. It seems we will have to look elsewhere for a more viable method.

Enjoy your weekend!

Comments

  • You have too much fun with physics xD
  • what about using some kind of texture that holds information about areas that are to be affected by soft-body sim? if this is technically possible, then youll be able to sketch where fat is supposed to be. such map could also be a real map, so that would allow for super squishy butts but also not so super squishy, ehh, tails maybe?
  • that's what I was thinking, is it possible to apply soft body physics only to certain parts (breasts, butts, bellies, etc.)? and even if not, it might be interesting if one wanted to make goo characters.

    anyways, you guys are amazing, even if the results aren't what you wanted you are exploring so many things that other developers don't even care or even think about. you are basically at the frontier of 3d erotic game development, be proud of yourselves
  • https://vimeo.com/228247052
    Try using it in the muscle system? It looks like the muscle editor will at the same time adjust the mesh of the main mesh.
  • odesodes Administrator
    @ratrei-ganart
    @kroch

    Some fans were asking the same thing on our patreon post. Copy pasting answer from patreon:

    We actually do have weighting! You might have noticed that the legs, arms and head are not moving. When we first started testing this, we made a weighting like this:
    https://gyazo.com/0d6206c2eebd5e3df218fd1e8890dfd2 https://gyazo.com/2b8e17f493832abee3bfad0f99984980

    Unfortunately, this did not look any good at all when interacting with objects: https://gyazo.com/67895eaaacc6aeccd43f5ea983c09202

    Furthermore, the base problem was still present. Sure, it's localized to a smaller area, but it's still there:
    https://gyazo.com/1b525be78b939fbf67bdd59c286a7266

    (Here, we're also playing around with a stiffness property, affecting just how closely it should try to match skinned position.) Instead, we finally ended up on a weighting like this:
    https://gyazo.com/a52019b74002b95b3818f319f188484e https://gyazo.com/92c1d5706592b0538f31257f3eef7219

    Still just a test of course, but it worked the best in regards to responding to objects. The fundamental problem is that the kind of weighting we need to do is not one on the surface, but rather one inside the actual body itself (volume). That way, bones would be fully weighted, and particles next to bones would also be quite stiff but would become more and more loose the farther away from bones they are. However, such an approach has its own set of problems, as explained in the main post.
  • @odes
    This is crazy. I finally got yiffalicious 1.0 to run on my Mac and it runs great! I am excited for the second edition, but I'm not sure I have the specs to run YL2. What would you reccomend?
  • odesodes Administrator
    @Onebiglotus
    YL2 will rely heavily on modern features such as compute shaders, which are only supported on DX11 hardware or equivalent. (For now, Windows is the only target platform.)

    I think YL2 will run on any DX11 hardware with 2048MB dedicated VRAM or more. So roughly a decent gaming rig that's 5 years old or newer.
  • I feel like you pushed for no collisions too hard, without doing a volumetric solution I'm not sure you'll get what you want. Do you have a way of limiting or scaling the velocity vector on these vertices, or particles or whatever, so they don't spaz around so much and instead are gently pushed around? As it is they have no inertia, basically only surface tension and a bit of simulated internal pressure, which you could probably turn up a bit, so they can deform as much as they need to to not collide, but this also means they receive arbitrarily large amounts of force and jiggle like a bubble. As long as the interactions are slow and gentle I think they look really good, but fast hard interactions make the membrane move too fast, so limiting the velocity or having a logarithmic scaling system to slow it down and allow clipping might work. Also having some sliders for these values, and being able to turn the physics on or off depending on the scene and how aggressive the interactions are would go a long way. I for one would still like this as an option, it could still be very impressive for small scale jiggle physics and vr interactions. Also have you seen this
  • Wow I love seeing you guys at work, I can see alot of potential with this element.
    It would be great if there was VR interaction support in the future so that hypothetically you could jiggle the mesh in places manually and smush parts together or grab with both Virtual hands. Any hopes for something like that in the future?
  • @SaltyArts I also hope that comprehensive VR support is something added later down the line, once everything else is more set in stone. With the Valve Index Controllers (Knuckles finger tracking controllers) coming out, the amount of interaction a VR user could have would be incredible! But even basic touching with Vive wands or Rift controllers would be great to see. The VR mode in Yiffalicious 1 would have been exponentially better if it let you affect the jiggly bits with VR controllers.
  • edited May 7
    so if I'm understanding this right, YL2 will allos us to make actual titfuck and hotdogging animations with no clipping tricks being used, additionally we could have things like breasts pressed up against glass or bondage devices distorting breasts, or spanking having actual jiggle impact.
  • where's next update? 
Sign In or Register to comment.