UI-Default.shader 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. Shader /*ase_name*/"Hidden/Templates/UI-Default"/*end*/
  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. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  14. /*ase_props*/
  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 One OneMinusSrcAlpha
  39. ColorMask [_ColorMask]
  40. /*ase_pass*/
  41. Pass
  42. {
  43. Name "Default"
  44. CGPROGRAM
  45. #pragma vertex vert
  46. #pragma fragment frag
  47. #pragma target 3.5
  48. #include "UnityCG.cginc"
  49. #include "UnityUI.cginc"
  50. #pragma multi_compile_local _ UNITY_UI_CLIP_RECT
  51. #pragma multi_compile_local _ UNITY_UI_ALPHACLIP
  52. /*ase_pragma*/
  53. struct appdata_t
  54. {
  55. float4 vertex : POSITION;
  56. float4 color : COLOR;
  57. float2 texcoord : TEXCOORD0;
  58. UNITY_VERTEX_INPUT_INSTANCE_ID
  59. /*ase_vdata:p=p;uv0=tc0.xy;c=c*/
  60. };
  61. struct v2f
  62. {
  63. float4 vertex : SV_POSITION;
  64. fixed4 color : COLOR;
  65. float2 texcoord : TEXCOORD0;
  66. float4 worldPosition : TEXCOORD1;
  67. float4 mask : TEXCOORD2;
  68. UNITY_VERTEX_OUTPUT_STEREO
  69. /*ase_interp(3,):sp=sp.xyzw;uv0=tc0.xy;c=c;uv1=tc1.xyzw*/
  70. };
  71. sampler2D _MainTex;
  72. fixed4 _Color;
  73. fixed4 _TextureSampleAdd;
  74. float4 _ClipRect;
  75. float4 _MainTex_ST;
  76. float _UIMaskSoftnessX;
  77. float _UIMaskSoftnessY;
  78. /*ase_globals*/
  79. v2f vert(appdata_t v /*ase_vert_input*/)
  80. {
  81. v2f OUT;
  82. UNITY_SETUP_INSTANCE_ID(v);
  83. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  84. /*ase_vert_code:v=appdata_t;OUT=v2f*/
  85. v.vertex.xyz += /*ase_vert_out:Offset;Float3*/ float3( 0, 0, 0 ) /*end*/;
  86. float4 vPosition = UnityObjectToClipPos(v.vertex);
  87. OUT.worldPosition = v.vertex;
  88. OUT.vertex = vPosition;
  89. float2 pixelSize = vPosition.w;
  90. pixelSize /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));
  91. float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
  92. float2 maskUV = (v.vertex.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy);
  93. OUT.texcoord = v.texcoord;
  94. OUT.mask = float4(v.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy)));
  95. OUT.color = v.color * _Color;
  96. return OUT;
  97. }
  98. fixed4 frag(v2f IN /*ase_frag_input*/) : SV_Target
  99. {
  100. //Round up the alpha color coming from the interpolator (to 1.0/256.0 steps)
  101. //The incoming alpha could have numerical instability, which makes it very sensible to
  102. //HDR color transparency blend, when it blends with the world's texture.
  103. const half alphaPrecision = half(0xff);
  104. const half invAlphaPrecision = half(1.0/alphaPrecision);
  105. IN.color.a = round(IN.color.a * alphaPrecision)*invAlphaPrecision;
  106. /*ase_frag_code:IN=v2f*/
  107. half4 color = /*ase_frag_out:Color;Float4*/IN.color * (tex2D(_MainTex, TRANSFORM_TEX(IN.texcoord.xy, _MainTex)) + _TextureSampleAdd)/*end*/;
  108. #ifdef UNITY_UI_CLIP_RECT
  109. half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
  110. color.a *= m.x * m.y;
  111. #endif
  112. #ifdef UNITY_UI_ALPHACLIP
  113. clip (color.a - 0.001);
  114. #endif
  115. color.rgb *= color.a;
  116. return color;
  117. }
  118. ENDCG
  119. }
  120. }
  121. CustomEditor "AmplifyShaderEditor.MaterialInspector"
  122. }