mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 13:05:57 +00:00
Make DLSS's picture reach the screen and stop the whole image wobbling with DLSS and DLAA
With a DLSS mode the game's own scaling draw covered DLSS's picture with the jittered scene. At a 1280x720 scene and 1920x1080 output the scaling is done by the game's tonemap, not by the FXAA shader vk_dlaa_skip_draw looks for, so no hash list could catch it. From DLSS's evaluation to the frame's end, passes larger than the light target now sample DLSS's output in its place (vk_dlaa_swap_img, applied in vk_exec_draw.c tex_info), whichever shader scales. The motion-vector shader inverted the view-projection in 32-bit floats. With a still camera (identical matrices each frame) the rounding still gave a few hundredths of a pixel of motion that changed with every jitter step; DLSS followed it and the whole picture wobbled. mv_pass now makes last frame's view-projection times the inverse of this frame's in double precision from the uniform snapshot (vk_usnap_host), and the shader only applies it. Measured on 1.4.3 indoors, still camera, mean per-pixel change between consecutive frames on static areas: DLSS quality 0.18 -> 0.06, DLAA 0.14 -> 0.05. A camera pan at 10 px per frame shows no ghosting.
This commit is contained in:
1 parent
c38e0ca13d
commit
5b23d6671b
7 files changed
+186
-179
No files matched your search
@@ -1,40 +1,32 @@
|
||||
#version 450
|
||||
// Camera motion vectors for DLAA (vk_dlaa.c mv_pass): each pixel's depth is taken back to the world through this
|
||||
// frame's view-projection and forward through last frame's; 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 camera block is TotK's scene uniform block (bound as c4 in the scene's vertex shaders): vec4 rows 3-6 are the
|
||||
// view-projection, rows of a row-major 4x4 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.
|
||||
// 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(binding = 2, std140) uniform Cur { vec4 r[16]; } cur;
|
||||
layout(binding = 3, std140) uniform Prev { vec4 r[16]; } prev;
|
||||
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;
|
||||
|
||||
mat4 vp(vec4 a, vec4 b, vec4 c, vec4 d) { return transpose(mat4(a, b, c, d)); }
|
||||
|
||||
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);
|
||||
mat4 c = vp(cur.r[3], cur.r[4], cur.r[5], cur.r[6]);
|
||||
mat4 q = vp(prev.r[3], prev.r[4], prev.r[5], prev.r[6]);
|
||||
vec4 world = inverse(c) * ndc;
|
||||
vec4 clip = pc.reproj * ndc;
|
||||
vec2 mv = vec2(0.0);
|
||||
if (abs(world.w) > 1e-12) {
|
||||
vec4 clip = q * (world / world.w);
|
||||
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;
|
||||
}
|
||||
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));
|
||||
}
|
||||
Reference in new issue
Block a user