playfield · docs

docs · 04

Time and dt

How motion works in a shader, and why anything that changes every frame is scaled by dt, the frame's length.

Things move in a shader because the picture is drawn again every frame with a new time. There are two ways to describe motion, and the second needs one extra idea: dt.

1. Position from time

The simplest motion says where something is at time t, in seconds:

  • x = t * speed moves steadily.
  • x = sin(t) swings back and forth between −1 and 1.
  • x = fract(t) counts from 0 to 1 every second, then starts again: a loop.

Each frame works this out from the clock alone, so it looks the same on any screen.

2. Change per second

Some things can't be written as a position from time. A trail, a simulation or a smoothed value is built from the last frame: each frame changes the value a little.

x = x + speed adds the same step every frame.

3. Why frames differ

A screen at 120 frames a second draws twice as many frames as one at 60. Adding the same step every frame makes the motion twice as fast on the faster screen. An export, which renders frame by frame at its own rate, would differ again.

4. dt

dt is the length of this frame, in seconds: about 1/60 at 60 frames a second, 1/120 at 120. Scale each frame's change by it:

x = x + speed * dt

Now speed means units per second, and the motion looks the same at 30, 60 or 120 frames a second, and in exports. Adding up a rate times a small time step, frame after frame, is the first idea of calculus: an integral, done one frame at a time.

Fades work the same way with a multiply: keeping exp(-rate * dt) of the last frame fades at the same speed at any frame rate.

The rule: if something changes by a fixed amount every frame, it needs dt.

In Playfield

  • dt can be used in any input expression and in Expression Blocks.
  • The Time node has a Frame length (dt) output.
  • Accumulate adds up Rate × dt: wire in a speed and get a position.
  • Feedback and the Pass have Per second timing, so trails and fades look the same at any frame rate.

Your email, to tell you when Playfield opens and about big updates. Nothing else; unsubscribe any time. Privacy