I'm trying to incorporate Spine animated sprites into an existing surface shader in Unity. Everything works except the lighting, which has a ghostly overlapping effect on the individual sprites of my character (see attached screenshot). Here is (a simplified version of) my shader:
Shader "Northway/SpritesDiffuseWave" {
Properties {
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
}
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 SimpleLambert vertex:vert nolightmap nodynlightmap keepalpha noinstancing
#include "UnitySprites.cginc"
struct Input {
float2 uv_MainTex;
fixed4 color;
};
half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten) {
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * atten;
c.a = s.Alpha;
return c;
}
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
o.color = float4(1, 1, 1, 1);
// ... unrelated custom shader code
}
void surf (Input IN, inout SurfaceOutput o) {
fixed4 color = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = color.rgb;
o.Alpha = color.a;
}
ENDCG
}
}
Looking at the compiled shader, I see Unity performs two passes: "LightMode" = "ForwardBase" and "LightMode" = "ForwardAdd". By contrast, Spine's "Skeleton Lit" frag shader combines them in one "LIGHTMODE"="Vertex" pass.
I don't understand what's going wrong - why Spine characters look ghostly when my Unity sprites using the same shader look fine. What is different about them? How do I fix it?
I would rather adapt my existing surface shader to work than modify Spine's frag shader.
This may be related to a known bug http://esotericsoftware.com/forum/Lit-shader-problem-with-layers-11810?p=52916&hilit=shader#p52916 in which the pixel lit shader(s) behave in the same ghostly overlapping way. Whatever the fix is, it may also help me and my custom shader.
BTW when I try the Spine/Sprite/Pixel Lit shader on my sprites I can't seem to generate any lighting at all, or fog. I'm using version 3.7 of the Unity sdk.
This may be related to a known bug http://esotericsoftware.com/forum/Lit-shader-problem-with-layers-11810?p=52916&hilit=shader#p52916 in which the pixel lit shader(s) behave in the same ghostly overlapping way. Whatever the fix is, it may also help me and my custom shader.
BTW when I try the Spine/Sprite/Pixel Lit shader on my sprites I can't seem to generate any lighting at all, or fog. I'm using version 3.7 of the Unity sdk.