@DMGregory Answer is correct but you mentioned that didn't reailze his answer,I just explain more here:
for counting shader animation iterations you should use periodic function.
if you want understand you can see below functions on GraphToy.
sin(clamp(x,0,(2*PI)))
sin(clamp(x,0,(2*PI)*2))
sin(clamp(x,0,(2*PI)*3))
this is simple example:
#define PI 3.14159265359
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
float Iterate = 2.0;
float Periodic = sin(clamp(iTime,0.,(2.0*PI)*Iterate));
fragColor = vec4(1.0) * Periodic;
}
so you can iterate your shader animation easily:
#define PI 3.14159265359
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
float Iterate = 2.0;
float Periodic = sin(clamp(iTime,0.0,(2.0*PI)*Iterate));
vec2 center = vec2( .5 );
vec2 dir = normalize( center - uv );
float d = length( center - uv );
float factor = .5 * Periodic;
float f = exp( factor * ( d - .5 ) ) - 1.;
if( d > .5 ) f = 0.;
fragColor = texture( iChannel0, uv + f * dir );
}
this is unity version of your shader that converted by shadertoy to unity tool.
Shader"ShaderMan/Periodic"{
Properties{
_MainTex("_MainTex", 2D) = "white"{}
_Iterate("Iterate",Float) = 2
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
#define PI 3.14159265359
float _Iterate;
fixed4 frag(v2f i) : SV_Target{
{
float Periodic = sin(clamp(_Time.y,0.0,(2.0*PI)*_Iterate));
fixed2 uv = i.uv;
fixed2 center = fixed2( .5 , .5 );
fixed2 dir = normalize( center - uv );
fixed d = length( center - uv );
fixed factor = .5 * Periodic;
fixed f = exp( factor * ( d - .5 ) ) - 1.;
if( d > .5 ) f = 0.;
return tex2D( _MainTex, uv + f * dir );
}
}ENDCG
}
}
}