LAYER_VELOCITY beta
Variable of @v12-engine/render
ts
LAYER_VELOCITY = "\n\nstruct Layer {\n\t// the view and projection the frame is drawn with (jittered, as the view's pass has it)\n\tviewProjection: mat4x4f,\n\t// the same without the jitter, this frame's and the frame's before\n\tplain: mat4x4f,\n\tlast: mat4x4f,\n\t// the picture's width and height in pixels, and 1 / them\n\tsize: vec4f,\n}\n@group(0) @binding(0) var<uniform> layer: Layer;\n\n@group(0) @binding(1) var sceneDepth: texture_depth_2d;\n// Half the way from where the point is to where it was, in clip space with y down the screen (what the blend adds to\n// a pixel's uv); nothing where the view drew something nearer\nfn velocityOut(position: vec4f, now: vec4f, was: vec4f) -> vec4f {\n\tif (position.z > textureLoad(sceneDepth, vec2i(position.xy), 0) + 0.000002) { discard; }\n\tlet v = 0.5 * (was.xy / was.w - now.xy / now.w) * vec2f(1.0, -1.0);\n\treturn vec4f(clamp(v, vec2f(-4.0), vec2f(4.0)), 0.0, 1.0);\n}\n"The velocity's: after a copy's own record its matrix of the frame before comes in four more locations. The vertex stage gives the place now and the place then, both without the jitter (layer.plain * now, layer.last * then), and the fragment returns velocityOut(position, now, was).