Search Unity

Changing Color On All VFX

Discussion in 'Visual Effect Graph' started by MousePods, Jul 27, 2021.

  1. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    Hi,

    I have 60+ of the same VFX in my game. I want to change the color (on update) for all of them. I am concerned that using "Set" will cause performance issues on all 60+ of them.

    Since they would all use the same material, I want to set one for all of them, but I cannot figure out how to do this. This would be great as then I could just change the material color and it wouldn't cause issues, I don't think?

    Is there a way to change the vfx graph asset color so it changed the color on all of them at once like you do with setting sharedmaterial?

    Thanks!
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    Do you need to change the color instantly, even for particles that are already spawned?
    Or you just need to start spawning red particles at some point, but old blue ones can continue as blue?
     
  3. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    I need to change all new/spawning particles instantly to that color.
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    I guess there is no other way than setting graph variable.
    Even if you made shader global variable and used it instead of color provided by graph, it's still inside shader, so in result all particles are affected - even those spawned before change as they ignore color from graph.

    Still I can see one workaround - you can create small texture and feed all graphs with it. When particle is initialized you sample this texture and use the sampled color as particle color.
    Later if you need to change the color for new particles, you just SetPixel() of that small texture and all graphs get new color automatically.
     
  5. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    That is a interesting workaround! Thanks for taking the time to write! How would you have two textures? I already have a texture for the graph. (Its a fog texture)

    I am surprised there is no way to do this easily. Would creating a property binder work? Just bind their color to the cameras color?

    https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@7.1/manual/PropertyBinders.html

    But I would be interested to know if it is even an issue updating the 60+ visual effects in update with setvector4.
     
  6. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    I have no clue, you would need to test it and compare results. If you need to update it every frame, then for sure there is way better way to spent these ms.
    Last time I checked PropertyBinder code, it was just script running every update to set graph property. Maybe this new buffer feature (2021) could help you somehow, but I did not test it or even read how it works.

    I would check if texture approach works, I am not sure what you mean by having two textures - just create property in graph. It would be something like this:
    textur.png
     
  7. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    I really appreciate all the information! It seems like property binder or texture way is a start to test!

    Just wondering if any vfx devs have any info on the inner working or alternative best ways to do this?

    @VladVNeykov
     
  8. FSGOwen

    FSGOwen

    Joined:
    Feb 3, 2023
    Posts:
    1
    Setting the graph color variable is changing the color for particles that are already emitted as well. Is there a way to only change the color for particles that are yet to spawn?
     
  9. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    188
    If you set the "color" attribute in the "Initialize Context", it should work.
    The "Initialize Context" is where you can set the logic and attributes when particles are born:
    upload_2023-4-6_15-5-28.png Unity_DusaEAHsCH.gif
     

    Attached Files:

    FSGOwen likes this.