Frame animation sequences belonging to one of the texture shader animation, the main principle is given texture aliquoted, and then change a portion of a loop in the equivalent time.
name | Types of | description |
_Time | float4 | (T / 20, t, 2t, 3t) where t is elapsed from the time of loading the scene |
_SinTime | float4 | (T / 8, t / 4, t / 2, t) where t is elapsed from the time of loading scenario sine |
_CosTime | float4 | (T / 8, t / 4, t / 2, t) where t is the cosine of the self-load elapsed time of the scene |
unity_DeltaTime | float4 | (Dt, 1 / dt, sdt, 1 / sdt) where dt is the time increment, sdt smoothed value for the time increment |
Script is as follows:
1 Shader "MyUnlit/FrameAnimation" 2 { 3 Properties 4 { 5 _Color("Color Tint",color)=(1,1,1,1) 6 _MainTex ("Texture", 2D) = "white" {} 7 _CutX("CutX Amount",float)=4 8 _CutY("CutY Amount" , A float ) = . 4 . 9 _SPEED ( " Speed " , Range ( . 1 , 100 )) = 30 10 } . 11 SubShader 12 is { 13 is // general frame of the animation sequences with the texture Alpha channel, thus rendering Yaoan transparency, tag needs to be set close deep write, and set using mixed 14 tags { " RenderType " = " transparent " " Queue " = " transparent " " ignoreprojector " = "true" } 15 ZWrite off 16 blend srcalpha oneminussrcalpha 17 18 Pass 19 { 20 Tags{"lightmode"="forwardbase"} 21 22 CGPROGRAM 23 #pragma vertex vert 24 #pragma fragment frag 25 #pragma multi_compile_fog 26 27 #include "UnityCG.cginc" 28 29 struct appdata 30 { 31 float4 vertex : POSITION; 32 float2 uv : TEXCOORD0; 33 }; 34 35 struct v2f 36 { 37 float2 uv : TEXCOORD0; 38 UNITY_FOG_COORDS(1) 39 float4 vertex : SV_POSITION; 40 }; 41 42 sampler2D _MainTex; 43 float4 _MainTex_ST; 44 fixed4 _Color; 45 float _CutX; 46 float _CutY; 47 float _Speed; 48 49 v2f vert (appdata v) 50 { 51 v2f o; 52 o.vertex = UnityObjectToClipPos(v.vertex); 53 o.uv = TRANSFORM_TEX(v.uv, _MainTex); 54 UNITY_TRANSFER_FOG(o,o.vertex); 55 return o; 56 } 57 58 fixed4 frag (v2f i) : SV_Target 59 { 60 //取得整数的时间 61 float= Floor Time (_Time.y * _SPEED); 62 is // aliquot parts row (from left to right because the playback sequence, the first column) 63 is a float Row = Floor (Time / _CutX); 64 // remainder portion of column 65 a float column = Time - * row _CutX; 66 67 // offset value is calculated, where u is a column index to a value, v is the opposite of the row index (the origin is the top left corner displays, and uv sample origin is the lower left corner, it should be negated so that the offset v) 68 half2 UV + = i.uv half2 (column, - Row); 69 // divided by the sample value to obtain the final row 70 uv.x / = _CutX; 71 is uv.y / = _CutY; 72 73 is fixed4 COL = tex2D(_MainTex,uv); 74 col.rgb *= _Color; 75 UNITY_APPLY_FOG(i.fogCoord, col); 76 return col; 77 } 78 ENDCG 79 } 80 } 81 FallBack "Transparent/VertexLit" 82 }