Spine-SkeletonGraphic-TintBlack.shader 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // This is a premultiply-alpha adaptation of the built-in Unity shader "UI/Default" to allow Unity UI stencil masking.
  2. Shader "Spine/SkeletonGraphic Tint Black"
  3. {
  4. Properties
  5. {
  6. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  7. [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
  8. [Toggle(_CANVAS_GROUP_COMPATIBLE)] _CanvasGroupCompatible("CanvasGroup Compatible", Int) = 0
  9. _Color ("Tint Color", Color) = (1,1,1,1)
  10. _Black ("Dark Color", Color) = (0,0,0,0)
  11. [Toggle(_DARK_COLOR_ALPHA_ADDITIVE)] _DarkColorAlphaAdditive("Additive DarkColor.A", Int) = 0
  12. [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Float) = 8
  13. [HideInInspector] _Stencil ("Stencil ID", Float) = 0
  14. [HideInInspector][Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Operation", Float) = 0
  15. [HideInInspector] _StencilWriteMask ("Stencil Write Mask", Float) = 255
  16. [HideInInspector] _StencilReadMask ("Stencil Read Mask", Float) = 255
  17. [HideInInspector] _ColorMask ("Color Mask", Float) = 15
  18. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  19. // Outline properties are drawn via custom editor.
  20. [HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
  21. [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
  22. [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
  23. [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
  24. [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
  25. [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
  26. [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
  27. }
  28. SubShader
  29. {
  30. Tags
  31. {
  32. "Queue"="Transparent"
  33. "IgnoreProjector"="True"
  34. "RenderType"="Transparent"
  35. "PreviewType"="Plane"
  36. "CanUseSpriteAtlas"="True"
  37. }
  38. Stencil
  39. {
  40. Ref [_Stencil]
  41. Comp [_StencilComp]
  42. Pass [_StencilOp]
  43. ReadMask [_StencilReadMask]
  44. WriteMask [_StencilWriteMask]
  45. }
  46. Cull Off
  47. Lighting Off
  48. ZWrite Off
  49. ZTest [unity_GUIZTestMode]
  50. Fog { Mode Off }
  51. Blend One OneMinusSrcAlpha
  52. ColorMask [_ColorMask]
  53. Pass
  54. {
  55. Name "Normal"
  56. CGPROGRAM
  57. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  58. #pragma shader_feature _ _CANVAS_GROUP_COMPATIBLE
  59. #pragma shader_feature _ _DARK_COLOR_ALPHA_ADDITIVE
  60. #pragma vertex vert
  61. #pragma fragment frag
  62. #include "UnityCG.cginc"
  63. #include "UnityUI.cginc"
  64. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  65. struct VertexInput {
  66. float4 vertex : POSITION;
  67. float4 color : COLOR;
  68. float2 texcoord : TEXCOORD0;
  69. float2 uv1 : TEXCOORD1;
  70. float2 uv2 : TEXCOORD2;
  71. UNITY_VERTEX_INPUT_INSTANCE_ID
  72. };
  73. struct VertexOutput {
  74. float4 vertex : SV_POSITION;
  75. fixed4 color : COLOR;
  76. half2 texcoord : TEXCOORD0;
  77. float4 darkColor : TEXCOORD1;
  78. float4 worldPosition : TEXCOORD2;
  79. UNITY_VERTEX_OUTPUT_STEREO
  80. };
  81. fixed4 _Color;
  82. fixed4 _Black;
  83. fixed4 _TextureSampleAdd;
  84. float4 _ClipRect;
  85. VertexOutput vert (VertexInput IN) {
  86. VertexOutput OUT;
  87. UNITY_SETUP_INSTANCE_ID(IN);
  88. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  89. OUT.worldPosition = IN.vertex;
  90. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  91. OUT.texcoord = IN.texcoord;
  92. OUT.color = IN.color;
  93. OUT.darkColor = float4(IN.uv1.r, IN.uv1.g, IN.uv2.r, IN.uv2.g);
  94. return OUT;
  95. }
  96. sampler2D _MainTex;
  97. #include "../CGIncludes/Spine-Skeleton-Tint-Common.cginc"
  98. fixed4 frag (VertexOutput IN) : SV_Target
  99. {
  100. half4 texColor = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd);
  101. texColor *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  102. #ifdef UNITY_UI_ALPHACLIP
  103. clip(texColor.a - 0.001);
  104. #endif
  105. float4 vertexColor = IN.color * float4(_Color.rgb * _Color.a, _Color.a);
  106. #ifdef _CANVAS_GROUP_COMPATIBLE
  107. // CanvasGroup alpha multiplies existing vertex color alpha, but
  108. // does not premultiply it to rgb components. This causes problems
  109. // with additive blending (alpha = 0), which is why we store the
  110. // alpha value in uv2.g (darkColor.a).
  111. float originalAlpha = IN.darkColor.a;
  112. float canvasAlpha = (originalAlpha == 0) ? IN.color.a : IN.color.a / originalAlpha;
  113. vertexColor.a = originalAlpha * _Color.a;
  114. #endif
  115. float4 fragColor = fragTintedColor(texColor, _Black.rgb + IN.darkColor, vertexColor, _Color.a, _Black.a);
  116. #ifdef _CANVAS_GROUP_COMPATIBLE
  117. fragColor.rgba *= canvasAlpha;
  118. #endif
  119. return fragColor;
  120. }
  121. ENDCG
  122. }
  123. }
  124. CustomEditor "SpineShaderWithOutlineGUI"
  125. }