MaxBlend.shader 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. Shader "UI/Soft Mask/Max Blend"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _Color("Tint", Color) = (1,1,1,1)
  7. _StencilComp("Stencil Comparison", Float) = 8
  8. _Stencil("Stencil ID", Float) = 0
  9. _StencilOp("Stencil Operation", Float) = 0
  10. _StencilWriteMask("Stencil Write Mask", Float) = 255
  11. _StencilReadMask("Stencil Read Mask", Float) = 255
  12. _ColorMask("Color Mask", Float) = 15
  13. _BlendOp("Blend Operation", Float) = 0
  14. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
  15. }
  16. SubShader
  17. {
  18. Tags
  19. {
  20. "Queue" = "Transparent"
  21. "IgnoreProjector" = "True"
  22. "RenderType" = "Transparent"
  23. "PreviewType" = "Plane"
  24. "CanUseSpriteAtlas" = "True"
  25. }
  26. Stencil
  27. {
  28. Ref[_Stencil]
  29. Comp[_StencilComp]
  30. Pass[_StencilOp]
  31. ReadMask[_StencilReadMask]
  32. WriteMask[_StencilWriteMask]
  33. }
  34. Cull Off
  35. Lighting Off
  36. ZWrite Off
  37. ZTest[unity_GUIZTestMode]
  38. Blend SrcAlpha One
  39. BlendOp [_BlendOp]
  40. ColorMask[_ColorMask]
  41. Pass
  42. {
  43. CGPROGRAM
  44. #pragma vertex vert
  45. #pragma fragment frag
  46. #pragma target 3.0
  47. #include "UnityCG.cginc"
  48. #include "UnityUI.cginc"
  49. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  50. struct appdata_t
  51. {
  52. float4 vertex : POSITION;
  53. float4 color : COLOR;
  54. float2 texcoord : TEXCOORD0;
  55. };
  56. struct v2f
  57. {
  58. float4 vertex : SV_POSITION;
  59. fixed4 color : COLOR;
  60. half2 texcoord : TEXCOORD0;
  61. float4 worldPosition : TEXCOORD1;
  62. };
  63. fixed4 _Color;
  64. fixed4 _TextureSampleAdd;
  65. float4 _ClipRect;
  66. v2f vert(appdata_t IN)
  67. {
  68. v2f OUT;
  69. OUT.worldPosition = IN.vertex;
  70. #if UNITY_VERSION >= 540
  71. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  72. #else
  73. OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
  74. #endif
  75. OUT.texcoord = IN.texcoord;
  76. #ifdef UNITY_HALF_TEXEL_OFFSET
  77. OUT.vertex.xy += (_ScreenParams.zw - 1.0) * float2(-1, 1);
  78. #endif
  79. OUT.color = IN.color * _Color;
  80. return OUT;
  81. }
  82. sampler2D _MainTex;
  83. fixed4 frag(v2f IN) : SV_Target
  84. {
  85. half4 tex = tex2D(_MainTex, IN.texcoord);
  86. half4 color = (tex + _TextureSampleAdd) * IN.color;
  87. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  88. #ifdef UNITY_UI_ALPHACLIP
  89. clip(color.a - 0.001);
  90. #endif
  91. return color;
  92. }
  93. ENDCG
  94. }
  95. }
  96. }
  97. // UNITY_SHADER_NO_UPGRADE