Spine-Skeleton-Tint.shader 3.9 KB

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