Font4.shader 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. 
  2. Shader "BFI/Font4"
  3. {
  4. Properties
  5. {
  6. _MainTex("Texture", 2D) = "white" {}
  7. _MainTex2("Texture2", 2D) = "white" {}
  8. _MainTex3("Texture3", 2D) = "white" {}
  9. _MainTex4("Texture4", 2D) = "white" {}
  10. _Color("Tint", Color) = (1,1,1,1)
  11. _StencilComp("Stencil Comparison", Float) = 8
  12. _Stencil("Stencil ID", Float) = 0
  13. _StencilOp("Stencil Operation", Float) = 0
  14. _StencilWriteMask("Stencil Write Mask", Float) = 255
  15. _StencilReadMask("Stencil Read Mask", Float) = 255
  16. _ColorMask("Color Mask", Float) = 15
  17. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
  18. }
  19. SubShader
  20. {
  21. Tags
  22. {
  23. "Queue" = "Transparent"
  24. "IgnoreProjector" = "True"
  25. "RenderType" = "Transparent"
  26. "PreviewType" = "Plane"
  27. "CanUseSpriteAtlas" = "True"
  28. }
  29. Stencil
  30. {
  31. Ref[_Stencil]
  32. Comp[_StencilComp]
  33. Pass[_StencilOp]
  34. ReadMask[_StencilReadMask]
  35. WriteMask[_StencilWriteMask]
  36. }
  37. Cull Off
  38. Lighting Off
  39. ZWrite Off
  40. ZTest[unity_GUIZTestMode]
  41. Blend SrcAlpha OneMinusSrcAlpha
  42. ColorMask[_ColorMask]
  43. Pass
  44. {
  45. Name "Default"
  46. CGPROGRAM
  47. #pragma vertex vert
  48. #pragma fragment frag
  49. #pragma target 2.0
  50. #include "UnityCG.cginc"
  51. #include "UnityUI.cginc"
  52. #include "BFILogic.cginc"
  53. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  54. struct appdata_t
  55. {
  56. float4 vertex : POSITION;
  57. float4 color : COLOR;
  58. float2 texcoord : TEXCOORD0;
  59. UNITY_VERTEX_INPUT_INSTANCE_ID
  60. };
  61. struct v2f
  62. {
  63. float4 vertex : SV_POSITION;
  64. fixed4 color : COLOR;
  65. float2 texcoord : TEXCOORD0;
  66. float4 worldPosition : TEXCOORD1;
  67. UNITY_VERTEX_OUTPUT_STEREO
  68. };
  69. fixed4 _Color;
  70. fixed4 _TextureSampleAdd;
  71. float4 _ClipRect;
  72. v2f vert(appdata_t v)
  73. {
  74. v2f OUT;
  75. UNITY_SETUP_INSTANCE_ID(v);
  76. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  77. OUT.worldPosition = v.vertex;
  78. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  79. OUT.texcoord = v.texcoord;
  80. OUT.color = v.color * _Color;
  81. return OUT;
  82. }
  83. sampler2D _MainTex;
  84. sampler2D _MainTex2;
  85. sampler2D _MainTex3;
  86. sampler2D _MainTex4;
  87. fixed4 frag(v2f IN) : SV_Target
  88. {
  89. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  90. half4 color2 = (tex2D(_MainTex2, IN.texcoord - float2(1.0, 0)) + _TextureSampleAdd) * IN.color;
  91. half4 color3 = (tex2D(_MainTex3, IN.texcoord - float2(2.0, 0)) + _TextureSampleAdd) * IN.color;
  92. half4 color4 = (tex2D(_MainTex4, IN.texcoord - float2(3.0, 0)) + _TextureSampleAdd) * IN.color;
  93. color *= when_le(IN.texcoord.x, 1.0);
  94. color2 *= and(when_gt(IN.texcoord.x, 1.0), when_le(IN.texcoord.x, 2.0));
  95. color3 *= and(when_gt(IN.texcoord.x, 2.0), when_le(IN.texcoord.x, 3.0));
  96. color4 *= when_gt(IN.texcoord.x, 3.0);
  97. color += color2 + color3 + color4;
  98. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  99. #ifdef UNITY_UI_ALPHACLIP
  100. clip(color.a - 0.001);
  101. #endif
  102. return color;
  103. }
  104. ENDCG
  105. }
  106. }
  107. }