home/ atoms/ glsl-unbounded-time-precision-loss

Unbounded `u_time` loses float precision over minutes, causing visible jitter in periodic motion

The u_time uniform grows continuously and eventually exceeds the range where a float holds fine fractional detail, causing visible jitter in animations that depend on exact fractional values. Periodic motion via sin(u_time) is inherently safe because the function is bounded, but fract(u_time) or fine coordinate arithmetic on large u_time will step. The standard mitigation is to wrap time: mod(u_time, 100.0), or fract(u_time * speed) for sawtooths. Speed always belongs in a multiplier — sin(u_time * speed) — not inside u_time itself.

Examples

sin(u_time) — safe (bounded) fract(u_time * 0.5) — sawtooth, safer than raw fract mod(u_time, 100.0) — explicit wrap to stay in range

Assessment

A shader runs fine for 2 minutes then flickers. Its only time reference is fract(u_time). Explain the likely cause and rewrite the expression to avoid precision loss.

“Unbounded `u_time`** eventually loses float precision (jitter after minutes) — wrap it for periodic motion (`sin(u_time)` is fine; `fract(u_time)` for sawtooths; `mod(u_time, N)`).”
context/ · L1-instruments/glsl/gotchas.md · chunk 1