Search Unity

Blending Modes in LWRP Particles

Discussion in 'Universal Render Pipeline' started by Koval331, Jun 13, 2019.

  1. Koval331

    Koval331

    Joined:
    Feb 3, 2019
    Posts:
    114
    I created a particle effect using a material created from Particles/Simple Lit shader with an image of white circle tinted red through Start Color setting. On the left I have Alpha Blending Mode and on the right Premultiply Blending Mode.

    alpha vs premultiply.png

    Why do I get black lines on the left?
     
    Last edited: Jun 13, 2019
  2. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    it is a white circle on a black background right?

    alpha blending =(RGB * Alpha) + (destination * inverse_Alpha)
    which means that white circle is getting it's edges multiplied darker by it's own alpha


    trying making RGB a plain white square, only the alpha defines the circle shape
    that is for alpha blending

    a texture that is pre-mupltipled (on black) needs to us pre-mult blending to look as you expect
    pre-mult blending = RGB + (destination * inverse_Alpha)
     
    Koval331 and richardkettlewell like this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Even if it's not, the LWRP Lit and SimpleLit particle shaders are straight up broken, even the latest on the Github. They do not handle Alpha blending properly.

    The bug is in the AlphaModulate() function in LWRP\ShaderLibrary\Particles.hlsl
    It currently looks like this:
    Code (csharp):
    1. half3 AlphaModulate(half3 albedo, half alpha)
    2. {
    3. #if defined(_ALPHAMODULATE_ON)
    4.     return lerp(half3(1.0h, 1.0h, 1.0h), albedo, alpha);
    5. #else
    6.     return albedo * alpha;
    7. #endif
    8. }
    But should look like this:
    Code (csharp):
    1. half3 AlphaModulate(half3 albedo, half alpha)
    2. {
    3. #if defined(_ALPHAMODULATE_ON)
    4.     return lerp(half3(1.0h, 1.0h, 1.0h), albedo, alpha);
    5. #elif defined(_ALPHAPREMULTIPLY_ON)
    6.     return albedo * alpha;
    7. #else
    8.     return albedo;
    9. #endif
    10. }
    The short version, the albedo should not be getting multiplied by the alpha when using Alpha mode. Otherwise you get the black edge you see above even with a solid white particle texture.

    Really, I kind of disagree with premultiplied multiplying the albedo by the alpha as well, at least with the Unlit shader, though it makes sense for the lit shaders due to the fact "premultiplied" means different things for lit and unlit shaders.
     
    Last edited: Jun 13, 2019
    Koval331 likes this.