- Home /
provide delta time to shader (GLSL)
I am using a custom shader (GLSL) in my game which requires time (Delta time) , for fragment shader, now i don't know from where to provide delta time to "uniform vec2 time". Thank you.
Answer by CHPedersen · Jul 30, 2014 at 12:55 PM
Generally, values are passed to shaders using one of the static variants of Shader.SetGlobalXXX if the variable should be globally available to all shaders, or the non-static Material.SetXXX if the variable is to be available to only that particular shader. In your case, it would be Shader.SetGlobalFloat, or Material.SetFloat, since Time.deltaTime is a floating point value.
But in your specific example, you don't need to pass the value manually, because Time.deltaTime just so happens to be one of the built in shader values which are passed by the engine for you. Please see the tables at this link for a comprehensive list of these built in variables:
http://docs.unity3d.com/Manual/SL-BuiltinValues.html
The one you need is called "unity_DeltaTime", and is a float4. The x-component contains the deltaTime itself, while the y, z and w components of the vector contain different variants useful in other scenarios.
The link provided is dead, now the list of built-in shader variables is at http://docs.unity3d.com/430/Documentation/Components/SL-BuiltinValues.html
The link provided is dead, now the list of built-in shader variables is at https://docs.unity3d.com/$$anonymous$$anual/SL-UnityShaderVariables.html