1
\$\begingroup\$

In the "Built-in shader variables" section of the Unity Manual, underneath the Time header, there is a table that provides information about each time variable: _Time; _SinTime; _CosTime; unity_DeltaTime. It states to use _Time to animate things inside of a shader. Why is it recommended to use time instead of delta time, like it's recommended to be used in C# scripts for animating?

Unity Manual/Built-in shader variables/Time

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

In MonoBehaviours, deltaTime is usually used to advance the internal state of the gameObject from the state of the last frame to the state of the new frame.

But shaders are stateless functions. They are not based on their last frame. Each frame is calculated from scratch based on the input parameters. That makes deltaTime not very useful in shaders. It will be roughly the same each frame, so what do you intend to do with it?

The absolute time, on the other hand, will be different each frame, which makes it far more useful for animations in shaders. A common technique to get cyclic animations is to calculate the modulus of _Time or to run the current time through a cyclic function like sine or cosine (which is why Unity provides shortcuts for the latter in form of _SinTime and _CosTime).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .