TMP_Sprite.shader 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Shader "TextMeshPro/Sprite"
  2. {
  3. Properties
  4. {
  5. _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. _ClipRect ("Clip Rect", vector) = (-32767, -32767, 32767, 32767)
  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 OneMinusSrcAlpha
  39. ColorMask [_ColorMask]
  40. Pass
  41. {
  42. CGPROGRAM
  43. #pragma vertex vert
  44. #pragma fragment frag
  45. #include "UnityCG.cginc"
  46. #include "UnityUI.cginc"
  47. #pragma multi_compile __ UNITY_UI_CLIP_RECT
  48. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  49. struct appdata_t
  50. {
  51. float4 vertex : POSITION;
  52. float4 color : COLOR;
  53. float2 texcoord : TEXCOORD0;
  54. };
  55. struct v2f
  56. {
  57. float4 vertex : SV_POSITION;
  58. fixed4 color : COLOR;
  59. half2 texcoord : TEXCOORD0;
  60. float4 worldPosition : TEXCOORD1;
  61. };
  62. fixed4 _Color;
  63. fixed4 _TextureSampleAdd;
  64. float4 _ClipRect;
  65. v2f vert(appdata_t IN)
  66. {
  67. v2f OUT;
  68. OUT.worldPosition = IN.vertex;
  69. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  70. OUT.texcoord = IN.texcoord;
  71. #ifdef UNITY_HALF_TEXEL_OFFSET
  72. OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
  73. #endif
  74. OUT.color = IN.color * _Color;
  75. return OUT;
  76. }
  77. sampler2D _MainTex;
  78. fixed4 frag(v2f IN) : SV_Target
  79. {
  80. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  81. #if UNITY_UI_CLIP_RECT
  82. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  83. #endif
  84. #ifdef UNITY_UI_ALPHACLIP
  85. clip (color.a - 0.001);
  86. #endif
  87. return color;
  88. }
  89. ENDCG
  90. }
  91. }
  92. }