Search Unity

Color and alpha blending in frag shader

Discussion in 'Shaders' started by WildStyle69, Dec 4, 2019.

  1. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    261
    Hi folks,

    I'm using fragment shaders with Graphics Blit to do paint operations on RenderTexture. Having some issues with color and alpha blending.

    Frag shader is using blend type: Blend SrcAlpha OneMinusSrcAlpha

    When painting colors I'm sampling the existing color and then mixing it with the new color via a lerp, is this an effective way to mix colors?

    When there is not much opacity the colors look OK, or when the colors are lighter tones and close to each other in the spectrum they mix pretty fine. However dark and mid tones of the same color don't mix well and it results in color banding.

    Painting like this in real-life layers more generally, so ideally that's what I'm trying to recreate. Having smooth blends even with opacity is the end goal.

    // WildStyle
     
    Last edited: Dec 5, 2019
  2. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    261
    Already fixed -- problem related to RenderTextureFormat and premultiplied alpha in the shaders.

    // WildStyle