Jump to content

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);
vector grad = volumegradient(2, 0, @P);

@v *= -grad;

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
Link to comment
Share on other sites

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);
vector grad = volumegradient(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:



Link to comment
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)



Link to comment
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!

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...