mirror of
https://github.com/sphynx-owner/JFA_driven_motion_blur_addon.git
synced 2025-09-19 12:16:16 +08:00
Complete overhaul, new implementations
- Overhauled file structure to be on addons for universality - Streamlined compositor shader stages with custom classes and resources - Added previous proven implementations (McGuire, Guertin) - entirely new and improved jump flood implementation, more realistic, robust, and performant
This commit is contained in:
@ -0,0 +1,137 @@
|
||||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D neighbor_max;
|
||||
layout(set = 0, binding = 4) uniform sampler2D tile_variance;
|
||||
layout(rgba16f, set = 0, binding = 5) uniform writeonly image2D output_color;
|
||||
layout(rgba16f, set = 0, binding = 6) uniform image2D past_color_image;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float minimum_user_threshold;
|
||||
float importance_bias;
|
||||
float maximum_jitter_value;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int sample_count;
|
||||
int frame;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - abs(T) / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, abs(T));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float multiplier)
|
||||
{
|
||||
return clamp(1. + (a - b) * multiplier, 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv, int FrameId){
|
||||
uv += float(FrameId) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
vec2 sample_random_offset(vec2 uv, float j)
|
||||
{
|
||||
return vec2(0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 tile_render_size = ivec2(textureSize(neighbor_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 vn = textureLod(neighbor_max, x, 0.0).xy * render_size / 2;
|
||||
|
||||
float vn_length = max(0.5, length(vn));
|
||||
|
||||
vec4 base_color = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_color, uvi, base_color);
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 vx = textureLod(velocity_sampler, x, 0.0).xy * render_size / 2;
|
||||
|
||||
float zx = -0.05 / textureLod(depth_sampler, x, 0.0).x;
|
||||
|
||||
float vx_length = max(0.5, length(vx));
|
||||
|
||||
float weight = 1. / vx_length;
|
||||
|
||||
vec4 sum = base_color * weight;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi, params.frame) - 0.5;
|
||||
|
||||
for(int i = 0; i < params.sample_count; i++)
|
||||
{
|
||||
if(i == (params.sample_count - 1) / 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float t = mix(-1, 1, (i + j + 1.0) / (params.sample_count + 1.0));
|
||||
|
||||
float T = t * vn_length;
|
||||
|
||||
vec2 y = x + (vn / render_size) * t;
|
||||
|
||||
vec2 vy = textureLod(velocity_sampler, y, 0.0).xy * render_size / 2;
|
||||
|
||||
float vy_length = max(0.5, length(vy));
|
||||
|
||||
float zy = -0.05 / textureLod(depth_sampler, y, 0.0).x;
|
||||
|
||||
float f = soft_depth_compare(zx, zy, 0.01);
|
||||
float b = soft_depth_compare(zy, zx, 0.01);
|
||||
|
||||
float ay = f * cone(T, vy_length) + b * cone(T, vx_length) + cylinder(T, vy_length) * cylinder(T, vx_length) * 2;
|
||||
|
||||
weight += ay;
|
||||
sum += ay * textureLod(color_sampler, y, 0.0);
|
||||
}
|
||||
|
||||
sum /= weight;
|
||||
|
||||
imageStore(output_color, uvi, sum);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://7fjex8wuiejk"
|
||||
path="res://.godot/imported/mcguire_blur.glsl-0cc0e90626b85e4aae8d4b21c9368b86.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_blur.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_blur.glsl-0cc0e90626b85e4aae8d4b21c9368b86.res"]
|
||||
|
||||
[params]
|
||||
|
@ -0,0 +1,72 @@
|
||||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D neighbor_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_neighbor_velocity = vec2(0);
|
||||
|
||||
float max_neighbor_velocity_length = 0;
|
||||
|
||||
for(int i = -1; i < 2; i++)
|
||||
{
|
||||
for(int j = -1; j < 2; j++)
|
||||
{
|
||||
vec2 current_offset = vec2(1) / vec2(render_size) * vec2(i, j);
|
||||
vec2 current_uv = uvn + current_offset;
|
||||
if(current_uv.x < 0 || current_uv.x > 1 || current_uv.y < 0 || current_uv.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_diagonal = (abs(i) + abs(j) == 2);
|
||||
|
||||
vec2 current_neighbor_velocity = textureLod(tile_max, current_uv, 0.0).xy;
|
||||
|
||||
bool facing_center = dot(current_neighbor_velocity, current_offset) > 0;
|
||||
|
||||
if(is_diagonal && !facing_center)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float current_neighbor_velocity_length = dot(current_neighbor_velocity, current_neighbor_velocity);
|
||||
if(current_neighbor_velocity_length > max_neighbor_velocity_length)
|
||||
{
|
||||
max_neighbor_velocity_length = current_neighbor_velocity_length;
|
||||
max_neighbor_velocity = current_neighbor_velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageStore(neighbor_max, uvi, vec4(max_neighbor_velocity, 0, 1));
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://byfogr1qtbafi"
|
||||
path="res://.godot/imported/mcguire_neighbor_max.glsl-aa40cc8d534a08ad7aaf84bf0615cc3a.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_neighbor_max.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_neighbor_max.glsl-aa40cc8d534a08ad7aaf84bf0615cc3a.res"]
|
||||
|
||||
[params]
|
||||
|
@ -0,0 +1,18 @@
|
||||
#[compute]
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D blur_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform image2D color_image;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(blur_sampler, 0));
|
||||
ivec2 output_size = imageSize(color_image);
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uv.x >= output_size.x) || (uv.y >= output_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
imageStore(color_image, uv, textureLod(blur_sampler, (vec2(uv) + 0.5) / output_size, 0.0));
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://ylkrbqh7unvl"
|
||||
path="res://.godot/imported/mcguire_overlay.glsl-a331e470c95eacb608a05976de7b2202.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_overlay.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_overlay.glsl-a331e470c95eacb608a05976de7b2202.res"]
|
||||
|
||||
[params]
|
||||
|
@ -0,0 +1,54 @@
|
||||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D velocity_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_max_x;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(velocity_sampler, 0));
|
||||
ivec2 output_size = imageSize(tile_max_x);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
ivec2 global_uvi = uvi * ivec2(params.tile_size, 1);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_velocity = vec2(0);
|
||||
|
||||
float max_velocity_length = 0;
|
||||
|
||||
for(int i = 0; i < params.tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(float(i) / render_size.x, 0);
|
||||
vec2 velocity_sample = textureLod(velocity_sampler, current_uv, 0.0).xy;
|
||||
float current_velocity_length = dot(velocity_sample, velocity_sample);
|
||||
if(current_velocity_length > max_velocity_length)
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = velocity_sample;
|
||||
}
|
||||
}
|
||||
imageStore(tile_max_x, uvi, vec4(max_velocity, 0, 1));
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://bp5jl5351ph2d"
|
||||
path="res://.godot/imported/mcguire_tile_max_x.glsl-9c459b3d537ec225893d39ee91be1c1e.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_tile_max_x.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_tile_max_x.glsl-9c459b3d537ec225893d39ee91be1c1e.res"]
|
||||
|
||||
[params]
|
||||
|
@ -0,0 +1,54 @@
|
||||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max_x;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max_x, 0));
|
||||
ivec2 output_size = imageSize(tile_max);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
ivec2 global_uvi = uvi * ivec2(1, params.tile_size);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_velocity = vec2(0);
|
||||
|
||||
float max_velocity_length = 0;
|
||||
|
||||
for(int i = 0; i < params.tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(0, float(i) / render_size.y);
|
||||
vec2 velocity_sample = textureLod(tile_max_x, current_uv, 0.0).xy;
|
||||
float current_velocity_length = dot(velocity_sample, velocity_sample);
|
||||
if(current_velocity_length > max_velocity_length)
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = velocity_sample;
|
||||
}
|
||||
}
|
||||
imageStore(tile_max, uvi, vec4(max_velocity, 0, 1));
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://deow8m5u2ji84"
|
||||
path="res://.godot/imported/mcguire_tile_max_y.glsl-d6c42f715f0dbdbc13190532231a64e9.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_tile_max_y.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_tile_max_y.glsl-d6c42f715f0dbdbc13190532231a64e9.res"]
|
||||
|
||||
[params]
|
||||
|
@ -0,0 +1,68 @@
|
||||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_variance;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
float variance = 0;
|
||||
|
||||
vec2 current_velocity = abs(normalize(textureLod(tile_max, uvn, 0.0).xy));
|
||||
|
||||
float tile_count = 0;
|
||||
|
||||
for(int i = -1; i < 2; i++)
|
||||
{
|
||||
for(int j = -1; j < 2; j++)
|
||||
{
|
||||
vec2 current_offset = vec2(1) / vec2(render_size) * vec2(i, j);
|
||||
vec2 current_uv = uvn + current_offset;
|
||||
if(current_uv.x < 0 || current_uv.x > 1 || current_uv.y < 0 || current_uv.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(i == j && i == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
tile_count += 1;
|
||||
|
||||
vec2 current_neighbor_velocity = abs(normalize(textureLod(tile_max, current_uv, 0.0).xy));
|
||||
|
||||
variance += dot(current_velocity, current_neighbor_velocity);
|
||||
}
|
||||
}
|
||||
|
||||
variance /= tile_count;
|
||||
|
||||
imageStore(tile_variance, uvi, vec4(1 - variance));
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://ddo60n85uqwbk"
|
||||
path="res://.godot/imported/mcguire_tile_variance.glsl-2a5a77e5f43c4a3d379a9c7c55e12bf6.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_tile_variance.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_tile_variance.glsl-2a5a77e5f43c4a3d379a9c7c55e12bf6.res"]
|
||||
|
||||
[params]
|
||||
|
Reference in New Issue
Block a user