Search Unity

Floating point issue with frac(_Time) on mobile devices

Discussion in 'Shaders' started by namjag, Jun 4, 2013.

  1. namjag

    namjag

    Joined:
    May 12, 2013
    Posts:
    5
    Greetings Community
    I am working on shaders for mobile devices that use _Time.
    In the first minutes testing the shaders on mobile they behave like intended but after some time shaders that use for example frac are going to lag and some of them are going to get more and more pixelated.
    After a some test I found out that frac has troubles with higher numbers.

    I made a demonstration scene that shows that behavior.

    On Pc you can’t see any difference. But on Android devices (haven’t tested it on IO’s devices yet) you are able to see that the upper plane that simply visualizes an frac(_Time[1]) works fine for a couple of minutes but the lower one that visualizes the same thing with an hour time offset
    ( frac(_Time[1]+3600) ) runs very chunky and slow. On some devices the second plane stays black. I think that happens because the frac function seems to loose precision when the number gets bigger and therefore skips lower decimal places.

    I tested that on 4 Different Devices:
    Nexus 7
    Galaxy Note 2
    Galaxy S II
    Galaxy Tab 10.1

    The scene with the shaders is attached to this post.

    So my questions are:
    Is that a bug?
    Do I have to skirt the issue with a script that controls the shader or is there a better way to manage these problems?

    thx
     

    Attached Files:

  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
  3. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I did. The rectangle is uniform on my iPhone 4S until an offset of 2^16 (over 45 days). On my 2010 MacBook Pro, it's 2^19.

    Move the fract to the vertex shader to support the undesirables.
     
  4. namjag

    namjag

    Joined:
    May 12, 2013
    Posts:
    5
    I am using an global variable now, witch perfectly does what i need!
    thx a lot