UIEffect.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Shader "Hidden/UI/Default (UIEffect)"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex ("Main 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. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  14. _ParamTex ("Parameter Texture", 2D) = "white" {}
  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 OneMinusSrcAlpha
  39. ColorMask [_ColorMask]
  40. Pass
  41. {
  42. Name "Default"
  43. CGPROGRAM
  44. #pragma vertex vert
  45. #pragma fragment frag
  46. #if !defined(SHADER_API_D3D11_9X) && !defined(SHADER_API_D3D9)
  47. #pragma target 2.0
  48. #else
  49. #pragma target 3.0
  50. #endif
  51. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  52. #pragma multi_compile __ GRAYSCALE SEPIA NEGA PIXEL
  53. #pragma multi_compile __ ADD SUBTRACT FILL
  54. #pragma multi_compile __ FASTBLUR MEDIUMBLUR DETAILBLUR
  55. #pragma multi_compile __ EX
  56. #include "UnityCG.cginc"
  57. #include "UnityUI.cginc"
  58. #define UI_EFFECT 1
  59. #include "UIEffect.cginc"
  60. #include "UIEffectSprite.cginc"
  61. fixed4 frag(v2f IN) : SV_Target
  62. {
  63. fixed4 param = tex2D(_ParamTex, float2(0.25, IN.eParam));
  64. fixed effectFactor = param.x;
  65. fixed colorFactor = param.y;
  66. fixed blurFactor = param.z;
  67. #if PIXEL
  68. half2 pixelSize = max(2, (1-effectFactor*0.95) * _MainTex_TexelSize.zw);
  69. IN.texcoord = round(IN.texcoord * pixelSize) / pixelSize;
  70. #endif
  71. #if defined(UI_BLUR) && EX
  72. half4 color = (Tex2DBlurring(_MainTex, IN.texcoord, blurFactor * _MainTex_TexelSize.xy * 2, IN.uvMask) + _TextureSampleAdd);
  73. #elif defined(UI_BLUR)
  74. half4 color = (Tex2DBlurring(_MainTex, IN.texcoord, blurFactor * _MainTex_TexelSize.xy * 2) + _TextureSampleAdd);
  75. #else
  76. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd);
  77. #endif
  78. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  79. #if UNITY_UI_ALPHACLIP
  80. clip (color.a - 0.001);
  81. #endif
  82. #if defined (UI_TONE)
  83. color = ApplyToneEffect(color, effectFactor);
  84. #endif
  85. color = ApplyColorEffect(color, fixed4(IN.color.rgb, colorFactor));
  86. color.a *= IN.color.a;
  87. return color;
  88. }
  89. ENDCG
  90. }
  91. }
  92. }