Search Unity

Adjust Particle Size based on a grayscale mask?

Discussion in 'Visual Effect Graph' started by unity_Wd9us_rR3t_Emg, Feb 21, 2022.

  1. unity_Wd9us_rR3t_Emg

    unity_Wd9us_rR3t_Emg

    Joined:
    Mar 5, 2019
    Posts:
    5
    Hi!

    I was wondering if it is possible to adjust the size of any given particle according to a given gray scale value of 2D image at that position. If so, how would one go about this?

    I am currently trying to spawn particles from the vertices of a mesh and then adjust their size with a given texture/mask/image, and I could not find a solution with the basic Particle System so I would like to try VFX Graph, if it is possible at all! :)

    Thanks in advance!
     
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi!

    If you are already sampling from a mesh, you can just use the mesh UVs, sample a texture, and set the size based on the result:


    Hope this helps! :)
     

    Attached Files:

  3. unity_Wd9us_rR3t_Emg

    unity_Wd9us_rR3t_Emg

    Joined:
    Mar 5, 2019
    Posts:
    5
    I am not sure if this works, as my mesh does not have faces as I only wanted to use the vertices as particle spawn positions :D But there is probably a smarter way to go about this for me then. This is at least a great start, thank you very much! I will see if I can get it to work like that.
     
  4. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Sure thing! If you don't have UVs, you can also maybe 2D-"project" the texture by remapping the particle positions to UV coordinates:
    upload_2022-2-21_18-12-51.png
    ("projecting" here on a flat plane, remapping XZ to UV)

    Or, you if you can store vertex colors in your vertices, you could just skip the texture part altogether and directly set the size in, for example, your red channel: upload_2022-2-21_18-14-53.png

    Lots of ways to go around :)
     
  5. unity_Wd9us_rR3t_Emg

    unity_Wd9us_rR3t_Emg

    Joined:
    Mar 5, 2019
    Posts:
    5
    Thank you so much! The 2D projection works like a charm!

    I have one more a little unrelated question, I was wondering if you can apply scrolling/looping noise to the particle positions just like in the Shuriken System? I tried the Turbulence not, but since it applies force the particles are just drifting off into nowhere :D
     
    Last edited: Feb 22, 2022
    VladVNeykov likes this.
  6. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Got a few ways to do this as well. Probably the simplest is to just add the noise offset to your position in the Output.

    The reason this works is that Output doesn't incrementally write to the position attribute; it will get the same position from Update each frame, and then you can add a changing value on top of that so you can create looping noise effects like what you mentioned:
     

    Attached Files:

  7. unity_Wd9us_rR3t_Emg

    unity_Wd9us_rR3t_Emg

    Joined:
    Mar 5, 2019
    Posts:
    5
    Thank you very much, that works perfectly. I should have thought of that, instead I always incrementally added more offset in the Update. But I also didn't know it was an option on the Output :D Thank you for putting up with my noob questions!
     
    VladVNeykov likes this.
  8. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Sure thing, happy it helped! :)