Search Unity

Question BlendOp Max gives strange result (project attached)

Discussion in 'Shaders' started by subGlitch, Aug 5, 2022.

  1. subGlitch

    subGlitch

    Joined:
    Jan 27, 2015
    Posts:
    23
    I have simple scene with 2 unlit transparent quads rendered above unlit black background. These quads have same size and texture (Default-Particle). The only difference is that one have shader with BlendOp Add (left) and another have shader with BlendOp Max.

    The question is - why the second looks bigger? I expect they should look absolutely the same, because (Color * SrcAlpha + Black * OneMinusSrcAlpha) should give the same result as MAX(Color * SrcAlpha, Black * OneMinusSrcAlpha), and in both cases the result should be (Color * SrcAlpha).

    Or am I wrong??

    Unity 2020.3.34, Standalone, BRP
    The project attached.

    upload_2022-8-5_13-32-32.png
     

    Attached Files:

    Last edited: Aug 5, 2022
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    The
    BlendOp Max
    and
    Min
    operators are unique in that they ignore the
    Blend
    settings. So
    BlendOp Max
    equates to:
    Code (csharp):
    1. max(Src, Dst)
    regardless of what you set the
    Blend
    to, and not
    Code (csharp):
    1. max(Src * SrcAlpha, Dst * OneMinusSrcAlpha)
     
  3. subGlitch

    subGlitch

    Joined:
    Jan 27, 2015
    Posts:
    23
    Wow, that's interesting, didn't know that. But that means that the Unity's doc is wrong. It says:
    • If the blending operation is Add, Sub, RevSub, Min, or Max, the GPU multiplies the value of the output of the fragment shader by the source factor.
    • If the blending operation is Add, Sub, RevSub, Min, or Max, the GPU multiplies the value that is already in the render target by the destination factor.
    Is this Unity's doc really incorrect?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Yep.

    You can try it yourself. Set the blend to:
    Blend Zero One
    . It won’t change how it looks.
     
  5. subGlitch

    subGlitch

    Joined:
    Jan 27, 2015
    Posts:
    23
    That's funny. Haha :) Thanks for the answer!