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

Question VFX Graph Set color over life

Discussion in 'Visual Effect Graph' started by Alexiiinka, Oct 27, 2022.

  1. Alexiiinka

    Alexiiinka

    Joined:
    Jul 27, 2021
    Posts:
    6
    Hello, can someone please explain to me, what is the difference if I add block Set color over lifetime to UPDATE node or in OUTPUT node? Thank you very much!
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,291
    Code in update is executed on actual particle data, meanwhile output modification is temporary, only for rendering and is discarded at the end of frame.
    As example if you got particle with initial size 1, and block Add Size 0.5 inside update, then your particles are going to grow every update like this: [1, 1.5, 2, 2.5], but if you do the same in output context then it will be always 1.5.
     
  3. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    183
    Morning.
    First ,just know that both are valid.
    What @Qriva said is correct and I would like to add some subtleties.

    -When doing operation in the "Update Context" , the calculation is done "per-Particle", and the attributes are Stored in Memory. Then the Values are loaded from memory and used to draw the Quad/Mesh etc...

    -When doing operation in the "Output Context", calculation is done "Per-vertex", no attributes are stored and it can be used directly for Drawing.

    So if you do a "Set Color over Lifetime" in the "Update Context", that means that you're doing calculation per-particle, but you're also storing the "Color" attribute. And you have extra steps of Storing/loading from memory that often are more costly than doing the operations per-vertex.

    Usually for performance, it's better to set those rendering attributes, Size, Color etc in the "Output Context".
    But, it's not always that easy. You need to be careful if you render Particles Meshes with high vertex count, as doing operation on the "Output context" will be done on each-Vertex....
    Also if the operations/behavior are quite heavy (Sampling Meshes for example) it's also better to do it in the "Update Context".

    To finish, also know that while you can set the "Position" attribute in the "Output Context" , doing so will prevent you from having proper Particle Sorting, proper Strip Orientation.
    Also , Size/position in the "Output Context" can also mess-up/confuse the camera frustum culling.

    So here would be the general guidelines :
    • Init : Set initial stored particle state based on some potentially complex/heavy behavior

    • Update : modified stored particle state. Typically all blocks that are needed by sim (like collision...)

    • Output : Alter state before rendering but do not actually store modifications. Put all things static/simple here that do not require heavy modification (fixed or exposed color, color based on life...)
    In the end, it’s a balance between memory and Computations, that have some point that needs to be profiled if needed.

    Hope this helps.
     
    Opaweynch, nicloay, XieJiJun and 2 others like this.