Search Unity

Question Alpha Channel is showing up correctly in editor, but as dark red in game mode.

Discussion in 'Shader Graph' started by hossboyz, Jun 27, 2022.

  1. hossboyz

    hossboyz

    Joined:
    Jan 11, 2021
    Posts:
    3
    Hello! I'm trying to make a shader in shader graph that will allow me to "pixel dissolve" a UI element (an Image) based on a parameter I control with a script. Below is my implementation, which I believe should work. Note that the blending mode is set to alpha.



    It shows up correctly in the editor view.




    However, in the game preview and when I test the game, it shows up instead as dark red.



    I feel I am missing something here. Is there an additional step required for elements on a canvas?
     
    Last edited: Jun 27, 2022
    madbox_alex_nguyen likes this.
  2. haisulu

    haisulu

    Joined:
    Sep 29, 2017
    Posts:
    1
    I have the same problem. Did you get it fixed?
     
  3. hossboyz

    hossboyz

    Joined:
    Jan 11, 2021
    Posts:
    3
    For whatever reason, if you set the blending mode to premultiply, it works. However, I don't understand why.

    EDIT: No wait, now the white doesn't fade out? I can make this work since all my images are 1-bit black and white, but it isn't a general solution.
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    Shader graph does not support UI right now.
     
  5. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    278
    I've noticed the same thing after importing my project in Unity version 2021.3.5.

    To be precise, when a CanvasGroup's alpha value is set below zero, any unlit sprite shaders show transparency incorrectly as opaque. I am unsure where the color of the opaque pixels is derived from, mine are dark red or stark white-blue for some reason. The shaders in question are all either animated noises with transparency, or noises in combination with smoothsteps, without any alpha applied to the shaders themselves.

    Any word on a fix? This kinda sucks for my project as a lot of UI elements are animating in and out using CanvasGroup alpha values. I can still work on it but this isn't suitable for production.
     
  6. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    121
    Shader Graph worked fine for me for UI (at least on PC), but I've used regular Unlit shaders instead of Unlit Sprite. Keep in mind thought that in this case you should manually add vertex color to the shader (multiply it with color and alpha) for it to work as expected.
     
  7. ScetticoBlu

    ScetticoBlu

    Joined:
    Nov 26, 2020
    Posts:
    21
    Thanks for the hint! Can you show how to achive this?
    I'm trying but probably missing something...
    I want to achive this dissolving effect, but since I can't figure out how to handle it with a TextMeshPro, I dissolve an image that is above the text and has the same texture as the background (the paper scroll). So I made some shaders with Shader Graph.
    Here when Unlit Sprite Shader is used:
    upload_2023-4-21_10-41-15.png
    As @hossboyz said, alpha gets filled with dark red, but the editor view looks fine.
    So I switched to Unlit Shader but the image is not rendered at all, while the editor view still looks as intended:
    (You can see the Unlit Shader, is a very basic one)
    upload_2023-4-21_10-44-5.png

    Can someone help me?
     
    Last edited: Apr 21, 2023