当前位置:网站首页>Shader_ Animation sequence frame

Shader_ Animation sequence frame

2022-07-07 15:52:00 Le_ Sam

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Zombie/ZombieAnimation"
{
	Properties
	{
		_MainTex("Base(RGB)" ,2D) = ""{}
		_Row("Row",Int) = 1
		_Column("Column",Int) = 1
		_Speed("Speed",Range(0,60)) = 30
	}

		SubShader
		{
			tags{"Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "PreviewType" = "Plane" }
			Blend SrcAlpha OneMinusSrcAlpha
			ColorMask RGB
			ZWrite Off
			Cull Off
			Pass
			{
				CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				#include "UnityCG.cginc"

				struct v2f
				{
					float4 pos:POSITION;
					float2 uv:TEXCOORD0;
				};

				sampler2D _MainTex;
				float4 _MainTex_ST;

				int _Row;
				int _Column;
				float _Speed;

				v2f vert(appdata_base v)
				{
					v2f o;
					o.pos = UnityObjectToClipPos(v.vertex);
					o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
					return o;
				}

				half4 frag(v2f IN) :COLOR
				{
					float2 uv = IN.uv;

					float cellX = uv.x / _Column;
					float cellY = uv.y / _Row;

					//Sprite total 
					int count = _Row * _Column;

					// stay 0 To count-1  Cycle in range 
					int SpriteIndex = fmod(_Time.w*_Speed,count);

					// At present Sprite Subscript of the line 
					int SpriteRowIndx = (SpriteIndex / _Column);

					// At present Sprite Subscript of the column 
					int SpriteColumnIndex = fmod(SpriteIndex,_Column);

					// because uv The lower left corner of the coordinate is (0,0), The first line is the bottom line , In order to conform to our common sense , We switch to the first line of the top line ,eg:0,1,2-->2,1,0
					SpriteRowIndx = (_Row - 1) - fmod(SpriteRowIndx,_Row);

					// multiply 1.0 Convert to floating point number 
					uv.x = cellX + SpriteColumnIndex * 1.0 / _Column;
					uv.y = cellY + SpriteRowIndx * 1.0 / _Row;

					half4 c = tex2D(_MainTex,uv);
					return c;
				}
				ENDCG
			}
		}
			FallBack "Diffuse"
}

 

原网站

版权声明
本文为[Le_ Sam]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130609270916.html