|
Shader "MyShader/ImageSequenceAnimation"
|
{
|
Properties
|
{
|
_Color("Color Tint",Color) = (1,1,1,1)
|
_MainTex("Image Sequence", 2D) = "white" {}
|
_HorizontalAmount("Horizontal Amount",Float) = 8
|
_VerticalAmount("Vertical Amount",Float) = 8
|
_Speed("Speed",Range(1,150)) = 30
|
_ChangeTime("ChangeTime",Float) = 0
|
|
}
|
SubShader
|
{
|
Tags{"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
|
Pass
|
{
|
Tags{"LightMode" = "ForwardBase"}
|
|
ZWrite Off
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
CGPROGRAM
|
// 两条非常重要的编译指令
|
#pragma vertex vert// 定点着色器
|
#pragma fragment frag// 片元着色器
|
#include "Lighting.cginc"
|
|
fixed4 _Color;
|
sampler2D _MainTex;
|
float4 _MainTex_ST;
|
float _HorizontalAmount;
|
float _VerticalAmount;
|
float _Speed;
|
float _ChangeTime;
|
|
|
struct a2v
|
{
|
float4 vertex:POSITION;
|
float2 texcoord:TEXCOORD0;
|
};
|
|
struct v2f
|
{
|
float4 pos:SV_POSITION;
|
float2 uv:TEXCOORD0;
|
};
|
|
v2f vert(a2v v)
|
{
|
v2f o;
|
o.pos = UnityObjectToClipPos(v.vertex);
|
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
|
return o;
|
}
|
|
fixed4 frag(v2f i) :SV_Target
|
{
|
//_Time float4 Time (t/20, t, t*2, t*3), use to animate things inside the shaders.
|
//_SinTime float4 Sine of time: (t/8, t/4, t/2, t).
|
//_CosTime float4 Cosine of time: (t/8, t/4, t/2, t).
|
//unity_DeltaTime float4 Delta time: (dt, 1/dt, smoothDt, 1/smoothDt).
|
//_ProjectionParams float4 x is 1.0 (or –1.0 if currently rendering with a flipped projection matrix), y is the camera’s near plane, z is the camera’s far plane and w is 1/FarPlane.
|
//_ScreenParams float4 x is the current render target width in pixels, y is the current render target height in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height.
|
//这里的 t 得到的时间单位是——秒
|
|
float time = floor((_Time.y - _ChangeTime) * _Speed);//对输入参数向下取整。例如 floor(float(1.3)) 返回的值为 1.0;但是 floor(float(-1.3))返回的值为-2.0。
|
float row = floor(time / _HorizontalAmount);//行
|
float column = time - row * _HorizontalAmount;//列
|
//--
|
//half2 uv = float2(i.uv.x / _HorizontalAmount, i.uv.y / _VerticalAmount);
|
//uv.x += column / _HorizontalAmount;
|
//uv.y -= row / _VerticalAmount;
|
// --
|
|
//--
|
half2 uv = i.uv + half2(column, -row);
|
uv.x /= _HorizontalAmount;
|
uv.y /= _VerticalAmount;
|
//--
|
|
fixed4 c = tex2D(_MainTex, uv);
|
c.rgb *= _Color;
|
|
return c;
|
}
|
|
ENDCG
|
}
|
}
|
Fallback "Transparent/VertexLit"
|
}
|