Standard.shader 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. Shader "BetterUI/Standard"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _StencilComp("Stencil Comparison", Float) = 8
  7. _Stencil("Stencil ID", Float) = 0
  8. _StencilOp("Stencil Operation", Float) = 0
  9. _StencilWriteMask("Stencil Write Mask", Float) = 255
  10. _StencilReadMask("Stencil Read Mask", Float) = 255
  11. _ColorMask("Color Mask", Float) = 15
  12. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
  13. SrcBlendMode ("SrcBlendMode", Float) = 5
  14. DstBlendMode ("DstBlendMode", Float) = 10
  15. [Toggle(COMBINE_ALPHA)] CombineAlpha("Combine Alpha", Float) = 0
  16. [Toggle(FORCE_CLIP)] ForceClip("Force Clip", Float) = 0
  17. ClipThreshold("Alpha Clip Threshold", Float) = 0.5
  18. }
  19. SubShader
  20. {
  21. Tags
  22. {
  23. "Queue" = "Transparent"
  24. "IgnoreProjector" = "True"
  25. "RenderType" = "Transparent"
  26. "PreviewType" = "Plane"
  27. "CanUseSpriteAtlas" = "True"
  28. }
  29. Stencil
  30. {
  31. Ref[_Stencil]
  32. Comp[_StencilComp]
  33. Pass[_StencilOp]
  34. ReadMask[_StencilReadMask]
  35. WriteMask[_StencilWriteMask]
  36. }
  37. Cull Off
  38. Lighting Off
  39. ZWrite Off
  40. ZTest[unity_GUIZTestMode]
  41. Blend [SrcBlendMode] [DstBlendMode]
  42. ColorMask[_ColorMask]
  43. Pass
  44. {
  45. Name "Standard"
  46. CGPROGRAM
  47. #pragma vertex vert
  48. #pragma fragment frag
  49. #pragma target 2.0
  50. #include "UnityCG.cginc"
  51. #include "UnityUI.cginc"
  52. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  53. #pragma multi_compile __ COMBINE_ALPHA
  54. #pragma multi_compile __ FORCE_CLIP
  55. struct appdata_t
  56. {
  57. float4 vertex : POSITION;
  58. float4 color : COLOR;
  59. float2 texcoord : TEXCOORD0;
  60. #if UNITY_VERSION >= 550
  61. UNITY_VERTEX_INPUT_INSTANCE_ID
  62. #endif
  63. };
  64. struct v2f
  65. {
  66. float4 vertex : SV_POSITION;
  67. fixed4 color : COLOR;
  68. float2 texcoord : TEXCOORD0;
  69. float4 worldPosition : TEXCOORD1;
  70. #if UNITY_VERSION >= 550
  71. UNITY_VERTEX_OUTPUT_STEREO
  72. #endif
  73. };
  74. fixed4 _TextureSampleAdd;
  75. float4 _ClipRect;
  76. #if UNITY_VERSION < 550
  77. bool _UseClipRect;
  78. bool _UseAlphaClip;
  79. bool CombineAlpha;
  80. bool ForceClip;
  81. #endif
  82. // VERTEX SHADER
  83. v2f vert(appdata_t IN)
  84. {
  85. v2f OUT;
  86. #if UNITY_VERSION >= 550
  87. UNITY_SETUP_INSTANCE_ID(IN);
  88. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  89. #endif
  90. OUT.worldPosition = IN.vertex;
  91. #if UNITY_VERSION >= 550
  92. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  93. #else
  94. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  95. #ifdef UNITY_HALF_TEXEL_OFFSET
  96. OUT.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1, 1);
  97. #endif
  98. #endif
  99. OUT.texcoord = IN.texcoord;
  100. OUT.color = IN.color;
  101. return OUT;
  102. }
  103. sampler2D _MainTex;
  104. float ClipThreshold;
  105. // FRAGMENT SHADER
  106. fixed4 frag(v2f IN) : SV_Target
  107. {
  108. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  109. #if UNITY_VERSION >= 550
  110. #ifdef COMBINE_ALPHA
  111. color.rgb *= color.a;
  112. #endif
  113. #ifdef FORCE_CLIP
  114. clip(color.a - ClipThreshold);
  115. #endif
  116. #else
  117. if (CombineAlpha)
  118. color.rgb *= color.a;
  119. if (ForceClip)
  120. clip(color.a - ClipThreshold);
  121. #endif
  122. #if UNITY_VERSION >= 550
  123. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  124. #ifdef UNITY_UI_ALPHACLIP
  125. clip(color.a - ClipThreshold);
  126. #endif
  127. #else
  128. if (_UseClipRect)
  129. color *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  130. if (_UseAlphaClip)
  131. clip(color.a - ClipThreshold);
  132. #endif
  133. return color;
  134. }
  135. ENDCG
  136. }
  137. }
  138. }