Last active
August 4, 2020 10:45
-
-
Save pharan/eb758e46630ad7ae2234227480922c21 to your computer and use it in GitHub Desktop.
A version of Spine/Skeleton shader that can be drawn within a Unity 2017 SpriteMask.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Spine/Skeleton SpriteMaskable" { | |
Properties { | |
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 | |
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} | |
_StencilRef ("Stencil Reference", Float) = 1.0 | |
_StencilComp ("Stencil Compare", Float) = 4.0 // For float values, see https://docs.unity3d.com/Manual/SL-Stencil.html under "Comparison Function" heading | |
} | |
SubShader { | |
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } | |
Fog { Mode Off } | |
Cull Off | |
ZWrite Off | |
Blend One OneMinusSrcAlpha | |
Lighting Off | |
Pass { | |
Stencil { | |
Ref [_StencilRef] //Customize this value | |
Comp [_StencilComp] //Customize the compare function | |
Pass Keep | |
} | |
Fog { Mode Off } | |
ColorMaterial AmbientAndDiffuse | |
SetTexture [_MainTex] { | |
Combine texture * primary | |
} | |
} | |
Pass { | |
Name "Caster" | |
Tags { "LightMode"="ShadowCaster" } | |
Offset 1, 1 | |
ZWrite On | |
ZTest LEqual | |
Fog { Mode Off } | |
Cull Off | |
Lighting Off | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_shadowcaster | |
#pragma fragmentoption ARB_precision_hint_fastest | |
#include "UnityCG.cginc" | |
sampler2D _MainTex; | |
fixed _Cutoff; | |
struct v2f { | |
V2F_SHADOW_CASTER; | |
float2 uv : TEXCOORD1; | |
}; | |
v2f vert (appdata_base v) { | |
v2f o; | |
TRANSFER_SHADOW_CASTER(o) | |
o.uv = v.texcoord; | |
return o; | |
} | |
float4 frag (v2f i) : COLOR { | |
fixed4 texcol = tex2D(_MainTex, i.uv); | |
clip(texcol.a - _Cutoff); | |
SHADOW_CASTER_FRAGMENT(i) | |
} | |
ENDCG | |
} | |
} | |
SubShader { | |
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } | |
Cull Off | |
ZWrite Off | |
Blend One OneMinusSrcAlpha | |
Lighting Off | |
Pass { | |
ColorMaterial AmbientAndDiffuse | |
SetTexture [_MainTex] { | |
Combine texture * primary DOUBLE, texture * primary | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment