GxrQuitDialogUIDefault.shader 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //==========================================================
  2. //
  3. // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
  4. // All rights reserved.
  5. //
  6. //==========================================================
  7. Shader "GxrSdk/QuitDialog/UIDefault"
  8. {
  9. Properties
  10. {
  11. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  12. _Color ("Tint", Color) = (1,1,1,1)
  13. _StencilComp ("Stencil Comparison", Float) = 8
  14. _Stencil ("Stencil ID", Float) = 0
  15. _StencilOp ("Stencil Operation", Float) = 0
  16. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  17. _StencilReadMask ("Stencil Read Mask", Float) = 255
  18. _ColorMask ("Color Mask", Float) = 15
  19. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  20. }
  21. SubShader
  22. {
  23. Tags
  24. {
  25. "Queue"="Transparent"
  26. "IgnoreProjector"="True"
  27. "RenderType"="Transparent"
  28. "PreviewType"="Plane"
  29. "CanUseSpriteAtlas"="True"
  30. }
  31. Stencil
  32. {
  33. Ref [_Stencil]
  34. Comp [_StencilComp]
  35. Pass [_StencilOp]
  36. ReadMask [_StencilReadMask]
  37. WriteMask [_StencilWriteMask]
  38. }
  39. Cull Off
  40. Lighting Off
  41. ZWrite Off
  42. ZTest [unity_GUIZTestMode]
  43. Blend SrcAlpha OneMinusSrcAlpha
  44. ColorMask [_ColorMask]
  45. Pass
  46. {
  47. Name "Default"
  48. CGPROGRAM
  49. #pragma vertex vert
  50. #pragma fragment frag
  51. #pragma target 2.0
  52. #include "UnityCG.cginc"
  53. #include "UnityUI.cginc"
  54. #pragma multi_compile_local _ UNITY_UI_CLIP_RECT
  55. #pragma multi_compile_local _ UNITY_UI_ALPHACLIP
  56. struct appdata_t
  57. {
  58. float4 vertex : POSITION;
  59. float4 color : COLOR;
  60. float2 texcoord : TEXCOORD0;
  61. UNITY_VERTEX_INPUT_INSTANCE_ID
  62. };
  63. struct v2f
  64. {
  65. float4 vertex : SV_POSITION;
  66. fixed4 color : COLOR;
  67. float2 texcoord : TEXCOORD0;
  68. float4 worldPosition : TEXCOORD1;
  69. half4 mask : TEXCOORD2;
  70. UNITY_VERTEX_OUTPUT_STEREO
  71. };
  72. sampler2D _MainTex;
  73. fixed4 _Color;
  74. fixed4 _TextureSampleAdd;
  75. float4 _ClipRect;
  76. float4 _MainTex_ST;
  77. float _UIMaskSoftnessX;
  78. float _UIMaskSoftnessY;
  79. v2f vert(appdata_t v)
  80. {
  81. v2f OUT;
  82. UNITY_SETUP_INSTANCE_ID(v);
  83. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  84. float4 vPosition = UnityObjectToClipPos(v.vertex);
  85. OUT.worldPosition = v.vertex;
  86. OUT.vertex = vPosition;
  87. float2 pixelSize = vPosition.w;
  88. pixelSize /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));
  89. float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
  90. float2 maskUV = (v.vertex.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy);
  91. OUT.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
  92. OUT.mask = half4(v.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy)));
  93. OUT.color = v.color * _Color;
  94. return OUT;
  95. }
  96. fixed4 frag(v2f IN) : SV_Target
  97. {
  98. half4 color = IN.color * (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd);
  99. #ifdef UNITY_UI_CLIP_RECT
  100. half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
  101. color.a *= m.x * m.y;
  102. #endif
  103. #ifdef UNITY_UI_ALPHACLIP
  104. clip (color.a - 0.001);
  105. #endif
  106. return color;
  107. }
  108. ENDCG
  109. }
  110. }
  111. }