Spine-Special-Skeleton-Grayscale.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // - Unlit
  2. // - Premultiplied Alpha Blending (Optional straight alpha input)
  3. // - Double-sided, no depth
  4. Shader "Spine/Special/Skeleton Grayscale" {
  5. Properties {
  6. _GrayPhase ("Phase", Range(0, 1)) = 1
  7. [NoScaleOffset] _MainTex ("MainTex", 2D) = "white" {}
  8. _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
  9. [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
  10. [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
  11. [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
  12. // Outline properties are drawn via custom editor.
  13. [HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
  14. [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
  15. [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
  16. [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
  17. [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
  18. [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
  19. [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
  20. }
  21. SubShader {
  22. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  23. Blend One OneMinusSrcAlpha
  24. Cull Off
  25. ZWrite Off
  26. Lighting Off
  27. Stencil {
  28. Ref[_StencilRef]
  29. Comp[_StencilComp]
  30. Pass Keep
  31. }
  32. Pass {
  33. Name "Normal"
  34. CGPROGRAM
  35. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  36. #pragma vertex vert
  37. #pragma fragment frag
  38. #include "UnityCG.cginc"
  39. sampler2D _MainTex;
  40. float _GrayPhase;
  41. struct VertexInput {
  42. float4 vertex : POSITION;
  43. float2 uv : TEXCOORD0;
  44. float4 vertexColor : COLOR;
  45. };
  46. struct VertexOutput {
  47. float4 pos : SV_POSITION;
  48. float2 uv : TEXCOORD0;
  49. float4 vertexColor : COLOR;
  50. };
  51. VertexOutput vert (VertexInput v) {
  52. VertexOutput o = (VertexOutput)0;
  53. o.uv = v.uv;
  54. o.vertexColor = v.vertexColor;
  55. o.pos = UnityObjectToClipPos(v.vertex);
  56. return o;
  57. }
  58. float4 frag (VertexOutput i) : SV_Target {
  59. float4 rawColor = tex2D(_MainTex,i.uv);
  60. float finalAlpha = (rawColor.a * i.vertexColor.a);
  61. #if defined(_STRAIGHT_ALPHA_INPUT)
  62. rawColor.rgb *= rawColor.a;
  63. #endif
  64. rawColor.rgb *= i.vertexColor.rgb;
  65. float3 finalColor = lerp(rawColor.rgb, dot(rawColor.rgb, float3(0.3, 0.59, 0.11)), _GrayPhase);
  66. return fixed4(finalColor, finalAlpha);
  67. }
  68. ENDCG
  69. }
  70. Pass {
  71. Name "Caster"
  72. Tags { "LightMode"="ShadowCaster" }
  73. Offset 1, 1
  74. ZWrite On
  75. ZTest LEqual
  76. Fog { Mode Off }
  77. Cull Off
  78. Lighting Off
  79. CGPROGRAM
  80. #pragma vertex vert
  81. #pragma fragment frag
  82. #pragma multi_compile_shadowcaster
  83. #pragma fragmentoption ARB_precision_hint_fastest
  84. #include "UnityCG.cginc"
  85. sampler2D _MainTex;
  86. fixed _Cutoff;
  87. struct VertexOutput {
  88. V2F_SHADOW_CASTER;
  89. float4 uvAndAlpha : TEXCOORD1;
  90. };
  91. VertexOutput vert (appdata_base v, float4 vertexColor : COLOR) {
  92. VertexOutput o;
  93. o.uvAndAlpha = v.texcoord;
  94. o.uvAndAlpha.a = vertexColor.a;
  95. TRANSFER_SHADOW_CASTER(o)
  96. return o;
  97. }
  98. float4 frag (VertexOutput i) : SV_Target {
  99. fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy);
  100. clip(texcol.a * i.uvAndAlpha.a - _Cutoff);
  101. SHADOW_CASTER_FRAGMENT(i)
  102. }
  103. ENDCG
  104. }
  105. }
  106. FallBack "Diffuse"
  107. CustomEditor "SpineShaderWithOutlineGUI"
  108. }