Spine-Skeleton-Fill.shader 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "CGIncludes/Spine-Common.cginc"
  41. sampler2D _MainTex;
  42. float4 _FillColor;
  43. float _FillPhase;
  44. struct VertexInput {
  45. float4 vertex : POSITION;
  46. float2 uv : TEXCOORD0;
  47. float4 vertexColor : COLOR;
  48. };
  49. struct VertexOutput {
  50. float4 pos : SV_POSITION;
  51. float2 uv : TEXCOORD0;
  52. float4 vertexColor : COLOR;
  53. };
  54. VertexOutput vert (VertexInput v) {
  55. VertexOutput o = (VertexOutput)0;
  56. o.uv = v.uv;
  57. o.vertexColor = PMAGammaToTargetSpace(v.vertexColor);
  58. o.pos = UnityObjectToClipPos(v.vertex);
  59. return o;
  60. }
  61. float4 frag (VertexOutput i) : SV_Target {
  62. float4 rawColor = tex2D(_MainTex,i.uv);
  63. float finalAlpha = (rawColor.a * i.vertexColor.a);
  64. #if defined(_STRAIGHT_ALPHA_INPUT)
  65. rawColor.rgb *= rawColor.a;
  66. #endif
  67. float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb), (_FillColor.rgb * finalAlpha), _FillPhase); // make sure to PMA _FillColor.
  68. return fixed4(finalColor, finalAlpha);
  69. }
  70. ENDCG
  71. }
  72. Pass {
  73. Name "Caster"
  74. Tags { "LightMode"="ShadowCaster" }
  75. Offset 1, 1
  76. ZWrite On
  77. ZTest LEqual
  78. Fog { Mode Off }
  79. Cull Off
  80. Lighting Off
  81. CGPROGRAM
  82. #pragma vertex vert
  83. #pragma fragment frag
  84. #pragma multi_compile_shadowcaster
  85. #pragma fragmentoption ARB_precision_hint_fastest
  86. #include "UnityCG.cginc"
  87. sampler2D _MainTex;
  88. fixed _Cutoff;
  89. struct VertexOutput {
  90. V2F_SHADOW_CASTER;
  91. float4 uvAndAlpha : TEXCOORD1;
  92. };
  93. VertexOutput vert (appdata_base v, float4 vertexColor : COLOR) {
  94. VertexOutput o;
  95. o.uvAndAlpha = v.texcoord;
  96. o.uvAndAlpha.a = vertexColor.a;
  97. TRANSFER_SHADOW_CASTER(o)
  98. return o;
  99. }
  100. float4 frag (VertexOutput i) : SV_Target {
  101. fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy);
  102. clip(texcol.a * i.uvAndAlpha.a - _Cutoff);
  103. SHADOW_CASTER_FRAGMENT(i)
  104. }
  105. ENDCG
  106. }
  107. }
  108. FallBack "Diffuse"
  109. CustomEditor "SpineShaderWithOutlineGUI"
  110. }