Spine-Skeleton-Fill.shader 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // - Unlit
  2. // - Premultiplied Alpha Blending (Optional straight alpha input)
  3. // - Double-sided, no depth
  4. Shader "Spine/Skeleton Fill" {
  5. Properties {
  6. _FillColor ("FillColor", Color) = (1,1,1,1)
  7. _FillPhase ("FillPhase", Range(0, 1)) = 0
  8. [NoScaleOffset] _MainTex ("MainTex", 2D) = "white" {}
  9. _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
  10. [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
  11. [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
  12. [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
  13. // Outline properties are drawn via custom editor.
  14. [HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
  15. [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
  16. [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
  17. [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
  18. [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
  19. [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
  20. [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
  21. }
  22. SubShader {
  23. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  24. Blend One OneMinusSrcAlpha
  25. Cull Off
  26. ZWrite Off
  27. Lighting Off
  28. Stencil {
  29. Ref[_StencilRef]
  30. Comp[_StencilComp]
  31. Pass Keep
  32. }
  33. Pass {
  34. Name "Normal"
  35. CGPROGRAM
  36. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  37. #pragma vertex vert
  38. #pragma fragment frag
  39. #include "UnityCG.cginc"
  40. sampler2D _MainTex;
  41. float4 _FillColor;
  42. float _FillPhase;
  43. struct VertexInput {
  44. float4 vertex : POSITION;
  45. float2 uv : TEXCOORD0;
  46. float4 vertexColor : COLOR;
  47. };
  48. struct VertexOutput {
  49. float4 pos : SV_POSITION;
  50. float2 uv : TEXCOORD0;
  51. float4 vertexColor : COLOR;
  52. };
  53. VertexOutput vert (VertexInput v) {
  54. VertexOutput o = (VertexOutput)0;
  55. o.uv = v.uv;
  56. o.vertexColor = v.vertexColor;
  57. o.pos = UnityObjectToClipPos(v.vertex);
  58. return o;
  59. }
  60. float4 frag (VertexOutput i) : SV_Target {
  61. float4 rawColor = tex2D(_MainTex,i.uv);
  62. float finalAlpha = (rawColor.a * i.vertexColor.a);
  63. #if defined(_STRAIGHT_ALPHA_INPUT)
  64. rawColor.rgb *= rawColor.a;
  65. #endif
  66. float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb), (_FillColor.rgb * finalAlpha), _FillPhase); // make sure to PMA _FillColor.
  67. return fixed4(finalColor, finalAlpha);
  68. }
  69. ENDCG
  70. }
  71. Pass {
  72. Name "Caster"
  73. Tags { "LightMode"="ShadowCaster" }
  74. Offset 1, 1
  75. ZWrite On
  76. ZTest LEqual
  77. Fog { Mode Off }
  78. Cull Off
  79. Lighting Off
  80. CGPROGRAM
  81. #pragma vertex vert
  82. #pragma fragment frag
  83. #pragma multi_compile_shadowcaster
  84. #pragma fragmentoption ARB_precision_hint_fastest
  85. #include "UnityCG.cginc"
  86. sampler2D _MainTex;
  87. fixed _Cutoff;
  88. struct VertexOutput {
  89. V2F_SHADOW_CASTER;
  90. float4 uvAndAlpha : TEXCOORD1;
  91. };
  92. VertexOutput vert (appdata_base v, float4 vertexColor : COLOR) {
  93. VertexOutput o;
  94. o.uvAndAlpha = v.texcoord;
  95. o.uvAndAlpha.a = vertexColor.a;
  96. TRANSFER_SHADOW_CASTER(o)
  97. return o;
  98. }
  99. float4 frag (VertexOutput i) : SV_Target {
  100. fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy);
  101. clip(texcol.a * i.uvAndAlpha.a - _Cutoff);
  102. SHADOW_CASTER_FRAGMENT(i)
  103. }
  104. ENDCG
  105. }
  106. }
  107. FallBack "Diffuse"
  108. CustomEditor "SpineShaderWithOutlineGUI"
  109. }