// Made with Amplify Shader Editor // Available at the Unity Asset Store - http://u3d.as/y3X Shader "UI/TextureSheetAnimation" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} _Color ("Tint", Color) = (1,1,1,1) [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 [PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {} _Y_Axit("Y_Axit", Float) = 4 _X_Axit("X_Axit", Float) = 4 _speed("speed", Range( 0 , 1)) = 1 //MASK SUPPORT ADD _StencilComp("Stencil Comparison", Float) = 8 _Stencil("Stencil ID", Float) = 0 _StencilOp("Stencil Operation", Float) = 0 _StencilWriteMask("Stencil Write Mask", Float) = 255 _StencilReadMask("Stencil Read Mask", Float) = 255 _ColorMask("Color Mask", Float) = 15 //MASK SUPPORT END } SubShader { LOD 0 Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } Cull Off Lighting Off ZWrite Off Blend One OneMinusSrcAlpha //MASK SUPPORT ADD Stencil { Ref[_Stencil] Comp[_StencilComp] Pass[_StencilOp] ReadMask[_StencilReadMask] WriteMask[_StencilWriteMask] } ColorMask[_ColorMask] //MASK SUPPORT END Pass { CGPROGRAM #ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX #define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) #endif #pragma vertex vert #pragma fragment frag #pragma target 3.0 #pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ ETC1_EXTERNAL_ALPHA #include "UnityCG.cginc" #include "UnityShaderVariables.cginc" #define ASE_NEEDS_FRAG_COLOR struct appdata_t { float4 vertex : POSITION; float4 color : COLOR; float2 texcoord : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float4 vertex : SV_POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_OUTPUT_STEREO }; uniform fixed4 _Color; uniform float _EnableExternalAlpha; uniform sampler2D _MainTex; uniform sampler2D _AlphaTex; uniform float _X_Axit; uniform float _Y_Axit; uniform float _speed; v2f vert( appdata_t IN ) { v2f OUT; UNITY_SETUP_INSTANCE_ID(IN); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); UNITY_TRANSFER_INSTANCE_ID(IN, OUT); IN.vertex.xyz += float3(0,0,0) ; OUT.vertex = UnityObjectToClipPos(IN.vertex); OUT.texcoord = IN.texcoord; OUT.color = IN.color * _Color; #ifdef PIXELSNAP_ON OUT.vertex = UnityPixelSnap (OUT.vertex); #endif return OUT; } fixed4 SampleSpriteTexture (float2 uv) { fixed4 color = tex2D (_MainTex, uv); #if ETC1_EXTERNAL_ALPHA // get the color from an external texture (usecase: Alpha support for ETC1 on android) fixed4 alpha = tex2D (_AlphaTex, uv); color.a = lerp (color.a, alpha.r, _EnableExternalAlpha); #endif //ETC1_EXTERNAL_ALPHA return color; } fixed4 frag(v2f IN ) : SV_Target { UNITY_SETUP_INSTANCE_ID( IN ); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN ); float2 texCoord58 = IN.texcoord.xy * float2( 1,1 ) + float2( 0,0 ); // *** BEGIN Flipbook UV Animation vars *** // Total tiles of Flipbook Texture float fbtotaltiles59 = _X_Axit * _Y_Axit; // Offsets for cols and rows of Flipbook Texture float fbcolsoffset59 = 1.0f / _X_Axit; float fbrowsoffset59 = 1.0f / _Y_Axit; // Speed of animation float fbspeed59 = _Time.y * (0.0 + (_speed - 0.0) * (15.0 - 0.0) / (1.0 - 0.0)); // UV Tiling (col and row offset) float2 fbtiling59 = float2(fbcolsoffset59, fbrowsoffset59); // UV Offset - calculate current tile linear index, and convert it to (X * coloffset, Y * rowoffset) // Calculate current tile linear index float fbcurrenttileindex59 = round( fmod( fbspeed59 + 0.0, fbtotaltiles59) ); fbcurrenttileindex59 += ( fbcurrenttileindex59 < 0) ? fbtotaltiles59 : 0; // Obtain Offset X coordinate from current tile linear index float fblinearindextox59 = round ( fmod ( fbcurrenttileindex59, _X_Axit ) ); // Multiply Offset X by coloffset float fboffsetx59 = fblinearindextox59 * fbcolsoffset59; // Obtain Offset Y coordinate from current tile linear index float fblinearindextoy59 = round( fmod( ( fbcurrenttileindex59 - fblinearindextox59 ) / _X_Axit, _Y_Axit ) ); // Reverse Y to get tiles from Top to Bottom fblinearindextoy59 = (int)(_Y_Axit-1) - fblinearindextoy59; // Multiply Offset Y by rowoffset float fboffsety59 = fblinearindextoy59 * fbrowsoffset59; // UV Offset float2 fboffset59 = float2(fboffsetx59, fboffsety59); // Flipbook UV half2 fbuv59 = texCoord58 * fbtiling59 + fboffset59; // *** END Flipbook UV Animation vars *** fixed4 c = ( tex2D( _MainTex, fbuv59 ) * IN.color ); c.rgb *= c.a; return c; } ENDCG } } CustomEditor "ASEMaterialInspector" } /*ASEBEGIN Version=18935 1936;204;1920;768;2960.819;198.7246;1;True;True Node;AmplifyShaderEditor.RangedFloatNode;62;-2600.127,280.5405;Inherit;False;Property;_speed;speed;2;0;Create;True;0;0;0;False;0;False;1;0;0;1;0;1;FLOAT;0 Node;AmplifyShaderEditor.TextureCoordinatesNode;58;-2337.554,-220.2126;Inherit;False;0;-1;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 Node;AmplifyShaderEditor.RangedFloatNode;60;-2256.127,23.54047;Inherit;False;Property;_X_Axit;X_Axit;1;0;Create;True;0;0;0;False;0;False;4;0;0;0;0;1;FLOAT;0 Node;AmplifyShaderEditor.RangedFloatNode;61;-2259.127,112.5405;Inherit;False;Property;_Y_Axit;Y_Axit;0;0;Create;True;0;0;0;False;0;False;4;0;0;0;0;1;FLOAT;0 Node;AmplifyShaderEditor.SimpleTimeNode;63;-2223.819,424.2754;Inherit;False;1;0;FLOAT;1;False;1;FLOAT;0 Node;AmplifyShaderEditor.TFHCRemapNode;64;-2207.819,229.2754;Inherit;False;5;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;3;FLOAT;0;False;4;FLOAT;15;False;1;FLOAT;0 Node;AmplifyShaderEditor.TemplateShaderPropertyNode;33;-1443.74,-239.7812;Inherit;False;0;0;_MainTex;Shader;True;0;5;SAMPLER2D;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 Node;AmplifyShaderEditor.TFHCFlipBookUVAnimation;59;-1834.303,71.37;Inherit;False;0;0;6;0;FLOAT2;0,0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;3;FLOAT2;0;FLOAT;1;FLOAT;2 Node;AmplifyShaderEditor.SamplerNode;35;-1146.778,-206.5093;Inherit;True;Property;_TextureSample0;Texture Sample 0;4;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 Node;AmplifyShaderEditor.VertexColorNode;38;-584.6258,306.0738;Inherit;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 Node;AmplifyShaderEditor.SimpleMultiplyOpNode;37;-359.4252,-54.56424;Inherit;True;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0 Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;53;34.70004,12.27794;Float;False;True;-1;2;ASEMaterialInspector;0;6;UI/TextureSheetAnimation;0f8ba0101102bb14ebf021ddadce9b49;True;SubShader 0 Pass 0;0;0;SubShader 0 Pass 0;2;False;True;3;1;False;-1;10;False;-1;0;1;False;-1;0;False;-1;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;-1;False;False;False;False;False;False;False;False;False;False;False;True;2;False;-1;False;False;True;5;Queue=Transparent=Queue=0;IgnoreProjector=True;RenderType=Transparent=RenderType;PreviewType=Plane;CanUseSpriteAtlas=True;False;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;0;;0;0;Standard;0;0;1;True;False;;False;0 WireConnection;64;0;62;0 WireConnection;59;0;58;0 WireConnection;59;1;60;0 WireConnection;59;2;61;0 WireConnection;59;3;64;0 WireConnection;59;5;63;0 WireConnection;35;0;33;0 WireConnection;35;1;59;0 WireConnection;37;0;35;0 WireConnection;37;1;38;0 WireConnection;53;0;37;0 ASEEND*/ //CHKSM=328BB2D755BD6FF7485145BBB12179BEC6859860