UIOverlay.shader 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /************************************************************************************
  2. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
  4. https://developer.oculus.com/licenses/oculussdk/
  5. Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
  6. under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  7. ANY KIND, either express or implied. See the License for the specific language governing
  8. permissions and limitations under the License.
  9. ************************************************************************************/
  10. Shader "UI/Default (Overlay)"
  11. {
  12. Properties
  13. {
  14. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  15. _Color ("Tint", Color) = (1,1,1,1)
  16. _StencilComp ("Stencil Comparison", Float) = 8
  17. _Stencil ("Stencil ID", Float) = 0
  18. _StencilOp ("Stencil Operation", Float) = 0
  19. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  20. _StencilReadMask ("Stencil Read Mask", Float) = 255
  21. _ColorMask ("Color Mask", Float) = 15
  22. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  23. }
  24. SubShader
  25. {
  26. Tags
  27. {
  28. "Queue"="Transparent"
  29. "IgnoreProjector"="True"
  30. "RenderType"="Transparent"
  31. "PreviewType"="Plane"
  32. "CanUseSpriteAtlas"="True"
  33. }
  34. Stencil
  35. {
  36. Ref [_Stencil]
  37. Comp [_StencilComp]
  38. Pass [_StencilOp]
  39. ReadMask [_StencilReadMask]
  40. WriteMask [_StencilWriteMask]
  41. }
  42. Cull Off
  43. Lighting Off
  44. ZWrite Off
  45. ZTest [unity_GUIZTestMode]
  46. Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
  47. ColorMask [_ColorMask]
  48. Pass
  49. {
  50. Name "Default"
  51. CGPROGRAM
  52. #pragma vertex vert
  53. #pragma fragment frag
  54. #pragma target 2.0
  55. #include "UnityCG.cginc"
  56. #include "UnityUI.cginc"
  57. #pragma multi_compile __ UNITY_UI_CLIP_RECT
  58. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  59. struct appdata_t
  60. {
  61. float4 vertex : POSITION;
  62. float4 color : COLOR;
  63. float2 texcoord : TEXCOORD0;
  64. UNITY_VERTEX_INPUT_INSTANCE_ID
  65. };
  66. struct v2f
  67. {
  68. float4 vertex : SV_POSITION;
  69. fixed4 color : COLOR;
  70. float2 texcoord : TEXCOORD0;
  71. float4 worldPosition : TEXCOORD1;
  72. UNITY_VERTEX_OUTPUT_STEREO
  73. };
  74. sampler2D _MainTex;
  75. fixed4 _Color;
  76. fixed4 _TextureSampleAdd;
  77. float4 _ClipRect;
  78. float4 _MainTex_ST;
  79. v2f vert(appdata_t v)
  80. {
  81. v2f OUT;
  82. UNITY_SETUP_INSTANCE_ID(v);
  83. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  84. OUT.worldPosition = v.vertex;
  85. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  86. OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  87. OUT.color = v.color * _Color;
  88. return OUT;
  89. }
  90. fixed4 frag(v2f IN) : SV_Target
  91. {
  92. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  93. #ifdef UNITY_UI_CLIP_RECT
  94. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  95. #endif
  96. #ifdef UNITY_UI_ALPHACLIP
  97. clip (color.a - 0.001);
  98. #endif
  99. return color;
  100. }
  101. ENDCG
  102. }
  103. }
  104. }