From 7f1863f83d239b7450394930474f8620511e019c Mon Sep 17 00:00:00 2001 From: clayjohn Date: Thu, 4 Jan 2024 16:09:32 -0800 Subject: [PATCH] Tune TAA disocclusion scale to avoid rejecting all samples during motion. --- servers/rendering/renderer_rd/effects/taa.cpp | 4 ++-- .../rendering/renderer_rd/shaders/effects/taa_resolve.glsl | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/servers/rendering/renderer_rd/effects/taa.cpp b/servers/rendering/renderer_rd/effects/taa.cpp index c1037ec11a2..4ac5552aa6c 100644 --- a/servers/rendering/renderer_rd/effects/taa.cpp +++ b/servers/rendering/renderer_rd/effects/taa.cpp @@ -62,8 +62,8 @@ void TAA::resolve(RID p_frame, RID p_temp, RID p_depth, RID p_velocity, RID p_pr memset(&push_constant, 0, sizeof(TAAResolvePushConstant)); push_constant.resolution_width = p_resolution.width; push_constant.resolution_height = p_resolution.height; - push_constant.disocclusion_threshold = 0.025f; - push_constant.disocclusion_scale = 10.0f; + push_constant.disocclusion_threshold = 2.5f; // If velocity changes by less than this amount of texels we can retain the accumulation buffer. + push_constant.disocclusion_scale = 0.01f; // Scale the weight of this pixel calculated as (change in velocity - threshold) * scale. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin(); RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, pipeline); diff --git a/servers/rendering/renderer_rd/shaders/effects/taa_resolve.glsl b/servers/rendering/renderer_rd/shaders/effects/taa_resolve.glsl index e50397cc5d3..00ac6a7919f 100644 --- a/servers/rendering/renderer_rd/shaders/effects/taa_resolve.glsl +++ b/servers/rendering/renderer_rd/shaders/effects/taa_resolve.glsl @@ -307,6 +307,8 @@ float luminance(vec3 color) { return max(dot(color, lumCoeff), 0.0001f); } +// This is "velocity disocclusion" as described by https://www.elopezr.com/temporal-aa-and-the-quest-for-the-holy-trail/. +// We use texel space, so our scale and threshold differ. float get_factor_disocclusion(vec2 uv_reprojected, vec2 velocity) { vec2 velocity_previous = imageLoad(last_velocity_buffer, ivec2(uv_reprojected * params.resolution)).xy; vec2 velocity_texels = velocity * params.resolution; @@ -336,7 +338,7 @@ vec3 temporal_antialiasing(uvec2 pos_group_top_left, uvec2 pos_group, uvec2 pos_ // Compute blend factor float blend_factor = RPC_16; // We want to be able to accumulate as many jitter samples as we generated, that is, 16. { - // If re-projected UV is out of screen, converge to current color immediatel + // If re-projected UV is out of screen, converge to current color immediately. float factor_screen = any(lessThan(uv_reprojected, vec2(0.0))) || any(greaterThan(uv_reprojected, vec2(1.0))) ? 1.0 : 0.0; // Increase blend factor when there is disocclusion (fixes a lot of the remaining ghosting).