liuliuliu.shader 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Shader "Custom/UI/Flow"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _Color("Tint", Color) = (1,1,1,1)
  7. _FlowTex("Flow Tex", 2D) = "white" {}
  8. _FlowMask("Flow Mask", 2D) = "white" {}
  9. _FlowColor("Flow Color", Color) = (1, 1, 1, 1)
  10. _FlowSpeed("Flow Speed", Range(-1, 3)) = 1
  11. _StencilComp("Stencil Comparison", Float) = 8
  12. _Stencil("Stencil ID", Float) = 0
  13. _StencilOp("Stencil Operation", Float) = 0
  14. _StencilWriteMask("Stencil Write Mask", Float) = 255
  15. _StencilReadMask("Stencil Read Mask", Float) = 255
  16. _ColorMask("Color Mask", Float) = 15
  17. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
  18. }
  19. SubShader
  20. {
  21. Tags
  22. {
  23. "Queue" = "Transparent"
  24. "IgnoreProjector" = "True"
  25. "RenderType" = "Transparent"
  26. "PreviewType" = "Plane"
  27. "CanUseSpriteAtlas" = "True"
  28. }
  29. Stencil
  30. {
  31. Ref[_Stencil]
  32. Comp[_StencilComp]
  33. Pass[_StencilOp]
  34. ReadMask[_StencilReadMask]
  35. WriteMask[_StencilWriteMask]
  36. }
  37. Cull Off
  38. Lighting Off
  39. ZWrite Off
  40. ZTest[unity_GUIZTestMode]
  41. Blend SrcAlpha OneMinusSrcAlpha
  42. ColorMask[_ColorMask]
  43. Pass
  44. {
  45. Name "Default"
  46. CGPROGRAM
  47. #pragma vertex vert
  48. #pragma fragment frag
  49. #pragma target 2.0
  50. #include "UnityCG.cginc"
  51. #include "UnityUI.cginc"
  52. #pragma multi_compile_local _ UNITY_UI_CLIP_RECT
  53. #pragma multi_compile_local _ UNITY_UI_ALPHACLIP
  54. struct appdata_t
  55. {
  56. float4 vertex : POSITION;
  57. float4 color : COLOR;
  58. float2 texcoord : TEXCOORD0;
  59. UNITY_VERTEX_INPUT_INSTANCE_ID
  60. };
  61. struct v2f
  62. {
  63. float4 vertex : SV_POSITION;
  64. fixed4 color : COLOR;
  65. float2 texcoord : TEXCOORD0;
  66. float4 worldPosition : TEXCOORD1;
  67. UNITY_VERTEX_OUTPUT_STEREO
  68. };
  69. sampler2D _MainTex;
  70. fixed4 _Color;
  71. fixed4 _TextureSampleAdd;
  72. float4 _ClipRect;
  73. float4 _MainTex_ST;
  74. sampler2D _FlowTex;
  75. float4 _FlowTex_ST;
  76. sampler2D _FlowMask;
  77. fixed4 _FlowColor;
  78. half _FlowSpeed;
  79. v2f vert(appdata_t v)
  80. {
  81. v2f OUT;
  82. UNITY_SETUP_INSTANCE_ID(v);
  83. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  84. OUT.worldPosition = v.vertex;
  85. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  86. OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  87. OUT.color = v.color * _Color;
  88. return OUT;
  89. }
  90. fixed4 frag(v2f IN) : SV_Target
  91. {
  92. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  93. #ifdef UNITY_UI_CLIP_RECT
  94. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  95. #endif
  96. #ifdef UNITY_UI_ALPHACLIP
  97. clip(color.a - 0.001);
  98. #endif
  99. fixed2 uv = IN.texcoord.xy;
  100. uv.x -= _FlowSpeed * _Time.y;
  101. fixed4 flow = _FlowColor * tex2D(_FlowTex, uv) * tex2D(_FlowMask, IN.texcoord).r;
  102. color += flow;
  103. return color;
  104. }
  105. ENDCG
  106. }
  107. }
  108. }