锅炉信息网 > 锅炉知识 > 锅炉百科

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

精选推荐

  • 711关东煮供应商
    711关东煮供应商

    今天给大家介绍三位,奶粉,全家、罗森这些便利店里关东煮的供应商。店里卖三四块钱一串的关东煮,在网上买不到,一块钱就搞定。首先关东

  • 健康日历|高压锅容易爆炸的4个原因
    健康日历|高压锅容易爆炸的4个原因

    来源:医药养生保健报设计:李雅琴医学审核:姜峰出品人:胡丽丽

  • 高炉
    高炉

    今天这活却是个白事,等到了时辰,那家人便准备火化,本来准备送普炉,我却心中一动,便对那家人说道:“这老人走也不要省,还是送高炉吧。”

  • 高压锅和电压力锅的区别,推荐几款点压力锅
    高压锅和电压力锅的区别,推荐几款点压

    记得之前有一次去朋友家玩,他正在用高压锅煮小米粥,是的,高压锅压小米粥,大概煮了半小时,高压锅突然爆炸了,现场惨不忍睹啊,幸好厨房里没

0