Script vs Shader for animated texture

Quick question…I need to make an animated texture, and I was thinking of using a sprite-sheet and moving the UVs with code, with something like Animating Tiled Texture UVs.

But I was wondering what would be the best way to achieve this, by script like the above, or creating a special shader that basically does the same thing? And what about performance between both methods?

Thanks for any help, and for your time!
Stephane

Wouldn’t using a script on multiple instances of the same material create an extra draw call for each instance?

In my point, put uv calculation into the GPU(shader) side may not be a good idea especially when your target platform is mobile or some devices with poor graphic processor.

What’s more, calculate uv offset by using “modf(GameTime / Cycle)” can easily cause precision problem when the game need to be played for a long time or “Cycle” is too small. I myself have encountered this problem many many times. But if you made your calculation on the C# side, this gonna be a very very easy problem(just make a private sum time value instead of a global one, and reset it after every “Cycle”).

I used to only put animate logic in shader when it happends on ParticleSystem. Because the particle system of my previous graphics engine only provide normalized particle age for each particle vertex. The only and efficient way for me is calculate them in shader.

Keep in mind “switch texture” will cost extra performance. If you have a lot of instanced materials using different texture in one frame, then DO NOT USE Material.SetTexture().

But sprite-sheet have a big disadvantage, all frames of the animation must load at the same time and you can not unload those “Out of sight frame” (because they are stored in one texture). This means a big waste of memory some time.

If you are trying to display a non-loop, long and high resolution animated frames, go for the Material.SetTexture(). Also don’t forget use Resources.Unload() to handle the memory issue. Or just simply use VideoTexture(not available on iOS, but u can buy one plugin developed by PRIME31).

Hi, Stephane:
I know it has been a long time, but I still want know which one did you use to make the animated and tiled texture, Shader or Script? I already know how to do that with scripts, but I’m dying to know how to make it work also in a Shader. I tried, but it didn’t work out well. So I wonder if you know anything, plz let me know :D.
Happy new year!
Young.

Hi, Stephane:
I know it has been a long time since the last reply, but I still want know which one did you use to make the animated and tiled texture, Shader or Script? I already know how to do that with scripts, but I’m dying to know how to make it work also in a Shader. I tried, but it didn’t work out well. So I wonder if you know anything, plz let me know :D.
Happy new year!
Young.

http://docs.unity3d.com/Documentation/Manual/VideoFiles.html