Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug SDF Collision is leaking particles.

Discussion in 'Visual Effect Graph' started by koirat, Feb 15, 2022.

  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    I have baked SDF from mesh (using unity SDF baker) (mesh as on the picture) and then I use this sdf for spawning particles with some offset over the mesh, and for collision.

    Particles falls with gravity and are colliding with a sdf collider.
    Unfortunately the particles start to leak through the SDF collision until no particle is on the surface.

     
    Last edited: Feb 15, 2022
  2. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    146
    Hello,

    For performance reasons, the implementation of the SDF collision is pretty naive. It anticipates the next position based on the delta time and current velocity (see here).
    This approach can miss thin objects or particles which are moving too fast.

    In your case, you can workaround the issue adding a collision with a plane below however, it won't prevent particles to go through your terrain.

    Actually, if you are really trying to collide a terrain generated from an height map, it would be more approriate to compute the collision directly on this heightMap. We aren't providing a builtin block for this specific case. It's doable within the graph but I'm aware it can be really complex to achieve.
     
  3. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    But It do not miss the particles on first impact, when particles are the fastest collision is proper, and then when the particles are not moving they are slowly sinking.
     
  4. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    146
    Interesting, Is the Gravity Block applied after or before the Collision Block ? Both are valid but having the Gravity before should minimize the needed adjustement of the position.

    Can you share your data ? Maybe we missed something here.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Order of gravity do not make any difference in this case.
    I have sent you data link to inbox
     
  6. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    146
    Thanks, according to your generated data, the source mesh used to generate the SDF wasn't closed. Thus, below the "ground" of your mesh, the distance field is positive, it explains why the particles can be sucked.

    To solve this problem you can :
    - Close the holes of your mesh
    - Optionally, you can extend the bounds of the SDF along the z axis during baking
    - Modify the In/Out Threshold in SDF Bake Tool
    ThinCap.gif

    If you want to check the content of the generated data, you can take a look at the debug view in SDF Bake Tool. Alternatively, you can use a "Conform to SDF" block to verify if there isn't a loophole in the source SDF data.
    _sdf_debug.gif

    Additionally, you should be aware the collision integrating the radius of particles with a non uniform scale transform can lead to unexpected result with extreme stretching (it's also the case with collision with primitive).That's why I suggested to extend the z bound.

    (Special thanks to @ludovic.theobald for these inputs)

    I hope it helps.
     
  7. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Thank you very much, I did not know mesh must be closed, I thought that particles will be attracted to the closest surface.

    Let's hope this thread is not a waste of your time and people with similar issue will find it helpful.
     
  8. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    146
    You're welcome, it's always a pleasure. Actually, thanks to this thread, we also realized the Collide With SDF block can be more robust for this kind of scenario, we registered an issue (this link is probably not yet available when you are reading).

    Thanks!
     
    ssojyeti2 and koirat like this.