Panning UV over Time causes blocky artifacts. (Float precision?)

Hello all,

Diving into Shaders with Strumpy lately and I’m trying to make a simple shader for a mobile game. The shader pans a texture over time. I used the “uvpan” example that came with Strumpy and it works ok. Except when you let the game run for 5+ minutes, after that, the texture will become blocky and panning becomes more choppy. My only conclusion was that the unity Time property was losing precisions as time passed.

So I tried to add a Modulus % operator in Strumpy to loop the time, but I couldn’t find it. I don’t think there is one, (correct me if I’m wrong)

So now there are two things I have found. I can still use Time if I subtract it with it’s floored self;
NewUV = UV_Cutoff * (Time - Floor(Time));
And this solved the blocky texture problem, but the panning still becomes choppy!

Another method I tried was writing a script to access the materials and reset the _Time property back to zero. And this method works flawlessly. But now I have a script on every game object that uses this material/shader. Is there not a better way? How does one properly use _Time in shaders for mobiles?

And links to more screenshots:
http://www.fileden.com/files/2007/1/8/613117/uvloop.jpg

http://www.fileden.com/files/2007/1/8/613117/uvloop2.jpg

http://www.fileden.com/files/2007/1/8/613117/device-2012-11-13-150346.jpg

Try the frac(x) intrinsic. Another cheap alternative would be to make a global looping time constant, and update it once per frame using Shader.SetGlobalFloat().

Flaot precision on the mobile devices is renowned for being pretty poor… You’re best off wrapping after 1.0 as often as possible :slight_smile: