Shader "Custom/FlowMapShader"
{
Properties
{
_MainTex ("MainTex", 2D) = "white" {}
_FlowSpeed("_FlowSpeed",Float) = 1
_FlowMap("_FlowMap",2D) = "white"{}
}
SubShader
{
Pass
{
Tags{"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float _FlowSpeed;
sampler2D _FlowMap;
struct a2v
{
fixed4 vertex : POSITION;
fixed2 texcoord : TEXCOORD0;
};
struct v2f
{
fixed4 pos: SV_POSITION;
fixed2 uv : TEXCOORD0;
};
v2f vert(a2v v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float3 flowDir = tex2D(_FlowMap,i.uv) * 2 - 1;
flowDir *= _FlowSpeed;
float phase0 = frac(_Time);
float phase1 = frac(_Time + 0.5);
float3 tex0 = tex2D(_MainTex,i.uv - flowDir.xy * phase0);
float3 tex1 = tex2D(_MainTex,i.uv - flowDir.xy * phase1);
float flowLerp = abs((0.5 - phase0)/0.5);
fixed3 finalColor = lerp(tex0,tex1,flowLerp);
return fixed4(finalColor,1);
}
ENDCG
}
}
FallBack "Specular"
}