So Im trying to use this shader I had from a while ago to implement shadows in a 2D top down game. In order to show clouds on top of the game. At the moment, Sprites dont overlap which is good, but the shape of the sprite rendered by the sprite renderer is completely different to the one inserted in the sprite renderer, as the sprites in the sprite renderer are circles not squares. And it seems to cover any other sprite in the scenes which is not what a shade is supposed to be like.
How can I modify the shader so that it respects the sprite. Also I want it to react to lighting the same way as sprite diffuse does.
Shader "Custom/OverlappingDiffuse"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" { }
_Color ("Tint", Color) = (1, 1, 1, 1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader
{
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" "CanUseSpriteAtlas" = "True" }
Cull Off
Lighting On
ZWrite Off
Blend One OneMinusSrcAlpha
Stencil
{
Ref 1
// Comp NotEqual
Comp NotEqual
Pass Replace
Fail Keep
ZFail Keep
ReadMask 1
WriteMask 1
}
CGPROGRAM
#pragma surface surf Lambert vertex:vert nofog keepalpha
#pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
sampler2D _MainTex;
fixed4 _Color;
sampler2D _AlphaTex;
struct Input
{
float2 uv_MainTex;
fixed4 color;
};
void vert(inout appdata_full v, out Input o)
{
#if defined(PIXELSNAP_ON)
v.vertex = UnityPixelSnap(v.vertex);
#endif
UNITY_INITIALIZE_OUTPUT(Input, o);
o.color = v.color * _Color;
}
fixed4 SampleSpriteTexture(float2 uv)
{
fixed4 color = tex2D(_MainTex, uv);
#if ETC1_EXTERNAL_ALPHA
color.a = tex2D(_AlphaTex, uv).r;
#endif //ETC1_EXTERNAL_ALPHA
return color;
}
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 c = SampleSpriteTexture(IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb * c.a;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
This is how is showing up in the editor:
here is what I want , and want I am getting at the moment: