FairyGUI-BMFont.shader 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. Shader "FairyGUI/BMFont"
  4. {
  5. Properties
  6. {
  7. _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
  8. _StencilComp ("Stencil Comparison", Float) = 8
  9. _Stencil ("Stencil ID", Float) = 0
  10. _StencilOp ("Stencil Operation", Float) = 0
  11. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  12. _StencilReadMask ("Stencil Read Mask", Float) = 255
  13. _ColorMask ("Color Mask", Float) = 15
  14. _BlendSrcFactor ("Blend SrcFactor", Float) = 5
  15. _BlendDstFactor ("Blend DstFactor", Float) = 10
  16. }
  17. SubShader
  18. {
  19. LOD 100
  20. Tags
  21. {
  22. "Queue" = "Transparent"
  23. "IgnoreProjector" = "True"
  24. "RenderType" = "Transparent"
  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. Fog { Mode Off }
  38. Blend [_BlendSrcFactor] [_BlendDstFactor]
  39. ColorMask [_ColorMask]
  40. Pass
  41. {
  42. CGPROGRAM
  43. #pragma multi_compile NOT_GRAYED GRAYED
  44. #pragma multi_compile NOT_CLIPPED CLIPPED SOFT_CLIPPED
  45. #pragma vertex vert
  46. #pragma fragment frag
  47. #pragma exclude_renderers d3d9 opengl flash
  48. #include "UnityCG.cginc"
  49. struct appdata_t
  50. {
  51. float4 vertex : POSITION;
  52. fixed4 color : COLOR;
  53. float4 texcoord : TEXCOORD0;
  54. };
  55. struct v2f
  56. {
  57. float4 vertex : SV_POSITION;
  58. fixed4 color : COLOR;
  59. float4 texcoord : TEXCOORD0;
  60. #ifdef CLIPPED
  61. float2 clipPos : TEXCOORD1;
  62. #endif
  63. #ifdef SOFT_CLIPPED
  64. float2 clipPos : TEXCOORD1;
  65. #endif
  66. };
  67. sampler2D _MainTex;
  68. CBUFFER_START(UnityPerMaterial)
  69. #ifdef CLIPPED
  70. float4 _ClipBox = float4(-2, -2, 0, 0);
  71. #endif
  72. #ifdef SOFT_CLIPPED
  73. float4 _ClipBox = float4(-2, -2, 0, 0);
  74. float4 _ClipSoftness = float4(0, 0, 0, 0);
  75. #endif
  76. CBUFFER_END
  77. v2f vert (appdata_t v)
  78. {
  79. v2f o;
  80. o.vertex = UnityObjectToClipPos(v.vertex);
  81. o.texcoord = v.texcoord;
  82. #if !defined(UNITY_COLORSPACE_GAMMA) && (UNITY_VERSION >= 550)
  83. o.color.rgb = GammaToLinearSpace(v.color.rgb);
  84. o.color.a = v.color.a;
  85. #else
  86. o.color = v.color;
  87. #endif
  88. #ifdef CLIPPED
  89. o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
  90. #endif
  91. #ifdef SOFT_CLIPPED
  92. o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
  93. #endif
  94. return o;
  95. }
  96. fixed4 frag (v2f i) : SV_Target
  97. {
  98. fixed4 col = i.color;
  99. fixed4 tcol = tex2D(_MainTex, i.texcoord);
  100. col.a *= tcol[i.texcoord.z];//z stores channel
  101. #ifdef GRAYED
  102. fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
  103. col.rgb = fixed3(grey, grey, grey);
  104. #endif
  105. #ifdef SOFT_CLIPPED
  106. float2 factor = float2(0,0);
  107. if(i.clipPos.x<0)
  108. factor.x = (1.0-abs(i.clipPos.x)) * _ClipSoftness.x;
  109. else
  110. factor.x = (1.0-i.clipPos.x) * _ClipSoftness.z;
  111. if(i.clipPos.y<0)
  112. factor.y = (1.0-abs(i.clipPos.y)) * _ClipSoftness.w;
  113. else
  114. factor.y = (1.0-i.clipPos.y) * _ClipSoftness.y;
  115. col.a *= clamp(min(factor.x, factor.y), 0.0, 1.0);
  116. #endif
  117. #ifdef CLIPPED
  118. float2 factor = abs(i.clipPos);
  119. col.a *= step(max(factor.x, factor.y), 1);
  120. #endif
  121. return col;
  122. }
  123. ENDCG
  124. }
  125. }
  126. Fallback "FairyGUI/Text"
  127. }