Shader播放序列帧
<1>代码
Shader "Tang/622/FrameAnim"{ Properties{ _MainTex("序列帧",2D) = "white" { } _Row("行",Float) = 8 _Col("列",Float) = 8 _Speed("速度",Float) = 80 } SubShader{ Tags {"Queue" = "Transparent" "RenderType" = "Transparent"} Pass{ Tags { "LightMode" = "ForwardBase" } ZWrite off cull off Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct a2v{ float4 vertex:POSITION; float4 texcoord:TEXCOORD0; }; struct v2f{ float4 pos:SV_POSITION; float2 uv:TEXCOORD0; }; sampler2D _MainTex;float4 _MainTex_ST; float _Row; float _Col; float _Speed; 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{ float time = floor(_Time.y*_Speed); //求行 float row = floor(time/_Col); //求列 float column = time - row*_Row; half2 uv = i.uv +half2(column,-row); //列 uv.x/=_Col; //行 row/_Row = 起始行uv i.uv.y/_Row = i.uv.y缩放 相加 = 当前uv.y uv.y/=_Row; return tex2D(_MainTex,uv); } ENDCG } } FallBack "Diffuse" }