previousFrame
This layer's own output from an earlier frame.
previousFrame(opts: {frames?: number; scale?: number} = {}): PreviousFrameInput
Import previousFrame from shaders/std.
With no options it is last frame's picture; frames: n reads the one from n frames ago (up to 8). scale keeps a smaller history, which is cheaper and blurs slightly with every frame (often what a trail wants).
Read it like any input: last(uv) gives straight-alpha colour. On the first frame it is transparent.
Parameters
| Name | Type | Notes |
|---|---|---|
opts | {frames?: number; scale?: number} | Optional. Default {}. |
Example
inputs: {last: previousFrame()},
paint: wgsl`
let ink = 1.0 - smoothstep(0.0, 0.03, distance(uv, pointer));
return max(last(uv) * fade, vec4f(ink));
`,
Tip. The whole body becomes one extra render pass, so a layer with a history costs a little more than one without.