先上效果图:
================ 效果为动态效果,后续视频文件上传成功再更新文章视频链接;=======================================
Shader代码实现:
算法代码行可自行修改参数调试,顺便说一句,改变算法可以有很多玩法;
Shader "LearnShadersFromOther/RGB_Wave"
{
Properties{
_MainTex("Mask Texture",2D) = ""{}
_GlowScale("Glow Scale", Range(0,5)) = 1
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Pass
{
ZWrite Off
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct VertexInput {
fixed4 vertex : POSITION;
fixed2 uv:TEXCOORD0;
fixed4 tangent : TANGENT;
fixed3 normal : NORMAL;
};
struct VertexOutput {
fixed4 pos : SV_POSITION;
fixed2 uv:TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed _GlowScale;
VertexOutput vert (VertexInput v)
{
VertexOutput o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag(VertexOutput i) : SV_Target
{
fixed c[3];
fixed4 col = tex2D(_MainTex, i.uv);
for(int j=0;j<3;j++)
{
float2 uv = i.uv;
float2 uvr = 2 * uv - 1;
uv -= 0.5;
_Time.y += 0.5;
fixed l=sqrt(dot(uvr,uvr));
uv += uv.yy / (l * abs((cos(_Time.y) + 2)) * cos(l * 11 - _Time.y - _Time.y));
c[j] = 0.03/length(fmod(uv,1) - 0.5);
}
fixed3 diff = fixed3(c[0], c[1], c[2]);
diff = diff*col.rgb * _GlowScale;
return fixed4(diff,1);
}
ENDCG
}
}
}
|