Search Unity

Question Painting shader dark edges issue

Discussion in 'Shaders' started by UserNobody, Sep 12, 2021.

  1. UserNobody

    UserNobody

    Joined:
    Oct 3, 2019
    Posts:
    144
    Hello,
    I am making a drawing mini-game and I am currently trying to create a paint shader.
    I use a white transparent image for the brush, for example:
    Untitled-17.png
    In this case, I added a black background, but in Unity, I have imported the same texture without the background. This brush image is premultiplied by me in a separate shader as such:
    Code (CSharp):
    1. fixed4 frag(v2f i) : SV_Target
    2. {
    3.     fixed4 color = tex2D(_MainTex, i.uv);
    4.  
    5.     fixed alpha = color.w;
    6.     color.x *= alpha;
    7.     color.y *= alpha;
    8.     color.z *= alpha;
    9.  
    10.     return color;
    11. }
    And then in the painting shader, I do this:
    Code (CSharp):
    1. fixed4 frag(v2f i) : SV_Target
    2. {
    3.     fixed4 mask = tex2D(_MainTex, i.uv) /* The brush texture */ * _Color;
    4.     fixed4 backdrop = tex2D(_Backdrop, i.bguv); //The painting canvas texture
    5.  
    6.     fixed4 color = backdrop * (1 - mask.a) + mask;
    7.     return color;
    8. }
    However, the output is not great...
    (The checker grid in the background is just a separate image with a grid background that indicates transparency and then I have another image in front that is painting result texture)

    Issue.png

    Can someone help me understand why is this happening? Thank you