MFUGUI_TextGray.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Shader "MFUGUI/TextGray"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _Color("Main Color", Color) = (1,1,1,1)
  7. _Gray("Gray", Float) = 0
  8. _DetailTex("Detail (RGB)", 2D) = "white" {}
  9. _Strength("Detail Strength", Range(0.0, 1.0)) = 0.2
  10. _StencilComp("Stencil Comparison", Float) = 8
  11. _Stencil("Stencil ID", Float) = 0
  12. _StencilOp("Stencil Operation", Float) = 0
  13. _StencilWriteMask("Stencil Write Mask", Float) = 255
  14. _StencilReadMask("Stencil Read Mask", Float) = 255
  15. _ColorMask("Color Mask", Float) = 15
  16. }
  17. SubShader
  18. {
  19. LOD 100
  20. Tags
  21. {
  22. "Queue" = "Transparent"
  23. "IgnoreProjector" = "True"
  24. "RenderType" = "Transparent"
  25. "PreviewType" = "Plane"
  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. ZTest[unity_GUIZTestMode]
  39. Blend SrcAlpha OneMinusSrcAlpha
  40. ColorMask[_ColorMask]
  41. Pass
  42. {
  43. CGPROGRAM
  44. #pragma vertex vert
  45. #pragma fragment frag
  46. #include "UnityCG.cginc"
  47. #include "UnityUI.cginc"
  48. struct appdata_t
  49. {
  50. float4 vertex : POSITION;
  51. float2 texcoord : TEXCOORD0;
  52. float2 texcoord2 : TEXCOORD1;
  53. fixed4 color : COLOR;
  54. };
  55. struct v2f
  56. {
  57. float4 vertex : SV_POSITION;
  58. float2 texcoord : TEXCOORD0;
  59. float2 texcoord2 : TEXCOORD1;
  60. float4 worldPosition : TEXCOORD2;
  61. fixed4 color : COLOR;
  62. };
  63. sampler2D _MainTex;
  64. sampler2D _DetailTex;
  65. float4 _MainTex_ST;
  66. float4 _DetailTex_ST;
  67. float4 _DetailTex_TexelSize;
  68. fixed4 _Color;
  69. fixed _Strength;
  70. fixed4 _TextureSampleAdd;
  71. float _Gray;
  72. bool _UseClipRect;
  73. float4 _ClipRect;
  74. bool _UseAlphaClip;
  75. v2f vert(appdata_t v)
  76. {
  77. v2f o;
  78. o.worldPosition = v.vertex;
  79. o.vertex = mul(UNITY_MATRIX_MVP, o.worldPosition);
  80. o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  81. o.texcoord2 = TRANSFORM_TEX(v.texcoord2 * _DetailTex_TexelSize.xy, _DetailTex);
  82. o.color = v.color * _Color;
  83. #ifdef UNITY_HALF_TEXEL_OFFSET
  84. o.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1,1);
  85. #endif
  86. return o;
  87. }
  88. fixed4 frag(v2f i) : COLOR
  89. {
  90. fixed4 color = (tex2D(_MainTex, i.texcoord) + _TextureSampleAdd) * i.color;
  91. fixed4 detail = tex2D(_DetailTex, i.texcoord2);
  92. color.rgb = lerp(color.rgb, color.rgb * detail.rgb, detail.a * _Strength);
  93. color = color * _Color;
  94. if (_Gray != 0) {
  95. float grey = dot(color.rgb, float3(0.299, 0.587, 0.114));
  96. color.rgb = float3(grey, grey, grey);
  97. }
  98. if (_UseClipRect)
  99. color *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
  100. if (_UseAlphaClip)
  101. clip(color.a - 0.001);
  102. return color;
  103. }
  104. ENDCG
  105. }
  106. }
  107. }