Spine-Skeleton-Fill.shader 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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][MaterialToggle(_USE_SCREENSPACE_OUTLINE_WIDTH)] _UseScreenSpaceOutlineWidth("Width in Screen Space", Float) = 0
  16. [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
  17. [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
  18. [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
  19. [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
  20. [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
  21. [HideInInspector] _OutlineOpaqueAlpha("Opaque Alpha", Range(0,1)) = 1.0
  22. [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
  23. }
  24. SubShader {
  25. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  26. Blend One OneMinusSrcAlpha
  27. Cull Off
  28. ZWrite Off
  29. Lighting Off
  30. Stencil {
  31. Ref[_StencilRef]
  32. Comp[_StencilComp]
  33. Pass Keep
  34. }
  35. Pass {
  36. Name "Normal"
  37. CGPROGRAM
  38. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  39. #pragma vertex vert
  40. #pragma fragment frag
  41. #include "UnityCG.cginc"
  42. #include "CGIncludes/Spine-Common.cginc"
  43. sampler2D _MainTex;
  44. float4 _FillColor;
  45. float _FillPhase;
  46. struct VertexInput {
  47. float4 vertex : POSITION;
  48. float2 uv : TEXCOORD0;
  49. float4 vertexColor : COLOR;
  50. };
  51. struct VertexOutput {
  52. float4 pos : SV_POSITION;
  53. float2 uv : TEXCOORD0;
  54. float4 vertexColor : COLOR;
  55. };
  56. VertexOutput vert (VertexInput v) {
  57. VertexOutput o = (VertexOutput)0;
  58. o.uv = v.uv;
  59. o.vertexColor = PMAGammaToTargetSpace(v.vertexColor);
  60. o.pos = UnityObjectToClipPos(v.vertex);
  61. return o;
  62. }
  63. float4 frag (VertexOutput i) : SV_Target {
  64. float4 rawColor = tex2D(_MainTex,i.uv);
  65. float finalAlpha = (rawColor.a * i.vertexColor.a);
  66. #if defined(_STRAIGHT_ALPHA_INPUT)
  67. rawColor.rgb *= rawColor.a;
  68. #endif
  69. float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb), (_FillColor.rgb * finalAlpha), _FillPhase); // make sure to PMA _FillColor.
  70. return fixed4(finalColor, finalAlpha);
  71. }
  72. ENDCG
  73. }
  74. Pass {
  75. Name "Caster"
  76. Tags { "LightMode"="ShadowCaster" }
  77. Offset 1, 1
  78. ZWrite On
  79. ZTest LEqual
  80. Fog { Mode Off }
  81. Cull Off
  82. Lighting Off
  83. CGPROGRAM
  84. #pragma vertex vert
  85. #pragma fragment frag
  86. #pragma multi_compile_shadowcaster
  87. #pragma fragmentoption ARB_precision_hint_fastest
  88. #include "UnityCG.cginc"
  89. sampler2D _MainTex;
  90. fixed _Cutoff;
  91. struct VertexOutput {
  92. V2F_SHADOW_CASTER;
  93. float4 uvAndAlpha : TEXCOORD1;
  94. };
  95. VertexOutput vert (appdata_base v, float4 vertexColor : COLOR) {
  96. VertexOutput o;
  97. o.uvAndAlpha = v.texcoord;
  98. o.uvAndAlpha.a = vertexColor.a;
  99. TRANSFER_SHADOW_CASTER(o)
  100. return o;
  101. }
  102. float4 frag (VertexOutput i) : SV_Target {
  103. fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy);
  104. clip(texcol.a * i.uvAndAlpha.a - _Cutoff);
  105. SHADOW_CASTER_FRAGMENT(i)
  106. }
  107. ENDCG
  108. }
  109. }
  110. FallBack "Diffuse"
  111. CustomEditor "SpineShaderWithOutlineGUI"
  112. }