How to realize the streamer effect of UGUI mask in unity
This article is about how to implement UGUI mask streamer effects in unity. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Here is the core shader:
Shader "UI/Unlit/Flowlight" {Properties {[PerRendererData] _ MainTex ("Sprite Texture", 2D) = "white" {} _ Color ("Tint", Color) = (1,1,1,1) [MaterialToggle] _ OffSet ("OffSet", float) = 0 [MaterialToggle] PixelSnap ("Pixel snap", float) = 0
/ * Flowlight * / _ FlowlightMaskTex ("Mask Texture", 2D) = "white" {} _ FlowlightTex ("Add Move Texture", 2D) = "white" {} _ FlowlightColor ("FlowlightColor", Color) = (0,0,0,1) _ Power ("Power", float) = 1 _ SpeedX ("SpeedX", float) = 1 _ SpeedY ("SpeedY", float) = 0 / *-* /
/ * UI * / _ StencilComp ("Stencil Comparison", Float) = 8 _ Stencil ("Stencil ID", Float) = 0 _ StencilOp ("Stencil Operation", Float) = 0 _ StencilWriteMask ("StencilWriteMask", Float) = 255StencilReadMask ("StencilReadMask", Float) = 255 / *-- * /}
SubShader {Tags {"Queue" = "Transparent"IgnoreProjector" = "True"RenderType" = "Transparent"PreviewType" = "Plane"CanUseSpriteAtlas" = "True"}
Cull Off Lighting Off ZWrite Off Blend One OneMinusSrcAlpha
/ * UI * / Stencil {Ref [_ Stencil] Comp [_ StencilComp] Pass [_ StencilOp] ReadMask [_ StencilReadMask] WriteMask [_ StencilWriteMask]} / *-* / Pass {CGPROGRAM#pragma vertex vert#pragma fragment frag#pragma multi_compile _ PIXELSNAP_ON#include "UnityCG.cginc"
Struct appdata_t {float4 vertex: POSITION; float4 color: COLOR; float2 texcoord: TEXCOORD0;}
Struct v2f {float4 vertex: SV_POSITION; fixed4 color: COLOR; half2 texcoord: TEXCOORD0
/ * Flowlight * / half2 texflowlight: TEXCOORD1; / *-* /
Fixed4 _ Color
/ * Flowlight * / fixed4 _ FlowlightColor; float _ Power; sampler2D _ FlowlightTex; fixed4 _ FlowlightTex_ST; sampler2D _ FlowlightMaskTex; fixed4 _ FlowlightMaskTex_ST; fixed _ SpeedX; fixed _ SpeedY; fixed x = 0; float _ OffSet; / *-* / V2f vert (appdata_t IN) {v2f OUT; OUT.vertex = mul (UNITY_MATRIX_MVP, IN.vertex); OUT.texcoord = IN.texcoord / * Flowlight * / OUT.texflowlight = TRANSFORM_TEX (IN.texcoord, _ FlowlightTex); OUT.texflowlight.x + = _ Time * _ SpeedX; OUT.texflowlight.y + = _ Time * _ SpeedY; OUT.color = IN.color * _ Color;#ifdef PIXELSNAP_ON OUT.vertex = UnityPixelSnap (OUT.vertex); # endif return OUT;}
Sampler2D _ MainTex
Fixed4 frag (V2f IN): SV_Target {fixed4 c = tex2D (_ MainTex, IN.texcoord) * IN.color; fixed4 cmask = tex2D (_ FlowlightMaskTex, IN.texcoord); if (cmask.a! = 0) {/ * Flowlight * / fixed4 cadd = tex2D (_ FlowlightTex, IN.texflowlight) * _ Power; cadd.rgb * = c.rgb; c.rgb + = cadd.rgb;} c.rgb * = c.a / *-
Return c;} ENDCG}} thank you for your reading! This is the end of this article on "how to achieve UGUI Mask streamer effects in unity". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!