Spine-Skeleton.shader 3.0 KB

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