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

Pre mult bug, issue unresolves

Discussion in 'General Graphics' started by Torbach78, Mar 4, 2019.

  1. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    Can others back me up here and get this fixed? it's been broken since January now... maybe a better explanation or image to communicate better than I have?

    QA missed the issue - LWRP shader graph
    https://fogbugz.unity3d.com/default.asp?1114708_oa3vfcoefub5e7mp

    Pre-multiplied Alpha blend == One OneMinusSrcAlpha
    • alpha only operates destination
    • alpha is not coupled against the source color
    • expectation (RGBA) 1,1,1,0 = 1

    I think @line #200
    Code (CSharp):
    1.   #ifdef _ALPHAPREMULTIPLY_ON
    2.    
    3.                 Color *= Alpha;
    4.         #endif
    5.                 return half4(Color, Alpha);
    what is happening (RGBA) 1,1,1,0 = 0
    RGB *= alpha is not expected


    tl:dr - Color and Alpha are not coupled using pre-mult blend mode
     
    Last edited: Mar 4, 2019
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Your issue isn't very clear. Are you expecting to handle the premultiplication yourself?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,321
    The only reason to include the option for premultiplication as a blend mode is if you have content that is already setup to be used with a premultiplied blend mode. If the shader is forcibly multiplying the color by the alpha, then that negates the usefulness of having the blend mode to begin with. By multiplying the color by the alpha it means Alpha Blend and Premultiplied Alpha produce identical results, which they should not.
     
  4. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    well yes, exactly! pre-multiply == our source texture assets are on black
    e.g. pre-multiplied

    White color /w black alpha = White output
    e.g. the source is added (One) (aka 'Linear dodge') and the destination is preserved destination *= (1-0)

    what happens right now alpha 0 destroys source color to black; this is computationally SrcAlpha OneMinusSrcAlpha which is the 'traditional' alpha blend

    we do not expect color *= alpha for the pre-mult alpha blend mode

    https://microsoft.github.io/Win2D/html/PremultipliedAlpha.htm
    https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre
     
  5. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Good point. I figured that much, but I wasn't 100% sure.

    So the issue is that premultiplied alpha mode is not actually different from the regular alpha blending mode. Even though the blending is set to
    Code (csharp):
    1. Blend One OneMinusSrcAlpha
    which is exactly as expected for premultiplied alpha, there is a line of code that negates this by multiplying the color with alpha anyway:
    Code (csharp):
    1. Color *= Alpha;
    This in effect changes the blending back to
    Code (csharp):
    1. Blend SrcAlpha OneMinusSrcAlpha
    which is the same as regular alpha blending.
     
    Torbach78 likes this.
  6. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    bingo

    how would I go about being more clear in the future?
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,321
    "Alpha and Premuliply should not produce identical results."
     
    jvo3dc likes this.
  8. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    Hi,

    Just wanted to say finally got around to looking at this issue today, the interesting thing is that this code 'Color *= Alpha' is not needed as this is done earlier. As to why it is done, pre-multiplied blending in this respect is about the PBR lighting and blending with existing screen pixels where we keep the reflections(direct specular and reflection probes) rather than premultiplying the alpha of the texture map.

    If you are after premultiplying the actual texture(removing the black fringing), this can be achieved with making sure you have the 'Alpha is Transparency' checkbox is checked on the texture importer settings, this will preserve the colours correctly, allowing you to then use the alpha to blend on top of any colour.

    Edit:Actually don't mind me, I see we are talking about the unlit masternode, not the PBR. This indeed makes Premultiply end up working the same as Alpha which is not ideal, fixed now.
     
    Last edited: Apr 1, 2019
  9. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    this has returned. 2019.4.2f1
    premultiply blend mode functions identically to Alpha
    upload_2020-7-1_11-39-32.png
     
  10. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
  11. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
  12. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    issue ongoing shadergraph (URP) Unity 2020.3.14f1
    case 1260085

    Premultiplied blend mode operates identically as Alpha blending
    unityPremult.png

    alpha alters color

    premult mode: Source * One + Destination * OneMinusSrcAlpha

    now operates like
    Source * SrcAlpha + Destination * OneMinusSrcAlpha



    ...Packages > Universal RP > Shaders > Unlit.txt

    #234
    upload_2021-7-22_17-28-8.png

    The master node in action violates blend mode intent [SourceOne]
    unlitMaster1.gif
     
    Last edited: Jul 23, 2021
  13. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    Unity PSA v2021.2.14f1 Premultiply blend mode is now working in shader graph and no longer redundant as alpha Blending (tested URP, unlit master node)

    :D
    premultURP.gif
     
    jitterhorse and bgolus like this.