Shader "ScrollTexUV"
{
// 属性
Properties
{
// 主纹理贴图 : 初始值白色
_MainTex("_MainTex", 2D) = "white" {}
// 纹理横向移动速度
_XScrollSpeed("XScrollSpeed", float) = 2
// 纹理纵向移动速度
_YScrollSpeed("YScrollSpeed", float) = 2
}
SubShader
{
Tags
{
// 渲染类型 : 不透明物体
"RenderType" = "Opaque"
}
// 层级细节 : 200
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float _XScrollSpeed;
float _YScrollSpeed;
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
fixed2 scrolledUV = IN.uv_MainTex;
// _Time为Unity Shader内部变量,代表时间,可直接使用
fixed xScrollValue = _XScrollSpeed * _Time;
fixed yScrollValue = _YScrollSpeed * _Time;
// 纹理UV随时间而移动
scrolledUV += fixed2(xScrollValue, yScrollValue);
// 使用移动的UV值进行采样,即可得滚动的纹理效果
half4 c = tex2D(_MainTex, scrolledUV);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}