#version 450 // Camera motion vectors for DLAA (vk_dlaa.c mv_pass): each pixel's depth goes through reproj, last frame's // view-projection times the inverse of this frame's (made on the CPU in double precision, so a still camera gives the // identity and no motion); the vector is last frame's window position minus this frame's, in render pixels, without // the jitter (DLSS's default convention). Objects that move on their own get only the camera's motion. // The view-projections are TotK's scene uniform block (bound as c4 in the scene's vertex shaders), vec4 rows 3-6, with // OpenGL clip depth (-w..w). The replay's viewports have negative heights, so window y grows downwards from ndc y = +1, // and depth is z_ndc * 0.5 + 0.5. layout(local_size_x = 8, local_size_y = 8) in; layout(binding = 0) uniform sampler2D depth_tex; layout(binding = 1, rg16f) uniform writeonly image2D mv_out; layout(push_constant) uniform P { mat4 reproj; // this frame's clip space to last frame's vec2 size; // render size in pixels vec2 jitter; // this frame's jitter, pixels, as the scene was drawn (window x right, y down) } pc; void main() { ivec2 p = ivec2(gl_GlobalInvocationID.xy); if (p.x >= int(pc.size.x) || p.y >= int(pc.size.y)) return; float d = texelFetch(depth_tex, p, 0).r; vec2 win = vec2(p) + 0.5 - pc.jitter; // where this pixel's surface sits without the jitter vec4 ndc = vec4(win.x / pc.size.x * 2.0 - 1.0, 1.0 - win.y / pc.size.y * 2.0, d * 2.0 - 1.0, 1.0); vec4 clip = pc.reproj * ndc; vec2 mv = vec2(0.0); if (clip.w > 1e-6) { vec2 pn = clip.xy / clip.w; vec2 pwin = vec2((pn.x * 0.5 + 0.5) * pc.size.x, (0.5 - pn.y * 0.5) * pc.size.y); mv = pwin - win; } imageStore(mv_out, p, vec4(mv, 0.0, 0.0)); }