UGUI遮罩流光Shader
最近在做UGUI的特效,一个常见的效果就是UI上的流光(土豪金闪闪)。常见的做法混合一个遮罩贴图,控制UV移动。但是最近有个想法是在UI的
最近在做UGUI的特效,一个常见的效果就是UI上的流光(土豪金闪闪)。
常见的做法混合一个遮罩贴图,控制UV移动。但是最近有个想法是在UI的部分纹理上流动,比如金属边什么的,于是就要再引入一个对应可以流动部分的纹理组合起来。
此工程的unitypackage下载地址:http://pan.baidu.com/s/1pLRhmBp
下面是核心shader:
Shader "UI/Unlit/Flowlight"n{ntPropertiesnt{ntt[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}ntt_Color("Tint", Color) = (1, 1, 1, 1)ntt[MaterialToggle] _OffSet("OffSet", float) = 0ntt[MaterialToggle] PixelSnap("Pixel snap", float) = 0nntt/* Flowlight */ntt_FlowlightMaskTex("Mask Texture", 2D) = "white" {}ntt_FlowlightTex("Add Move Texture", 2D) = "white" {}ntt_FlowlightColor("Flowlight Color", Color) = (0, 0, 0, 1)ntt_Power("Power", float) = 1ntt_SpeedX("SpeedX", float) = 1ntt_SpeedY("SpeedY", float) = 0ntt/* --------- */nntt/* UI */ntt_StencilComp("Stencil Comparison", Float) = 8ntt_Stencil("Stencil ID", Float) = 0ntt_StencilOp("Stencil Operation", Float) = 0ntt_StencilWriteMask("Stencil Write Mask", Float) = 255ntt_StencilReadMask("Stencil Read Mask", Float) = 255ntt/* -- */nt}nntSubShadernt{nttTagsntt{nttt"Queue" = "Transparent"nttt"IgnoreProjector" = "True"nttt"RenderType" = "Transparent"nttt"PreviewType" = "Plane"nttt"CanUseSpriteAtlas" = "True"ntt}nnttCull OffnttLighting OffnttZWrite OffnttBlend One OneMinusSrcAlphanntt/* UI */nttStencilntt{ntttRef[_Stencil]ntttComp[_StencilComp]ntttPass[_StencilOp]ntttReadMask[_StencilReadMask]ntttWriteMask[_StencilWriteMask]ntt}ntt/* -- */ntPassnt{nttCGPROGRAMn#pragma vertex vertn#pragma fragment fragn#pragma multi_compile _ PIXELSNAP_ONn#include "UnityCG.cginc"nntstruct appdata_tnt{nttfloat4 vertex : POSITION;nttfloat4 color : COLOR;nttfloat2 texcoord : TEXCOORD0;nt};nntstruct v2fnt{nttfloat4 vertex : SV_POSITION;nttfixed4 color : COLOR;ntthalf2 texcoord : TEXCOORD0;nntt/* Flowlight */ntthalf2 texflowlight : TEXCOORD1;ntt/* --------- */nt};nntfixed4 _Color;nnt/* Flowlight */ntfixed4 _FlowlightColor;ntfloat _Power;ntsampler2D _FlowlightTex;ntfixed4 _FlowlightTex_ST;ntsampler2D _FlowlightMaskTex;ntfixed4 _FlowlightMaskTex_ST;ntfixed _SpeedX;ntfixed _SpeedY;ntfixed x = 0;ntfloat _OffSet;nt/* --------- */ntv2f vert(appdata_t IN)nt{nttv2f OUT;nttOUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);nttOUT.texcoord = IN.texcoord;ntt/* Flowlight */nttOUT.texflowlight = TRANSFORM_TEX(IN.texcoord, _FlowlightTex);nttOUT.texflowlight.x += _Time * _SpeedX;nttOUT.texflowlight.y += _Time * _SpeedY;nttOUT.color = IN.color * _Color;n#ifdef PIXELSNAP_ONnttOUT.vertex = UnityPixelSnap(OUT.vertex);n#endifnttreturn OUT;nt}nntsampler2D _MainTex;nntfixed4 frag(v2f IN) : SV_Targetnt{nttfixed4 c = tex2D(_MainTex, IN.texcoord)*IN.color;nttfixed4 cmask = tex2D(_FlowlightMaskTex, IN.texcoord);ntif (cmask.a != 0)nt{ntt/* Flowlight */nttfixed4 cadd = tex2D(_FlowlightTex, IN.texflowlight) * _Power;nttcadd.rgb *= c.rgb;nttc.rgb += cadd.rgb;nt}ntc.rgb *= c.a;nt/* --------- */nntreturn c;nt}nttENDCGnt}nt}n}n
上一篇:荷乙 奥斯VS布雷达
下一篇:电加热蒸汽发生器工作原理