# Distance Field Soft Bodies

**URL:** <https://forums.unrealengine.com/t/distance-field-soft-bodies/32105>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [June 9, 2015, 9:33pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105 "2015-06-09T21:33:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roel](https://forums.unrealengine.com/u/Roel)\
**Post date:** [June 9, 2015, 9:33pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/1 "2015-06-09T21:33:04Z")

</div>

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:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/5/91536c0b27b2cfe7fd7fdd515e82f3b219d85854.jpeg "Distance Field Soft Bodies") ](https://www.youtube.com/watch?v=shmJIbCayhc)

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:

 ![MaterialOverview.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/c/4c741230278ba3888cda6869432a403319ee4a54.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![Tom\_Looman](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tom_looman/32/1215549_2.png) [@Tom\_Looman](https://forums.unrealengine.com/u/Tom_Looman)\
**Post date:** [June 9, 2015, 11:08pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/2 "2015-06-09T23:08:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![zeOrb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zeOrb](https://forums.unrealengine.com/u/zeOrb)\
**Post date:** [June 10, 2015, 12:21am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/3 "2015-06-10T00:21:13Z")

</div>

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

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/f/e/efedc8c62cc4685ec131e4dc1e3ae10a699d25c3.jpeg "Jelly Night - Movement") ](https://www.youtube.com/watch?v=LPhFS5aUNn0)

---

<div class="post-metadata">

**Author:** ![ZacD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ZacD](https://forums.unrealengine.com/u/ZacD)\
**Post date:** [June 10, 2015, 12:47am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/4 "2015-06-10T00:47:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ZacD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ZacD](https://forums.unrealengine.com/u/ZacD)\
**Post date:** [June 10, 2015, 3:58am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/6 "2015-06-10T03:58:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PLASTICA-MAN](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plastica-man/32/990043_2.png) [@PLASTICA-MAN](https://forums.unrealengine.com/u/PLASTICA-MAN)\
**Post date:** [June 10, 2015, 4:51am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/7 "2015-06-10T04:51:44Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [June 10, 2015, 7:45am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/8 "2015-06-10T07:45:56Z")

</div>

Awesome idea!

Distance Fields are going to prove so useful!

---

<div class="post-metadata">

**Author:** ![Charles200000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Charles200000](https://forums.unrealengine.com/u/Charles200000)\
**Post date:** [June 10, 2015, 11:16am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/9 "2015-06-10T11:16:13Z")

</div>

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 🙂 .

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_bcf66e2c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bcf66e2c](https://forums.unrealengine.com/u/anonymous_user_bcf66e2c)\
**Post date:** [June 10, 2015, 11:38am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/10 "2015-06-10T11:38:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PLASTICA-MAN](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plastica-man/32/990043_2.png) [@PLASTICA-MAN](https://forums.unrealengine.com/u/PLASTICA-MAN)\
**Post date:** [June 10, 2015, 5:39pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/11 "2015-06-10T17:39:52Z")

</div>

> [@;307750](#):
>
> 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 ?

---

<div class="post-metadata">

**Author:** ![Roel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roel](https://forums.unrealengine.com/u/Roel)\
**Post date:** [June 10, 2015, 6:38pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/12 "2015-06-10T18:38:21Z")

</div>

> [@zeOrb;307530](#):
>
> Oh my god, you’re genius! Thanks!  
> Time to resurrect my little jelly!

Cool! Let me know if you run into any issues 🙂

> [@DanielW;307592](#):
>
> 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.

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.

> [@PLASTICA-MAN;307612](#):
>
> 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. 🙂

> [@Charles;307742](#):
>
> 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 🙂 .

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

> [@ZacD;307595](#):
>
> 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.

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

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/2/1a23ced744856b70e3798941957892e391775248.jpeg "Distance Field Cloaking") ](https://www.youtube.com/watch?v=3ScaP9QOE4A)

Here is the overview:

 ![a9ffe807de4dae2c480caf41c173da2f65ee166b.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/9/f/a9ffe807de4dae2c480caf41c173da2f65ee166b.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![ZacD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ZacD](https://forums.unrealengine.com/u/ZacD)\
**Post date:** [June 10, 2015, 10:24pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/14 "2015-06-10T22:24:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Charles200000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Charles200000](https://forums.unrealengine.com/u/Charles200000)\
**Post date:** [June 10, 2015, 10:33pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/15 "2015-06-10T22:33:36Z")

</div>

OK , thank you for your time 🙂 !

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

Very cool work!! 🙂

---

<div class="post-metadata">

**Author:** ![dokipen](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dokipen/32/1145419_2.png) [@dokipen](https://forums.unrealengine.com/u/dokipen)\
**Post date:** [June 11, 2015, 11:21am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/16 "2015-06-11T11:21:57Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [June 11, 2015, 8:06pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/17 "2015-06-11T20:06:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Roel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roel](https://forums.unrealengine.com/u/Roel)\
**Post date:** [June 11, 2015, 8:16pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/18 "2015-06-11T20:16:22Z")

</div>

> [@dokipen;308689](#):
>
> 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)

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f70d3582](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f70d3582](https://forums.unrealengine.com/u/anonymous_user_f70d3582)\
**Post date:** [June 11, 2015, 8:23pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/19 "2015-06-11T20:23:42Z")

</div>

this threads got some good stuff in it:)

---

<div class="post-metadata">

**Author:** ![zalo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zalo](https://forums.unrealengine.com/u/zalo)\
**Post date:** [June 26, 2015, 10:01pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/20 "2015-06-26T22:01:53Z")

</div>

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

![02.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/f/1f6e06fd9142df18a7e35889771888d5160a58fc.png)&d=1432909197

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

---

<div class="post-metadata">

**Author:** ![dokipen](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dokipen/32/1145419_2.png) [@dokipen](https://forums.unrealengine.com/u/dokipen)\
**Post date:** [June 27, 2015, 3:36am UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/22 "2015-06-27T03:36:49Z")

</div>

> [@DanielW;319610](#):
>
> It’s in there!!! DistanceFieldGradient. Gotta normalize if you just want direction only.
> 
> Of course you can compute your own gradient by finite differencing the DistanceToNearestSurface, but this node is faster as it only does the clipmap selection once.
> 
> I would love to know what other use cases you know of for distance + gradient.

I do a lot of custom expression work on particles for simulations at work. One simple case is to get particles to stick to a surface if they penetrate. Another is a ‘tangent force’. It’s two cross products. First you do a a cross product with the gradient and an arbitrary ‘direction’ vector. Then you get that result and cross product it with the original gradient. You get a vector which ‘slides along the surface’ of the original geo and follows its contours. Would be interesting for possible water effects.

Another use case I am thinking of is using them to do a world position offset on a character to do warping effects near other objects. like a gravity/black hole stretching thing or also something giving off heat and making the vertices of other objects wobble with some noise in the direction of the gradient to simulate heat haze.

Also fake monochromatic GI from the world. it would be from everything and with no colour info but used in a subtle way would be like a cheap bounce effect.

---

<div class="post-metadata">

**Author:** ![EnricoUniverse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EnricoUniverse](https://forums.unrealengine.com/u/EnricoUniverse)\
**Post date:** [September 1, 2015, 8:19pm UTC](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105/23 "2015-09-01T20:19:29Z")

</div>

This is amazing!!

[Next page](https://forums.unrealengine.com/t/distance-field-soft-bodies/32105.md?page=2)
