Shader "_MyShader/8_Animation/1_Scroll"
{
Properties
{
_MainTex ("Base Layer (RGB)", 2D) = "white" {}
_DetailTex ("2nd Layer (RGB)", 2D) = "white" {}
_ScrollX ("Base Layer Scrool Speed", float) = 1.0
_Scroll2X ("2nd Layer Scrool Speed", float) = 1.0
_Multiplier ("Layer Multiplier", float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry"}
Pass
{
Tags { "LightMode"="ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _DetailTex;
float4 _DetailTex_ST;
float _ScrollX;
float _Scroll2X;
float _Multiplier;
struct a2v {
float4 vertex:POSITION;
float4 texcoord:TEXCOORD;
};
struct v2f {
float4 pos:SV_POSITION;
float4 uv:TEXCOORD1;
};
v2f vert(a2v v){
v2f o;
o.pos=mul(UNITY_MATRIX_MVP,v.vertex);
o.uv.xy=TRANSFORM_TEX(v.texcoord,_MainTex) + frac(float2(_ScrollX,0)*_Time.y);
o.uv.zw=TRANSFORM_TEX(v.texcoord,_DetailTex) + frac(float2(_Scroll2X,0)*_Time.y);
return o;
}
fixed4 frag(v2f i):SV_Target{
fixed4 firstLayer = tex2D(_MainTex,i.uv.xy);
fixed4 secondLayer = tex2D(_DetailTex,i.uv.zw);
fixed4 col = lerp(firstLayer,secondLayer,secondLayer.a);
col.rgb *= _Multiplier;
return col;
}
ENDCG
}
}
FallBack "VertexLit"
}
UnityShader 学习笔记 16 循环滚动的背景
最新推荐文章于 2023-12-05 16:14:35 发布