图片交叉移动
发布时间 :
字数:272
阅读 :
Shader "UIEffect/UV Cross"
{
Properties
{
[PerRendererData] _MainTex ("Texture", 2D) = "white" {}
_Vector("Count And Move",Vector)=(1,1,1,1)
_xOffset("xOffset",float)=10
//_yOffset("_yOffset",float)=10
_Rotate("Rotate",float)=10
_Scale("Scale",float)=1
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
Tags {"Queue"="Transparent"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color:COLOR;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 color:COLOR;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.color=v.color;
return o;
}
sampler2D _MainTex;
float4 _Vector;
float _xOffset;
//float _yOffset;
float _Rotate;
float _Scale;
fixed4 frag (v2f i) : SV_Target
{
float2 count=_Vector.xy;
i.uv=i.uv-0.5;
float2 uv=i.uv*count* ((sin(_Time.x*_Scale)+1)/2+1);
float2 finalUV = uv;
float angle=_Rotate*_Time.x;
finalUV.x = uv.x * cos(angle) - uv.y * sin(angle);
finalUV.y = uv.x * sin(angle) + uv.y * cos(angle);
finalUV += float2(0.5f, 0.5f);
uv=finalUV;
uv.y+=_Time.x*_Vector.w;
uv.x+=_Time.x*_Vector.z*(((floor(uv.y)%2)-0.5)*2);
uv.x+=(floor(uv.y)%2)*_xOffset;
//uv.y+=(floor(uv.x)%2)*_yOffset;
fixed4 col = tex2D(_MainTex, uv);
//return fixed4(1,1,1,1);
return col*i.color;
}
ENDCG
}
}
}