FairyGUI-Text.shader 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. Shader "FairyGUI/Text"
  4. {
  5. Properties
  6. {
  7. _MainTex ("Alpha (A)", 2D) = "white" {}
  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. #include "UnityCG.cginc"
  48. struct appdata_t
  49. {
  50. float4 vertex : POSITION;
  51. fixed4 color : COLOR;
  52. float4 texcoord : TEXCOORD0;
  53. };
  54. struct v2f
  55. {
  56. float4 vertex : SV_POSITION;
  57. fixed4 color : COLOR;
  58. float4 texcoord : TEXCOORD0;
  59. #ifdef CLIPPED
  60. float2 clipPos : TEXCOORD1;
  61. #endif
  62. #ifdef SOFT_CLIPPED
  63. float2 clipPos : TEXCOORD1;
  64. #endif
  65. };
  66. sampler2D _MainTex;
  67. CBUFFER_START(UnityPerMaterial)
  68. #ifdef CLIPPED
  69. float4 _ClipBox = float4(-2, -2, 0, 0);
  70. #endif
  71. #ifdef SOFT_CLIPPED
  72. float4 _ClipBox = float4(-2, -2, 0, 0);
  73. float4 _ClipSoftness = float4(0, 0, 0, 0);
  74. #endif
  75. CBUFFER_END
  76. v2f vert (appdata_t v)
  77. {
  78. v2f o;
  79. o.vertex = UnityObjectToClipPos(v.vertex);
  80. o.texcoord = v.texcoord;
  81. #if !defined(UNITY_COLORSPACE_GAMMA) && (UNITY_VERSION >= 550)
  82. o.color.rgb = GammaToLinearSpace(v.color.rgb);
  83. o.color.a = v.color.a;
  84. #else
  85. o.color = v.color;
  86. #endif
  87. #ifdef CLIPPED
  88. o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
  89. #endif
  90. #ifdef SOFT_CLIPPED
  91. o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
  92. #endif
  93. return o;
  94. }
  95. fixed4 frag (v2f i) : SV_Target
  96. {
  97. fixed4 col = i.color;
  98. col.a *= tex2D(_MainTex, i.texcoord).a;
  99. #ifdef GRAYED
  100. fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
  101. col.rgb = fixed3(grey, grey, grey);
  102. #endif
  103. #ifdef SOFT_CLIPPED
  104. float2 factor = float2(0,0);
  105. if(i.clipPos.x<0)
  106. factor.x = (1.0-abs(i.clipPos.x)) * _ClipSoftness.x;
  107. else
  108. factor.x = (1.0-i.clipPos.x) * _ClipSoftness.z;
  109. if(i.clipPos.y<0)
  110. factor.y = (1.0-abs(i.clipPos.y)) * _ClipSoftness.w;
  111. else
  112. factor.y = (1.0-i.clipPos.y) * _ClipSoftness.y;
  113. col.a *= clamp(min(factor.x, factor.y), 0.0, 1.0);
  114. #endif
  115. #ifdef CLIPPED
  116. float2 factor = abs(i.clipPos);
  117. col.a *= step(max(factor.x, factor.y), 1);
  118. #endif
  119. return col;
  120. }
  121. ENDCG
  122. }
  123. }
  124. }