Search Unity

Particles flowing over surface

Discussion in 'Visual Effect Graph' started by alexxUID, Nov 29, 2020.

  1. alexxUID

    alexxUID

    Joined:
    Jan 14, 2020
    Posts:
    48
    Hi,
    coming from a 3D background I am used to control particle movement in specific cases by providing a mesh as a guide for the particles so they can flow over the surface starting on one side and ending at the other.

    Is it really that there is no built in way to create this behavior in either CPU or GPU particle systems in unity?

    I have seen users asking for this since a lot of years but never a real solution.

    If it is not available in unity: which would be the best approach for it? I was thinking about having the surface and use UVs to sample a point in 3D, add to the UV, sample again and so on but I would expect that to be quite expensive.

    I am quite inexperienced in hardcore unity but open to new solutions.

    Thanks

    Alex
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I think vector fields are the closest thing we have, which are essentially 3d textures where every texel contains a direction.

    In the built in ParticleSystem Component they come via the supplementary ParticleSystemForceField Component.

    In the Visual Effect Graph package, there are force/velocity blocks that use vector fields.
     
    alexxUID and florianhanke like this.
  3. alexxUID

    alexxUID

    Joined:
    Jan 14, 2020
    Posts:
    48
    Thanks for the answer Richard,
    I checked vector fields as a solution before but unfortunately they won't do the job for me since the surface I want to use will be deformed on creation of the prefabs instance. I should have mentioned that.
    I also find the creation of the fields quite hard to control.
    Anyway thanks for the input - that's what I am looking for.
     
    richardkettlewell likes this.
  4. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @alexxUID ,

    The approach you mentioned does work (we used it for the antagonist in Unity's The Heretic short), but it does require a bit of a setup:

    You write the vertex world position of the mesh to its vertex colors, and then "unwrap" the mesh by assigning its UVs to it's vertex XYZ position (effectively getting a flat 2D look mimicking how the UVs look). Then a separate camera renders only that mesh and outputs the result to a render texture, which you then feed into the VFX graph and sample to get the world position at each UV coordinate. As long as your UV's are laid out in the manner you want the particles to animate on the mesh, you can then move the sampling and the particles will "flow" on the mesh.

    Alternatively, if your mesh vertices are ordered, you could use the sample mesh operator and get the position from there, but authoring the appropriate mesh for this might be tricky.

    And as Richard mentioned, vertex fields or SDFs to flow on the surface are also a viable alternative, but authoring them once again is not as straight-forward at the moment.

    Hope this helps!
     
  5. alexxUID

    alexxUID

    Joined:
    Jan 14, 2020
    Posts:
    48
    Oof, that's a mouthful :D
    I guess I will postpone that for now and mark it under nice to have, since I am alone.
    But I am impressed this all is possible in realtime. Nicely done guys!
     
    VladVNeykov likes this.
  6. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    569
    alexxUID likes this.
  7. alexxUID

    alexxUID

    Joined:
    Jan 14, 2020
    Posts:
    48
    Wow.. that second example looks like it is the thing I would like to achieve. But no way I am learning Houdini to create the fields - just struggled through the basics of blender :)
    But in time I will definitely have a look in the files.
    Thanks a lot!
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  9. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    569

    I did take a look into creating the fields inside Unity. I made some progress and then got sidetracked. I think I used https://github.com/xraxra/SDFr to create a distance field and then sampled 6 points around each point in that to get a gradient vector. My maths is a bit shakey in this area so I probably did something wrong at that point, it looked wrong and I lost interest but this might give you a good starting point.