Spine-Skeleton-PMA-Screen.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Spine/Skeleton PMA Screen
  2. // - single color multiply tint
  3. // - unlit
  4. // - Premultiplied alpha Multiply blending
  5. // - No depth, no backface culling, no fog.
  6. // - ShadowCaster pass
  7. Shader "Spine/Blend Modes/Skeleton PMA Screen" {
  8. Properties {
  9. _Color ("Tint Color", Color) = (1,1,1,1)
  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. [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
  14. [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
  15. // Outline properties are drawn via custom editor.
  16. [HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
  17. [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
  18. [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
  19. [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
  20. [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
  21. [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
  22. [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
  23. }
  24. SubShader {
  25. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  26. LOD 100
  27. Fog { Mode Off }
  28. Cull Off
  29. ZWrite Off
  30. Blend One OneMinusSrcColor
  31. Lighting Off
  32. Stencil {
  33. Ref[_StencilRef]
  34. Comp[_StencilComp]
  35. Pass Keep
  36. }
  37. Pass {
  38. Name "Normal"
  39. CGPROGRAM
  40. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  41. #pragma vertex vert
  42. #pragma fragment frag
  43. #include "UnityCG.cginc"
  44. uniform sampler2D _MainTex;
  45. uniform float4 _Color;
  46. struct VertexInput {
  47. float4 vertex : POSITION;
  48. float2 uv : TEXCOORD0;
  49. float4 vertexColor : COLOR;
  50. };
  51. struct VertexOutput {
  52. float4 pos : SV_POSITION;
  53. float2 uv : TEXCOORD0;
  54. float4 vertexColor : COLOR;
  55. };
  56. VertexOutput vert (VertexInput v) {
  57. VertexOutput o;
  58. o.pos = UnityObjectToClipPos(v.vertex);
  59. o.uv = v.uv;
  60. o.vertexColor = v.vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
  61. return o;
  62. }
  63. float4 frag (VertexOutput i) : SV_Target {
  64. float4 texColor = tex2D(_MainTex, i.uv);
  65. #if defined(_STRAIGHT_ALPHA_INPUT)
  66. texColor.rgb *= texColor.a;
  67. #endif
  68. return (texColor * i.vertexColor);
  69. }
  70. ENDCG
  71. }
  72. Pass {
  73. Name "Caster"
  74. Tags { "LightMode"="ShadowCaster" }
  75. Offset 1, 1
  76. ZWrite On
  77. ZTest LEqual
  78. CGPROGRAM
  79. #pragma vertex vert
  80. #pragma fragment frag
  81. #pragma multi_compile_shadowcaster
  82. #pragma fragmentoption ARB_precision_hint_fastest
  83. #include "UnityCG.cginc"
  84. struct v2f {
  85. V2F_SHADOW_CASTER;
  86. float4 uvAndAlpha : TEXCOORD1;
  87. };
  88. uniform float4 _MainTex_ST;
  89. v2f vert (appdata_base v, float4 vertexColor : COLOR) {
  90. v2f o;
  91. TRANSFER_SHADOW_CASTER(o)
  92. o.uvAndAlpha.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
  93. o.uvAndAlpha.z = 0;
  94. o.uvAndAlpha.a = vertexColor.a;
  95. return o;
  96. }
  97. uniform sampler2D _MainTex;
  98. uniform fixed _Cutoff;
  99. float4 frag (v2f i) : SV_Target {
  100. fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy);
  101. clip(texcol.a * i.uvAndAlpha.a - _Cutoff);
  102. SHADOW_CASTER_FRAGMENT(i)
  103. }
  104. ENDCG
  105. }
  106. }
  107. CustomEditor "SpineShaderWithOutlineGUI"
  108. }