|
@@ -19,6 +19,7 @@
|
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
// File changes (yyyy-mm-dd)
|
|
// File changes (yyyy-mm-dd)
|
|
|
|
|
+// 2025-11-05: Jakub Brzyski: Added dynamic variance, base variance value adjusted to reduce ghosting
|
|
|
// 2022-05-06: Panos Karabelas: first commit
|
|
// 2022-05-06: Panos Karabelas: first commit
|
|
|
// 2020-12-05: Joan Fons: convert to Vulkan and Godot
|
|
// 2020-12-05: Joan Fons: convert to Vulkan and Godot
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
@@ -38,6 +39,8 @@
|
|
|
#define RPC_9 0.11111111111
|
|
#define RPC_9 0.11111111111
|
|
|
#define RPC_16 0.0625
|
|
#define RPC_16 0.0625
|
|
|
|
|
|
|
|
|
|
+#define DISOCCLUSION_SCALE 0.01 // Scale the weight of this pixel calculated as (change in velocity - threshold) * scale.
|
|
|
|
|
+
|
|
|
layout(local_size_x = GROUP_SIZE, local_size_y = GROUP_SIZE, local_size_z = 1) in;
|
|
layout(local_size_x = GROUP_SIZE, local_size_y = GROUP_SIZE, local_size_z = 1) in;
|
|
|
|
|
|
|
|
layout(rgba16f, set = 0, binding = 0) uniform restrict readonly image2D color_buffer;
|
|
layout(rgba16f, set = 0, binding = 0) uniform restrict readonly image2D color_buffer;
|
|
@@ -49,8 +52,8 @@ layout(rgba16f, set = 0, binding = 5) uniform restrict writeonly image2D output_
|
|
|
|
|
|
|
|
layout(push_constant, std430) uniform Params {
|
|
layout(push_constant, std430) uniform Params {
|
|
|
vec2 resolution;
|
|
vec2 resolution;
|
|
|
- float disocclusion_threshold; // 0.1 / max(params.resolution.x, params.resolution.y
|
|
|
|
|
- float disocclusion_scale;
|
|
|
|
|
|
|
+ float disocclusion_threshold; // 0.1 / max(params.resolution.x, params.resolution.y)
|
|
|
|
|
+ float variance_dynamic;
|
|
|
}
|
|
}
|
|
|
params;
|
|
params;
|
|
|
|
|
|
|
@@ -273,7 +276,8 @@ vec3 clip_history_3x3(uvec2 group_pos, vec3 color_history, vec2 velocity_closest
|
|
|
// Compute min and max (with an adaptive box size, which greatly reduces ghosting)
|
|
// Compute min and max (with an adaptive box size, which greatly reduces ghosting)
|
|
|
vec3 color_avg = (s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9) * RPC_9;
|
|
vec3 color_avg = (s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9) * RPC_9;
|
|
|
vec3 color_avg2 = ((s1 * s1) + (s2 * s2) + (s3 * s3) + (s4 * s4) + (s5 * s5) + (s6 * s6) + (s7 * s7) + (s8 * s8) + (s9 * s9)) * RPC_9;
|
|
vec3 color_avg2 = ((s1 * s1) + (s2 * s2) + (s3 * s3) + (s4 * s4) + (s5 * s5) + (s6 * s6) + (s7 * s7) + (s8 * s8) + (s9 * s9)) * RPC_9;
|
|
|
- float box_size = mix(0.0f, 2.5f, smoothstep(0.02f, 0.0f, length(velocity_closest)));
|
|
|
|
|
|
|
+ // Use variance clipping as described in https://developer.download.nvidia.com/gameworks/events/GDC2016/msalvi_temporal_supersampling.pdf
|
|
|
|
|
+ float box_size = mix(0.0f, params.variance_dynamic, smoothstep(0.02f, 0.0f, length(velocity_closest)));
|
|
|
vec3 dev = sqrt(abs(color_avg2 - (color_avg * color_avg))) * box_size;
|
|
vec3 dev = sqrt(abs(color_avg2 - (color_avg * color_avg))) * box_size;
|
|
|
vec3 color_min = color_avg - dev;
|
|
vec3 color_min = color_avg - dev;
|
|
|
vec3 color_max = color_avg + dev;
|
|
vec3 color_max = color_avg + dev;
|
|
@@ -304,7 +308,7 @@ float get_factor_disocclusion(vec2 uv_reprojected, vec2 velocity) {
|
|
|
vec2 velocity_texels = velocity * params.resolution;
|
|
vec2 velocity_texels = velocity * params.resolution;
|
|
|
vec2 prev_velocity_texels = velocity_previous * params.resolution;
|
|
vec2 prev_velocity_texels = velocity_previous * params.resolution;
|
|
|
float disocclusion = length(prev_velocity_texels - velocity_texels) - params.disocclusion_threshold;
|
|
float disocclusion = length(prev_velocity_texels - velocity_texels) - params.disocclusion_threshold;
|
|
|
- return clamp(disocclusion * params.disocclusion_scale, 0.0, 1.0);
|
|
|
|
|
|
|
+ return clamp(disocclusion * DISOCCLUSION_SCALE, 0.0, 1.0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
vec3 temporal_antialiasing(uvec2 pos_group_top_left, uvec2 pos_group, uvec2 pos_screen, vec2 uv, sampler2D tex_history) {
|
|
vec3 temporal_antialiasing(uvec2 pos_group_top_left, uvec2 pos_group, uvec2 pos_screen, vec2 uv, sampler2D tex_history) {
|