Search Unity

Need help with _Time for a loop > 1 sec

Discussion in 'Shaders' started by julienc, Nov 5, 2017.

  1. julienc

    julienc

    Joined:
    Nov 26, 2012
    Posts:
    5
    Hi all,
    in my shader i need to loop over certains points (think animation of vertex). I am currently using fmod(_Time.x, 1) to loop a 0.00 to 1.0 value from 0 to 1 second. This works perfectly fine.

    However, I now need to expand on this to go from 1 seconds to at least 2 seconds and fmod is no longer relevant.

    Browsing from tons of forum posts I do not find much information about _Time. Probably there is some hack with sin(_Time) that I cannot find by myself.

    Would someone have an idea? thanks
     
  2. Atair

    Atair

    Joined:
    Oct 16, 2015
    Posts:
    42
    fmod(_Time.x, 2) * 0.5 unless i didn't understand your problem
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    FYI the code fmod(_Time.x, 1.0) will loop between 0.0 and 0.999... over 20 seconds.

    _Time.x = time / 20
    https://docs.unity3d.com/455/Documentation/Manual/SL-BuiltinValues.html

    Unmodified time is in _Time.y. You may also want to use frac(value) instead of fmod(value, 1).

    So to go from 0.0 to 0.999... over some value of seconds the simplest code is:

    frac(_Time.y / seconds)