- Home /
GLSL: Get current time in millis
Hello, is there any way that in fragment or vertex shader we can get the current time? I wanted to use it as a random seed and also as a incremental variable to animate shaders in a simple way.
Is it possible? If not, is there any way to get random and sequentially incrementated vars?
Thnaks!
Have you tried _Time?
http://docs.unity3d.com/Documentation/Components/SL-BuiltinValues.html
Answer by aldonaletto · Nov 22, 2012 at 02:44 AM
Unity gently gives us the vec4 variable _Time at shader level: _Time.y is the current time, while _Time.x = time/20, _Time.z = time 2 and _Time.w = time 3.
Additionally, you can pass values from scripts to the shaders with SetFloat:
function Start(){
renderer.material.SetFloat("_Seed", Time.time);
}
From what I've read about GLSL shaders, you have only to declare the uniform variable with the same name used in the script:
...
GLSLPROGRAM
uniform float _Seed; // declare the _Seed uniform float
Oh, it only works on play mode activated... Cool!! Thanks!!!
Your answer
![](https://koobas.hobune.stream/wayback/20220613084316im_/https://answers.unity.com/themes/thub/images/avi.jpg)