Spine-Skeleton-TintBlack.shader 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Spine/Skeleton Tint Black
  2. // - Two color tint
  3. // - UV2 and UV3 as Black Tint color.
  4. // - Final black tint is (UV black data and _Black/"Black Point")
  5. // - unlit
  6. // - Premultiplied alpha blending (optional straight alpha input)
  7. // - No depth, no backface culling, no fog.
  8. Shader "Spine/Skeleton Tint Black" {
  9. Properties {
  10. _Color ("Tint Color", Color) = (1,1,1,1)
  11. _Black ("Dark Color", Color) = (0,0,0,0)
  12. [NoScaleOffset] _MainTex ("MainTex", 2D) = "black" {}
  13. [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
  14. _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
  15. [Toggle(_DARK_COLOR_ALPHA_ADDITIVE)] _DarkColorAlphaAdditive("Additive DarkColor.A", Int) = 0
  16. [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
  17. [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
  18. // Outline properties are drawn via custom editor.
  19. [HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
  20. [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
  21. [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
  22. [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
  23. [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
  24. [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
  25. [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
  26. }
  27. SubShader {
  28. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  29. LOD 100
  30. Fog { Mode Off }
  31. Cull Off
  32. ZWrite Off
  33. Blend One OneMinusSrcAlpha
  34. Lighting Off
  35. Stencil {
  36. Ref[_StencilRef]
  37. Comp[_StencilComp]
  38. Pass Keep
  39. }
  40. Pass {
  41. Name "Normal"
  42. CGPROGRAM
  43. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  44. #pragma shader_feature _ _DARK_COLOR_ALPHA_ADDITIVE
  45. #pragma vertex vert
  46. #pragma fragment frag
  47. #include "UnityCG.cginc"
  48. sampler2D _MainTex;
  49. float4 _Color;
  50. float4 _Black;
  51. struct VertexInput {
  52. float4 vertex : POSITION;
  53. float2 uv : TEXCOORD0;
  54. float2 uv1 : TEXCOORD1;
  55. float2 uv2 : TEXCOORD2;
  56. float4 vertexColor : COLOR;
  57. };
  58. struct VertexOutput {
  59. float4 pos : SV_POSITION;
  60. float2 uv : TEXCOORD0;
  61. float3 darkColor : TEXCOORD1;
  62. float4 vertexColor : COLOR;
  63. };
  64. VertexOutput vert (VertexInput v) {
  65. VertexOutput o;
  66. o.pos = UnityObjectToClipPos(v.vertex); // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  67. o.uv = v.uv;
  68. o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
  69. o.darkColor = float3(v.uv1.r, v.uv1.g, v.uv2.r);
  70. return o;
  71. }
  72. #include "CGIncludes/Spine-Skeleton-Tint-Common.cginc"
  73. float4 frag (VertexOutput i) : SV_Target {
  74. float4 texColor = tex2D(_MainTex, i.uv);
  75. return fragTintedColor(texColor, _Black.rgb + i.darkColor, i.vertexColor, _Color.a, _Black.a);
  76. }
  77. ENDCG
  78. }
  79. Pass {
  80. Name "Caster"
  81. Tags { "LightMode"="ShadowCaster" }
  82. Offset 1, 1
  83. ZWrite On
  84. ZTest LEqual
  85. CGPROGRAM
  86. #pragma vertex vert
  87. #pragma fragment frag
  88. #pragma multi_compile_shadowcaster
  89. #pragma fragmentoption ARB_precision_hint_fastest
  90. #include "UnityCG.cginc"
  91. sampler2D _MainTex;
  92. fixed _Cutoff;
  93. struct v2f {
  94. V2F_SHADOW_CASTER;
  95. float4 uvAndAlpha : TEXCOORD1;
  96. };
  97. v2f vert (appdata_base v, float4 vertexColor : COLOR) {
  98. v2f o;
  99. TRANSFER_SHADOW_CASTER(o)
  100. o.uvAndAlpha = v.texcoord;
  101. o.uvAndAlpha.a = vertexColor.a;
  102. return o;
  103. }
  104. float4 frag (v2f i) : SV_Target {
  105. fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy);
  106. clip(texcol.a * i.uvAndAlpha.a - _Cutoff);
  107. SHADOW_CASTER_FRAGMENT(i)
  108. }
  109. ENDCG
  110. }
  111. }
  112. CustomEditor "SpineShaderWithOutlineGUI"
  113. }