Const Advancedclass MyTemporalPass extends Pass3D {
public readonly stage = 'afterTransparent';
public readonly requiredOutputs = [velocityOutput];
public build(graph: RenderGraph, ctx: PassContext): void {
const velocity = graph.getSceneOutput(velocityOutput);
graph.addPass(new MyResolvePass({ renderer: ctx.renderer, velocity }));
}
}
How far each pixel's surface moved on screen since the camera's previous render, from the camera's motion alone, in an
rg16floattextureThe value is the surface's UV now minus its UV at the previous render, with UV running 0 to 1 across the view's image, so
uv - velocityis where the surface was in last frame's image. Objects count as still: a car passing a still camera reads zero, and a cockpit parented to a moving camera reads the camera's motion, so motion blur streaks it though it holds still on screen.vruns the way the scene texture's rows do, like theuvaneffect(uv)receives, souv - velocityworks on both backends and any target. Which wayvpoints on screen varies with both, so turn it into a screen direction only for display. The texture is pooled and can be larger than the view: a FullscreenPass mapsuvonto it insampleColorandsampleColor2, and a shader of your own scales a view UV by the camera'suViewportUVScalefirst.Each camera compares with its own previous render, so a view drawn twice in a frame reads no motion the second time; give that render a camera of its own. A camera reads zero on its first render. A camera cut reads the jump between shots for one frame; call Camera3D#resetHistory on the cut so it reads zero instead. The camera's
jittercancels out, and each component is clamped to ±1. On a canvas withantialiasthe velocity is multisampled with the scene, so an edge pixel reads the average of its samples, counting zero where nothing drew.Opaque surfaces write it. One whose material has a template of its own doesn't, so its pixels keep zero or the motion of a surface behind it that drew first. Blended, glass and refractive surfaces leave the opaque value under them. Where nothing drew, the background included, it reads zero, so a turning camera's sky reads as still.