Spine-Skeleton-Tint.shader 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Spine/Skeleton Tint
  2. // - Two color tint
  3. // - unlit
  4. // - Premultiplied alpha blending (Optional straight alpha input)
  5. // - No depth, no backface culling, no fog.
  6. Shader "Spine/Skeleton Tint" {
  7. Properties {
  8. _Color ("Tint Color", Color) = (1,1,1,1)
  9. _Black ("Dark Color", Color) = (0,0,0,0)
  10. [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {}
  11. [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
  12. _Cutoff("Shadow alpha cutoff", Range(0,1)) = 0.1
  13. [Toggle(_DARK_COLOR_ALPHA_ADDITIVE)] _DarkColorAlphaAdditive("Additive DarkColor.A", Int) = 0
  14. [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
  15. [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
  16. // Outline properties are drawn via custom editor.
  17. [HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
  18. [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
  19. [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
  20. [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
  21. [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
  22. [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
  23. [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
  24. }
  25. SubShader {
  26. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  27. Fog { Mode Off }
  28. Cull Off
  29. ZWrite Off
  30. Blend One OneMinusSrcAlpha
  31. Lighting Off
  32. Stencil {
  33. Ref[_StencilRef]
  34. Comp[_StencilComp]
  35. Pass Keep
  36. }
  37. Pass {
  38. Name "Normal"
  39. CGPROGRAM
  40. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  41. #pragma shader_feature _ _DARK_COLOR_ALPHA_ADDITIVE
  42. #pragma vertex vert
  43. #pragma fragment frag
  44. #include "UnityCG.cginc"
  45. sampler2D _MainTex;
  46. float4 _Color;
  47. float4 _Black;
  48. struct VertexInput {
  49. float4 vertex : POSITION;
  50. float2 uv : TEXCOORD0;
  51. float4 vertexColor : COLOR;
  52. };
  53. struct VertexOutput {
  54. float4 pos : SV_POSITION;
  55. float2 uv : TEXCOORD0;
  56. float4 vertexColor : COLOR;
  57. };
  58. VertexOutput vert (VertexInput v) {
  59. VertexOutput o;
  60. o.pos = UnityObjectToClipPos(v.vertex);
  61. o.uv = v.uv;
  62. o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
  63. return o;
  64. }
  65. #include "CGIncludes/Spine-Skeleton-Tint-Common.cginc"
  66. float4 frag (VertexOutput i) : SV_Target {
  67. float4 texColor = tex2D(_MainTex, i.uv);
  68. return fragTintedColor(texColor, _Black.rgb, i.vertexColor, _Color.a, _Black.a);
  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. CustomEditor "SpineShaderWithOutlineGUI"
  109. }