Search Unity

The front UI element completely overwrites the alpha channel.

Discussion in 'UGUI & TextMesh Pro' started by Elfinnik159, May 4, 2020.

  1. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    Hello, My game window has a transparent background, all transparent details “shine through” showing the desktop.
    My problem is that the top element of the UI overwrites the alpha channel information without considering the bottom. In a normal game, this is invisible, but when I need to use the UI alpha channel, a problem appears.

    Scene:
    upload_2020-5-4_12-36-2.png
    Back panel: color: white, alpha = 1
    Front panel: color: red, alpha = 0.5
    This is clearly seen when using a shader with GrabPass. Channels Output: (alpha, alpha, alpha, 1)
    And since I use the alpha channel, instead:
    upload_2020-5-4_12-36-22.png
    I get this:
    upload_2020-5-4_12-36-18.png
    Example from the game:
    upload_2020-5-4_12-34-6.png
    (It is expected that the transparent red panel will not shine through because there is an opaque white panel behind it)

    This problem persists on different versions (2018-2019) and in different color spaces (G / L). Forward rendering, orthographic camera. Canvas Render Mode: any.

    Tell me please, is there a way to fix this?
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Do I understand it correctly that this only happens with non-default materials?
    If so, please post the code of the shader, if possible.
     
  3. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    No, this problem is with the default material (standard UI / Default shader).
    I found a solution to the problem in another section of the forum: for some reason, the standard UI shader uses Blend SrcAlpha OneMinusSrcAlpha, which leads to this result. To fix this, I had to change the standard shader:
    Change blending mode to:
    Blend One OneMinusSrcAlpha
    Add line:
    color.rgb * = color.a;
    After that, I get the expected result (the alpha channel is not overwritten, but mixed correctly)