Sorry to revive but does anyone know working surface shader that is equivalent to the ones come with Spine Unity(skeleton, skeleton lit shader)? I've tried all the shaders written here but they all seem to have problem blending/sorting skeleton. I'm trying to add translucent lighting effect but need surface version of the shader to do it.
It's been solved. Since I started this, I'll just drop my code which won't help many people :p
Ignore the shader name. Basically it renders skeletal animation with lighting and shadow and ignores which direction the model is facing towards a light source, just taking distance in account.
Shader "Custom/TranslucentSpine" {
Properties {
_MainTex ("RGBA Texture Image", 2D) = "white" {}
_Color ("Diffuse Material Color", Color) = (1,1,1,1)
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 100
Cull Off
ZWrite Off
Pass {
Tags {"LightMode" = "ForwardBase" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float _Cutoff;
uniform float4 _LightColor0;
uniform float4 _Color;
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
float3 normal : NORMAL;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
float4 col : COLOR;
float3 diffuseColor : TEXCOORD1;
};
vertexOutput vert(vertexInput input) {
vertexOutput output;
float4x4 modelMatrix = _Object2World;
float4x4 modelMatrixInverse = _World2Object;
float3 normalDirection = normalize(float3(mul(float4(input.normal, 0.0), modelMatrixInverse)));
float3 viewDirection = normalize(float3(float4(_WorldSpaceCameraPos, 1.0)- mul(modelMatrix, input.vertex)));
float3 lightDirection;
float attenuation;
if (0.0 == _WorldSpaceLightPos0.w){ // directional light
attenuation = 1.0;
lightDirection = normalize(float3(_WorldSpaceLightPos0));
} else { // point or spot light
float3 vertexToLightSource = float3(_WorldSpaceLightPos0 - mul(modelMatrix, input.vertex));
float distance = length(vertexToLightSource);
attenuation = 1.0 / distance; // linear attenuation
lightDirection = normalize(vertexToLightSource);
}
float3 ambientLighting = float3(UNITY_LIGHTMODEL_AMBIENT) * float3(_Color);
float3 diffuseReflection = attenuation * float3(_LightColor0) * float3(_Color) * max(0.0, 5);
output.diffuseColor = ambientLighting + diffuseReflection*0.5;
output.tex = input.texcoord;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
return output;
}
float4 frag(vertexOutput input) : COLOR {
fixed4 tex = tex2D(_MainTex, float2(input.tex));
tex.rgb = input.diffuseColor * tex.rgb;
return tex;
}
ENDCG
}
Pass {
Tags {"LightMode" = "ForwardAdd" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float _Cutoff;
uniform float4 _LightColor0;
uniform float4 _Color;
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
float3 normal : NORMAL;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
float4 col : COLOR;
float3 diffuseColor : TEXCOORD1;
};
vertexOutput vert(vertexInput input) {
vertexOutput output;
float4x4 modelMatrix = _Object2World;
float4x4 modelMatrixInverse = _World2Object;
float3 normalDirection = normalize(float3(mul(float4(input.normal, 0.0), modelMatrixInverse)));
float3 viewDirection = normalize(float3(float4(_WorldSpaceCameraPos, 1.0)- mul(modelMatrix, input.vertex)));
float3 lightDirection;
float attenuation;
if (0.0 == _WorldSpaceLightPos0.w){ // directional light
attenuation = 1.0;
lightDirection = normalize(float3(_WorldSpaceLightPos0));
} else { // point or spot light
float3 vertexToLightSource = float3(_WorldSpaceLightPos0 - mul(modelMatrix, input.vertex));
float distance = length(vertexToLightSource);
attenuation = 1.0 / distance; // linear attenuation
lightDirection = normalize(vertexToLightSource);
}
float3 ambientLighting = float3(UNITY_LIGHTMODEL_AMBIENT) * float3(_Color);
float3 diffuseReflection = attenuation * float3(_LightColor0) * float3(_Color) * max(0.0, 5);
output.diffuseColor = ambientLighting + diffuseReflection*0.5;
output.tex = input.texcoord;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
return output;
}
float4 frag(vertexOutput input) : COLOR {
fixed4 tex = tex2D(_MainTex, float2(input.tex));
tex.rgb = input.diffuseColor * tex.rgb;
return tex;
}
ENDCG
}
}
Fallback "Transparent/Cutout/Diffuse"
}