播放序列帧 shader

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"

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值