Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Resolved Shader looks different when changing color at runtime on a Visual Effect

Discussion in 'Visual Effect Graph' started by Lunas_Dreams, Apr 9, 2024.

  1. Lunas_Dreams

    Lunas_Dreams

    Joined:
    Oct 1, 2016
    Posts:
    7
    Hallo, first of, i just started to learn shader graph and visual effects graph.

    I was making a visual effect that uses a voronoi shader i made with shader graph.
    At first everything worked fine, till i reached a point where i change the color of the Visual effect at runtime via code(even when giving the very same hdr color).
    When i do it in the inspector it does not happen.
    When i do that, the Alpha seems to become much lower to the point where it becomes barly visible.
    For debugging purposes i put my shader on a simple plane (without the visual effect). There it also looks really pale from the start.
    So it seems the Visual effects graph increases the Alpha of the shader, but loses that when changing the color via script.

    Left side(no change to the color). Right side after giving the Viusal Effect the exact same color via script.
    Visual Effect befor and after color change.png

    Here is the color that i use:
    HDR Color.png


    The visual effect part that uses the voronoi shader just makes 1 constant particle quad and only alter the size, rotation and gives a exposed variable to change the color
    Swirl Visual Effect.png

    The Shader
    Shader part 1.png Shader part 2.png

    Is there some setting that would make the shader look the same on a plane, in the visual effect or after changing the color at runtime via script?

    Code (CSharp):
    1. [ColorUsageAttribute(true,true)]
    2. public Color swirl;
    3.  
    4. public void _myFunction()
    5. {
    6.       visualEffect.SetVector4("SwirlColor", swirl);
    7. }
    I'm using Unity 2023.2.2f1
     
  2. Lunas_Dreams

    Lunas_Dreams

    Joined:
    Oct 1, 2016
    Posts:
    7
    Ok, after watching through the screenshots i made for this post i noticed in the visual effect graph the alpha of the swirl color was set to 8.
    When changing the alpha in the instance of the visual effect it seem to take the the 8 from the visual effect as the base value.
    After i changed the alpha in the visual effects graph to 1 there was still no change.
    But when i then changed the alpha on an instance of the visual effect by 1, it loooked exactly the same as when chaning by code.
     
    OrsonFavrel likes this.
  3. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    229
    I am glad that you found the source of the issue. Great work, it's beautiful. Don't hesitate to share an animated version. I'm always curious to see beautiful VFX . :)
     
  4. Lunas_Dreams

    Lunas_Dreams

    Joined:
    Oct 1, 2016
    Posts:
    7
    Thank you very much for the compliment.
    Here an animated version :)
    Portal Visual Effect.gif

    Im still not completly satisfied how it looks i might make the outer edge more visible and maybe give it some background to give it more contrast but i'm not yet sure how to approch that. Or maybe add some sort of distortion in the future.

    In the end it should become a Portal laying on the ground where units will come out of.

    Edit: fixed typo
     
    Last edited: Apr 9, 2024
    OrsonFavrel likes this.
  5. Lunas_Dreams

    Lunas_Dreams

    Joined:
    Oct 1, 2016
    Posts:
    7
    Here a version visible from the game camera and with team color.
    Cards and Teamcolored Portals.gif