FairyGUI-Image.shader 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. Shader "FairyGUI/Image"
  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], One One
  39. ColorMask [_ColorMask]
  40. Pass
  41. {
  42. CGPROGRAM
  43. #pragma multi_compile NOT_COMBINED COMBINED
  44. #pragma multi_compile NOT_GRAYED GRAYED COLOR_FILTER
  45. #pragma multi_compile NOT_CLIPPED CLIPPED SOFT_CLIPPED ALPHA_MASK
  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. #ifdef COMBINED
  69. sampler2D _AlphaTex;
  70. #endif
  71. CBUFFER_START(UnityPerMaterial)
  72. #ifdef CLIPPED
  73. float4 _ClipBox = float4(-2, -2, 0, 0);
  74. #endif
  75. #ifdef SOFT_CLIPPED
  76. float4 _ClipBox = float4(-2, -2, 0, 0);
  77. float4 _ClipSoftness = float4(0, 0, 0, 0);
  78. #endif
  79. CBUFFER_END
  80. #ifdef COLOR_FILTER
  81. float4x4 _ColorMatrix;
  82. float4 _ColorOffset;
  83. float _ColorOption = 0;
  84. #endif
  85. v2f vert (appdata_t v)
  86. {
  87. v2f o;
  88. o.vertex = UnityObjectToClipPos(v.vertex);
  89. o.texcoord = v.texcoord;
  90. #if !defined(UNITY_COLORSPACE_GAMMA) && (UNITY_VERSION >= 550)
  91. o.color.rgb = GammaToLinearSpace(v.color.rgb);
  92. o.color.a = v.color.a;
  93. #else
  94. o.color = v.color;
  95. #endif
  96. #ifdef CLIPPED
  97. o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
  98. #endif
  99. #ifdef SOFT_CLIPPED
  100. o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
  101. #endif
  102. return o;
  103. }
  104. fixed4 frag (v2f i) : SV_Target
  105. {
  106. fixed4 col = tex2D(_MainTex, i.texcoord.xy / i.texcoord.w) * i.color;
  107. #ifdef COMBINED
  108. col.a *= tex2D(_AlphaTex, i.texcoord.xy / i.texcoord.w).g;
  109. #endif
  110. #ifdef GRAYED
  111. fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
  112. col.rgb = fixed3(grey, grey, grey);
  113. #endif
  114. #ifdef SOFT_CLIPPED
  115. float2 factor = float2(0,0);
  116. if(i.clipPos.x<0)
  117. factor.x = (1.0-abs(i.clipPos.x)) * _ClipSoftness.x;
  118. else
  119. factor.x = (1.0-i.clipPos.x) * _ClipSoftness.z;
  120. if(i.clipPos.y<0)
  121. factor.y = (1.0-abs(i.clipPos.y)) * _ClipSoftness.w;
  122. else
  123. factor.y = (1.0-i.clipPos.y) * _ClipSoftness.y;
  124. col.a *= clamp(min(factor.x, factor.y), 0.0, 1.0);
  125. #endif
  126. #ifdef CLIPPED
  127. float2 factor = abs(i.clipPos);
  128. col.a *= step(max(factor.x, factor.y), 1);
  129. #endif
  130. #ifdef COLOR_FILTER
  131. if (_ColorOption == 0)
  132. {
  133. fixed4 col2 = col;
  134. col2.r = dot(col, _ColorMatrix[0]) + _ColorOffset.x;
  135. col2.g = dot(col, _ColorMatrix[1]) + _ColorOffset.y;
  136. col2.b = dot(col, _ColorMatrix[2]) + _ColorOffset.z;
  137. col2.a = dot(col, _ColorMatrix[3]) + _ColorOffset.w;
  138. col = col2;
  139. }
  140. else //premultiply alpha
  141. col.rgb *= col.a;
  142. #endif
  143. #ifdef ALPHA_MASK
  144. clip(col.a - 0.001);
  145. #endif
  146. return col;
  147. }
  148. ENDCG
  149. }
  150. }
  151. }