Shader “LordShader/AnimShader”
{
Properties
{
_MainTex(“Base (RGB)”, 2D) = “white” {}
_Rows(“Row Nums”,float) = 1
_Cols(“Column Nums”,float) = 1
_Speed(“Speed”, Range(0.01, 32)) = 12
_Size("_Size", Range(0.01, 32)) = 1
_PosX("_PosX",float) = 1
_PosY("_PosY",float) = 1
}
SubShader
{
Tags { "Queue" = "Transparent" }
CGPROGRAM
#pragma surface surf Lambert2 alpha
inline fixed4 LightingLambert2(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed diff = max(0, dot(s.Normal, lightDir));
fixed4 c;
c.rgb = s.Albedo;// * _LightColor0.rgb * (diff * atten * 2);
c.a = s.Alpha;
return c;
}
sampler2D _MainTex;
float _Rows;
float _Cols;
float _Speed;
float _Scale;
float2 _Pos;
float _Size;
float _PosX;
float _PosY;
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN,inout SurfaceOutput o)
{
//一共有多少个单元
float cellCount = _Rows * _Cols;
float CurrentIndex = fmod(_Time.y * _Speed,cellCount);
CurrentIndex = floor(CurrentIndex);
float curRowIndex = CurrentIndex / _Cols;
curRowIndex = floor(curRowIndex) + 1;//抛掉0
curRowIndex = _Rows - curRowIndex;//从上往下遍历
float curColIndex = fmod(CurrentIndex,_Cols);
float2 spriteUV = IN.uv_MainTex;
_Pos = float2(_PosX, _PosY);
_Pos += float2(150, 150);
_Pos *= 0.00333;
float _Size_N = _Size * 0.00333;
if (abs(spriteUV.x - _Pos.x) < _Size_N && abs(spriteUV.y - _Pos.y) < _Size_N)
{
//float xValue = spriteUV.x;
//float yValue = spriteUV.y;
float xValue = (spriteUV.x - _Pos.x + _Size_N) * 300 / (2 * _Size);
float yValue = (spriteUV.y - _Pos.y + _Size_N) * 300 / (2 * _Size);
xValue = (xValue + curColIndex) / _Cols;
yValue = (yValue + curRowIndex) / _Rows;
spriteUV = float2(xValue, yValue);
half4 c = tex2D(_MainTex, spriteUV);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
}
ENDCG
}
FallBack "Diffuse"
}