Distance Field Soft Bodies

Hi everyone,

Today I made a little test using the master branch of Unreal Engine. The idea was to mimic the effect of soft bodies by using the new “DistanceToNearestSurface” node.

Here is the result:

Since it uses the material to deform it, it is completely fake, but I still think it looks pretty good. I’m not using it myself for anything, so if you need it or would just like to give it a try here is my content package:
www.roelbartstra.com/resources/downloads/distancefieldsoftbodies.zip

It is created on the master branch. It does not work with the latest version in the launcher 4.8 preview 4!!!

Here is the material overview:

If you want more accurate physics results you could maybe try making a physics repulsor per sphere.

Feel free to ask any questions and ENJOY!

2 Likes

Awwww this is so awesome!

Can’t wait to use it in 4.8 w/ a shield deformation effect I had in mind, this distance field feature is just too cool!

Oh my god, you’re genius! Thanks!
Time to resurrect my little jelly!

DistanceToNearestSurface node sounds like it’s going to be crazy versatile, it could be used for seafoam, clouds going around buildings/mountains, maybe even change how your character moves when it gets close to a wall.

This is a really inventive use of the global distance field! Awesome stuff.

Well you can only sample it on the GPU in a material graph, so it needs to be visual-only effects. 's soft body approximation is just a visual effect, the actual collision between the balls is using the standard physics.

One thing I am curious about , are the spheres themselves in the distance field? Static meshes are in the distance field by default if they cast shadows and have ‘Affect Distance Field Lighting’ enabled. If the spheres are in the distance field, usually you get a distance of 0 when you do a DistanceToNearestSurface with your own position. But if the spheres aren’t in the distance field, they would not squish each other.

I was thinking about a stealth game where your character cloaks near walls and uncloaks in the open. But you could use it for snow piling up more around buildings, or leaves, or trash.

Wow awesome sample. I donwloaded your contnet file and put its content in the content folder of a blank project. When I tried to open the map like in the video, I found nothing. I opened the contetn folder in the editor and I found nothing there too. How to use the content folder you provided, Thanks. :slight_smile:

Awesome idea!

Distance Fields are going to prove so useful!

Very cool but I can’t open the assets in the UE4 (I put the Uasset on my content fonlder but nothing) any ideas?
This is very cool I have already test the Flex Nvidia soft body but you need to compile the Ue4 source from the ue4 flex branch and I get a lot of but soo that cool to be integreated in the 4.8 :slight_smile: .

For anyone who is having issues running the project. Make sure to take heed of the following text written in the OP: “It is created on the master branch. It does not work with the latest version in the launcher 4.8 preview 4!!!”. So make sure you have the master branch.

I see. Now 4.8 is released and is no longer in preview. Can this now work in the full 4.8 or do we still need the master branch to make it run ?

Cool! Let me know if you run into any issues :slight_smile:

Ah! That explaines the strange results I got at positive location. They all seem to be 0, unless you are inside another distance field, which now that you explain it makes a lot of sense. The colliders are less than half of the actual sphere size. It probably sees it as the nearest surface since you are inside it, which is closer than your own surface since you can’t get inside yourself.

Make sure you are working in the master branch from GitHub. It’s Unreal 4.9.0.

I though this idea was cool, so I made it for you. Hope you like it:

Here is the overview:

I would still suggest also looking into using the depth texture, since it makes more sense from a natural standpoint to base the distortion based on the distance behind the object from the viewers perspective. It also has the benefit of not needing DX11. But I can understand how the distance fields help to make an effect like this more gameplay consistent with distance fields. Especially in multiplayer.

Oh I see how it works now. If you get a value of 0 from DistanceToNearestSurface on your own surface, then you’re not intersecting anything. If you get a negative value, you are intersecting something else.

The cloaking looks awesome, I could definitely seeing a game or power up based around it.

OK , thank you for your time :slight_smile: !

I will check that but for my project I think that I will still with the 4.8.

Very cool work!! :slight_smile:

Hey , would it be possible to get the gradient of the distance field as a vector please? At work we do lots of volume math with sdfs and their gradients (just a simple finite difference).

One example would be dot products with the gradient and an up vector to get masks for the ground that we can remap to get falloffs.

It’s basically a ‘normal to nearest surface’ and would be handy to have it to do more specific effects similar to the cloaking one above (but imaging being able to cloak against just the wall and not the floor which having the gradient would allow us to do)

This is going to be my new favourite node. Just had an idea… will report back in several days…

In the live stream said they used the gradient to calculate the normal for making the GPU particle collision. I would really like to know how this is done with that node.

this threads got some good stuff in it:)

I’m pretty sure both nodes exist as per this image from the engine features preview:

02.png&d=1432909197

I’m building master right now to test it since it seems absolute world position is broken in promoted right now…