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

Multiply alpha blends "dissolves" alpha channel on the render target ?

Discussion in 'General Graphics' started by Gulliver, Jun 18, 2019.

  1. Gulliver

    Gulliver

    Joined:
    Jan 8, 2013
    Posts:
    101
    Hello.
    I'm working ob VR project. All game interface renders to the Render Target Texture, and then it used on the plane in the 3D space. The problem is -- when interface element (button for example) consists of several semi-transparent parts, resulting alpha in this place is noticeable less than other, what causes undesirable effect of the "holes" in the interface.

    On right side I added final line to fragment shader:
    c.rgb = c.a;
    alpha_5.jpg

    Why it happens ? If alpha component with alpha blending blends by same equitation we'll have really strange things. Lets assume background alpha always 1. Then applying equitation
    color = src_color*src_alpha+dst_color(1-src_alpha)
    with src_color = src_alpha wi'll have
    alpha = src_alpha*src_alpha + (1-src_alpha)
    and for 0.5 will have alpha(0.5) = 0.5*0.5 + 1*(1-0.5) = 0.75 ?!
    alpha.jpg
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Try using separate blend modes for the color and alpha:

    Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
     
    Gulliver likes this.
  3. Gulliver

    Gulliver

    Joined:
    Jan 8, 2013
    Posts:
    101
    Thank you. I did not know that it's possible to set a separate blend for alpha.