0
Follow
1
View

shader gpu animation problem in unity, how to dynamically change the animation every time from the first frame play

dn780617 注册会员
2023-02-28 20:14

Modulation based on Monster group and GPT:
You can set the animation time to a variable such as _AnimTime and then set it to 0 to reset the animation each time it plays. In your script, you can set this variable to 0 each time you need to reset the animation. Also, if the animation texture loop is incomplete, you may need to use the modulo operator to limit the timestamp to the texture range. For example, in a vertex shader, you would use the following code:


float animTime = fmod(_Time.y, _AnimTime);
float4 uv_anim = float4((v.vid + 0.5) * UNITY_ACCESS_INSTANCED_PROP(Props, _AnimTex_TexelSize).x, animTime / UNITY_ACCESS_INSTANCED_PROP(Props, _AnimTime), 0.0, 0.0);

This will make the animation start at 0 each time it is played and limit it to the texture.