Shaders 2D sprites diffuse - more than two source of lights - issue with full lightning objects
Please look at this video. You can see clearly what's wrong is with this default official unity shader: youtube video
I'm using custom default sprite diffuse shader downloaded from unity page (tried all others, no one is working great on 2d sprite renderers and animations). Code is here:
Shader "Custom/Diffuse" {
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 Off
ZWrite Off
Blend One OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Lambert vertex:vert nofog keepalpha
#pragma multi_compile _ PIXELSNAP_ON
sampler2D _MainTex;
fixed4 _Color;
sampler2D _AlphaTex;
float _AlphaSplitEnabled;
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 UNITY_TEXTURE_ALPHASPLIT_ALLOWED
if (_AlphaSplitEnabled)
color.a = tex2D (_AlphaTex, uv).r;
#endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED
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"
}
As you can see problem is only when third light is coming. If sprite is lighted partially by two lights it's good. But when from 3, all sprite is lighted at once. Why? I'm max beginner at shaders, don't know what is wrong with which line.
Tried to change Player settings for Redering Path ( Legacy Vertex Lit does not have this problem, but animations ale flickering as hell it's not stable option for me, can not change it). Changed color space from linear to gamma, but gamma has its issues as well. Turned off batching, both and one per time. Nothing helps.
I belive that this shader somehow works invalid, even if it's the one built-in unity. Have no idea what I should change there anyway. Working on it for like a week o0