deltaTime
Provides the time elapsed in seconds since the last rendered frame within a TSL shader, serving as the cornerstone for frame-rate independent animations and physics simulations.
Core Advantages
It fully automates the process of calculating and passing the time difference. Developers can effortlessly create smooth, consistent animations within the shader without any manual JS-side work, ensuring dynamic effects behave identically regardless of hardware performance (FPS).
Common Uses
Creating frame-rate independent movement, rotation, or scaling animations.
Implementing simple physics like gravity and drag directly within a shader.
Driving periodic effects like water waves, pulses, or flashes with a consistent, time-based rhythm.
Building internal, shader-based timers for complex effects.
How to adjust
This node's value is not adjustable; it is an objective measurement of the time taken for the last frame, provided by the renderer. The key is how to 'use' it: multiply any rate of change (like speed or angular velocity) by deltaTime to convert a 'per-frame' change into a 'per-second' change, thus achieving frame-rate independent, smooth animation.
Code Examples
1// Accumulate time to create a continuous animation driver
2totalTime.addAssign( deltaTime );
3
4// Use the accumulated time to drive a wave motion
5// Multiplying by a speed factor ensures the wave propagates consistently over time
6const wave = sin( distanceToCenter * frequency - totalTime * speed );