XGame-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. // FairyGUI/Text 从该shader修改而来
  4. Shader "XGame/Text Shader"
  5. {
  6. Properties
  7. {
  8. _MainTex ("Alpha (A)", 2D) = "white" {}
  9. _StencilComp ("Stencil Comparison", Float) = 8
  10. _Stencil ("Stencil ID", Float) = 0
  11. _StencilOp ("Stencil Operation", Float) = 0
  12. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  13. _StencilReadMask ("Stencil Read Mask", Float) = 255
  14. _ColorMask ("Color Mask", Float) = 15
  15. _BlendSrcFactor ("Blend SrcFactor", Float) = 5
  16. _BlendDstFactor ("Blend DstFactor", Float) = 10
  17. }
  18. SubShader
  19. {
  20. LOD 100
  21. Tags
  22. {
  23. "Queue" = "Transparent"
  24. "IgnoreProjector" = "True"
  25. "RenderType" = "Transparent"
  26. }
  27. Stencil
  28. {
  29. Ref [_Stencil]
  30. Comp [_StencilComp]
  31. Pass [_StencilOp]
  32. ReadMask [_StencilReadMask]
  33. WriteMask [_StencilWriteMask]
  34. }
  35. Cull Off
  36. Lighting Off
  37. ZWrite Off
  38. Fog { Mode Off }
  39. Blend [_BlendSrcFactor] [_BlendDstFactor]
  40. ColorMask [_ColorMask]
  41. Pass
  42. {
  43. CGPROGRAM
  44. #pragma multi_compile NOT_GRAYED GRAYED
  45. #pragma multi_compile NOT_CLIPPED CLIPPED SOFT_CLIPPED
  46. #pragma vertex vert
  47. #pragma fragment frag
  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. // 颜色值取贴图的颜色
  100. col *= tex2D(_MainTex, i.texcoord);
  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. //
  127. Fallback "FairyGUI/Text"
  128. }