# Gentle nudge/push particles away from surface (using SDF?)

## Recommended Posts

Alrighy, I have a big wedge of stupid in my head that is keeping me from doing this. I have particles emitting into a container (a super-simplified version is attached). I would like to get it where instead of the usual bounce/slide off a wall, the particles slow down and gradually move/are pushed away from the containing walls. I'm assuming this would be done using SDF/volume sample/volume gradient and a POP wrangle modifying the velocity based on the sampled values, but I just can't get it to work. I've seen lots of tutorials on using this approach to get particles to stay NEAR a surface, but my brain isn't adapting that to a nudge-away-from-a-surface instead of a nudge-towards. What am I doing wrong?

The POP wrangle code-in-progress (the collider is input 2, the VDB is input 3):

float samp = volumesample(2, 0, @P);

SOMETHING is happening, just not what I want. (And ideally I could have a second SDF inside the container pushing out, thus gently keeping the particles within a certain radius of the container wall, not going to the center.)

Thanks for any help!

Edited by bentway23

##### Share on other sites

Hi,
I attached an example. I think that technically, you are doing it right. Maybe try to add just a little bit of that gradient?

`v@v -= grad * 0.01;`

If you want to use the samp, then the wrangle might look like this:

```float samp = volumesample(2, 0, @P);

float omin = chf("old_min"); // 0 in -1 to 0
float omax = chf("old_max"); // 0 in -1 to 0
float nmin = 0;
float nmax = 1;
samp = fit(samp, omin, omax, nmin, nmax);
samp = chramp("dist",samp);

v@v -= normalize(grad) * samp * 0.01;```

Also you may toggle the Fill Interior on the VDB from Polygons.

Btw this is great tutorial, you may jump to 36th minute, or so:
https://vimeo.com/162213251

##### Share on other sites

Btw in that example, I also added a VDB Visualize Tree - Points with values. With that node, you can see, what are the values of SDF inside your Container.

In your example, the minimum SDF value inside the container is -0.495, so "old min" should be set to -0.5.

The fit() functions remaps samp for the ramp (because ramp wants the values to be 0-1).

(You could also proceduralize that "old min" with Attibute Promote set to Minimum ... if you want to, let me know)

##### Share on other sites

This is great! I'm glad to see I was at least in the ballpark, and I was able to quickly create and inner "core" pushing them away from the center and taming that unruly mob by simply adding instead of subtracting the inner gradient. Also, the visualize tree is new to me and way better than the create-a-bunch-of-points-create-an-attribute-and-scroll-through-the-geometry-spreadsheet method I've been using.

Also, I wasn't sure about "fill interior"--my approach was (theoretically) making a hollow VDB from the container walls and using the external-to-the-vdb-but-inside-the-container values for the sampling.

Thanks so much!

• 1

## Create an account

Register a new account