Spine-Skeleton.shader 3.3 KB

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