I need help improving shader

Hello!
I’m making a 2D game and I want to simulate “shadow” of the sprites, I think I just use semi-transparent black-tinted sprite for that; but the “shadows” are not “blended” well (I’m not sure what’s that called, please check my attached image).

And after searching around, I found a solution that is using a “shader” and downloaded it (from a user on reddit), it works so far but the edges of the shadow is jagged, I would like to smooth out those edges but I’m not sure how to modify the shader.

  • on the left: not “blended” well shadows
  • on the right: this is what I need but I want the edges to be smoother

can anyone help me with this? or point me to a direction to resolve this? (beware that I know nothing about shader :frowning: )

I also attach the shader file I downloaded.

Thank you for reading.

6392801–712775–ShadowShader.shader (1.61 KB)

Hello @Tom-Kazansky ,

If we take a look at the fragment shader, we see the following check

                if (color.a == 0.0)
                    discard;

Here we discard all pixels with the alpha value of 0. If we instead increase the value of which we discard to let’s say < 0.1, you will see that the edges are rendered a bit smoother.

            half4 frag(v2f i) : COLOR
            {
                half4 color = tex2D(_MainTex, i.uv);
                if (color.a < 0.1)
                    discard;

                color = _Color;
                return color;
            }
1 Like

Thank you very much!
it works.

I think I should learn about shader (soon) :slight_smile:

1 Like