improvements: smoother blur, better defaults

This commit is contained in:
sphynx-owner 2024-07-08 16:55:17 +03:00
commit 0d29da4911
7 changed files with 52 additions and 23 deletions

View file

@ -33,11 +33,11 @@
[ext_resource type="PackedScene" uid="uid://b62ieebpxbuin" path="res://Scenes/Section03/S3B1.tscn" id="16_m1vvn"] [ext_resource type="PackedScene" uid="uid://b62ieebpxbuin" path="res://Scenes/Section03/S3B1.tscn" id="16_m1vvn"]
[ext_resource type="PackedScene" uid="uid://q5n4wbhxihjp" path="res://Scenes/Section03/S3B2.tscn" id="17_4e0xd"] [ext_resource type="PackedScene" uid="uid://q5n4wbhxihjp" path="res://Scenes/Section03/S3B2.tscn" id="17_4e0xd"]
[ext_resource type="PackedScene" uid="uid://ncj04jk76gn0" path="res://Scenes/Section02/Bistro_StringLights.tscn" id="17_j1o0m"] [ext_resource type="PackedScene" uid="uid://ncj04jk76gn0" path="res://Scenes/Section02/Bistro_StringLights.tscn" id="17_j1o0m"]
[ext_resource type="RDShaderFile" uid="uid://b02ng0mepo13k" path="res://MyJumpFloodIteration/jump_flood_blur.glsl" id="17_lj2u4"] [ext_resource type="RDShaderFile" uid="uid://cdb8ur8nilc2v" path="res://MyJumpFloodIteration/jump_flood_blur.glsl" id="17_lj2u4"]
[ext_resource type="PackedScene" uid="uid://chlhxyb30n5bj" path="res://Scenes/Section03/S3B3.tscn" id="18_4ij38"] [ext_resource type="PackedScene" uid="uid://chlhxyb30n5bj" path="res://Scenes/Section03/S3B3.tscn" id="18_4ij38"]
[ext_resource type="AudioStream" uid="uid://b6rc81y5wriln" path="res://Audio/day_bg.ogg" id="18_kwmnc"] [ext_resource type="AudioStream" uid="uid://b6rc81y5wriln" path="res://Audio/day_bg.ogg" id="18_kwmnc"]
[ext_resource type="RDShaderFile" uid="uid://ei3ro3axdl8y" path="res://MyJumpFloodIteration/jfp_backtracking_experimental.glsl" id="18_opepq"] [ext_resource type="RDShaderFile" uid="uid://4q34gu55e05b" path="res://MyJumpFloodIteration/jfp_backtracking_experimental.glsl" id="18_opepq"]
[ext_resource type="RDShaderFile" uid="uid://bc2dlayo43x06" path="res://MyJumpFloodIteration/jump_flood_overlay.glsl" id="19_7g3lb"] [ext_resource type="RDShaderFile" uid="uid://dh60de130esmd" path="res://MyJumpFloodIteration/jump_flood_overlay.glsl" id="19_7g3lb"]
[ext_resource type="PackedScene" uid="uid://cou4bgmlcrc2" path="res://Scenes/Section03/S3B4.tscn" id="19_acyb5"] [ext_resource type="PackedScene" uid="uid://cou4bgmlcrc2" path="res://Scenes/Section03/S3B4.tscn" id="19_acyb5"]
[ext_resource type="AudioStream" uid="uid://cngxal8rdb5mj" path="res://Audio/night_bg.ogg" id="19_ida67"] [ext_resource type="AudioStream" uid="uid://cngxal8rdb5mj" path="res://Audio/night_bg.ogg" id="19_ida67"]
[ext_resource type="Script" path="res://MyJumpFloodIteration/jump_flood_blur.gd" id="20_0qnwf"] [ext_resource type="Script" path="res://MyJumpFloodIteration/jump_flood_blur.gd" id="20_0qnwf"]
@ -97,9 +97,10 @@ overlay_shader_file = ExtResource("19_7g3lb")
construction_pass = ExtResource("18_opepq") construction_pass = ExtResource("18_opepq")
perpen_error_threshold = 0.3 perpen_error_threshold = 0.3
sample_step_multiplier = 8.0 sample_step_multiplier = 8.0
backtracking_velocity_match_threshold = 0.49 backtracking_velocity_match_threshold = 0.9
backtracking_velocity_match_parallel_sensitivity = 0.5 backtracking_velocity_match_parallel_sensitivity = 1.0
backtracking_velcoity_match_perpendicular_sensitivity = 0.1 backtracking_velcoity_match_perpendicular_sensitivity = 0.05
backtracbing_depth_match_threshold = 0.001
JFA_pass_count = 3 JFA_pass_count = 3
framerate_independent = true framerate_independent = true
uncapped_independence = false uncapped_independence = false

View file

@ -23,7 +23,7 @@ layout(push_constant, std430) uniform Params
float velocity_match_threshold; float velocity_match_threshold;
float parallel_sensitivity; float parallel_sensitivity;
float perpendicular_sensitivity; float perpendicular_sensitivity;
float nan3; float depth_match_threshold;
float nan4; float nan4;
} params; } params;
@ -144,6 +144,14 @@ vec4 get_backtracked_sample(vec2 uvn, vec2 chosen_uv, vec2 chosen_velocity, vec4
float general_velocity_multiplier = min(best_sample_fitness.y, max_dilation_radius); float general_velocity_multiplier = min(best_sample_fitness.y, max_dilation_radius);
vec2 best_uv = chosen_uv;
float best_velocity_match_threshold = params.velocity_match_threshold;
int initial_steps_to_compare = 2;
int steps_to_compare = initial_steps_to_compare;
for(int i = -step_count; i < step_count + 1; i++) for(int i = -step_count; i < step_count + 1; i++)
{ {
float velocity_multiplier = general_velocity_multiplier * (1 + float(i) / float(step_count)); float velocity_multiplier = general_velocity_multiplier * (1 + float(i) / float(step_count));
@ -153,7 +161,7 @@ vec4 get_backtracked_sample(vec2 uvn, vec2 chosen_uv, vec2 chosen_velocity, vec4
continue; continue;
} }
vec2 new_sample = uvn - chosen_velocity * velocity_multiplier; vec2 new_sample = round((uvn - chosen_velocity * velocity_multiplier) * render_size) / render_size;
if((new_sample.x < 0.) || (new_sample.x > 1.) || (new_sample.y < 0.) || (new_sample.y > 1.)) if((new_sample.x < 0.) || (new_sample.x > 1.) || (new_sample.y < 0.) || (new_sample.y > 1.))
{ {
@ -162,11 +170,25 @@ vec4 get_backtracked_sample(vec2 uvn, vec2 chosen_uv, vec2 chosen_velocity, vec4
vec2 velocity_test = textureLod(velocity_sampler, new_sample, 0.0).xy; vec2 velocity_test = textureLod(velocity_sampler, new_sample, 0.0).xy;
if(get_motion_difference(chosen_velocity, velocity_test, params.parallel_sensitivity, params.perpendicular_sensitivity) <= params.velocity_match_threshold) float depth_test = textureLod(depth_sampler, new_sample, 0.0).x;
float velocity_match = get_motion_difference(chosen_velocity, velocity_test, params.parallel_sensitivity, params.perpendicular_sensitivity);
if((abs(depth_test - npd / best_sample_fitness.z) < params.depth_match_threshold) && (velocity_match <= best_velocity_match_threshold))
{ {
chosen_uv = new_sample; best_uv = new_sample;
best_sample_fitness.x = velocity_multiplier; if(steps_to_compare == 0)
return vec4(chosen_uv, best_sample_fitness.x, 0); {
chosen_uv = best_uv;
best_velocity_match_threshold = velocity_match;
return vec4(chosen_uv, 0, 0);
}
steps_to_compare--;
}
else if(initial_steps_to_compare > steps_to_compare)
{
chosen_uv = best_uv;
return vec4(chosen_uv, 0, 0);
} }
} }
@ -181,7 +203,7 @@ void main()
{ {
return; return;
} }
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size; vec2 uvn = (vec2(uvi)) / render_size;
int iteration_index = params.iteration_index; int iteration_index = params.iteration_index;

View file

@ -2,7 +2,7 @@
importer="glsl" importer="glsl"
type="RDShaderFile" type="RDShaderFile"
uid="uid://ei3ro3axdl8y" uid="uid://4q34gu55e05b"
path="res://.godot/imported/jfp_backtracking_experimental.glsl-d67307f6899fed647164be410a7debc8.res" path="res://.godot/imported/jfp_backtracking_experimental.glsl-d67307f6899fed647164be410a7debc8.res"
[deps] [deps]

View file

@ -35,15 +35,19 @@ class_name MotionBlurSphynxJumpFlood
@export var sample_step_multiplier : float = 8 @export var sample_step_multiplier : float = 8
## how sensitive the backtracking for velocities be ## how sensitive the backtracking for velocities be
@export var backtracking_velocity_match_threshold : float = 0.49 @export var backtracking_velocity_match_threshold : float = 0.9
## how sensitively the backtracking should treat velocities that are a different ## how sensitively the backtracking should treat velocities that are a different
## length along that velocity ## length along that velocity
@export var backtracking_velocity_match_parallel_sensitivity : float = 0.5; @export var backtracking_velocity_match_parallel_sensitivity : float = 1
## how sensitively the backtracking should treat velcoities that have perpendicular ## how sensitively the backtracking should treat velcoities that have perpendicular
## offset to that velocity ## offset to that velocity
@export var backtracking_velcoity_match_perpendicular_sensitivity : float = 0.1; @export var backtracking_velcoity_match_perpendicular_sensitivity : float = 0.05
## how closely does the depth of the backtracked sample has to match the original sample to be
## considered (in NDC space)
@export var backtracbing_depth_match_threshold : float = 0.001
## the number of passes performed by the jump flood algorithm based dilation, ## the number of passes performed by the jump flood algorithm based dilation,
## each pass added doubles the maximum radius of dilation available ## each pass added doubles the maximum radius of dilation available
@ -236,7 +240,7 @@ func _render_callback(p_effect_callback_type, p_render_data):
backtracking_velocity_match_threshold, backtracking_velocity_match_threshold,
backtracking_velocity_match_parallel_sensitivity, backtracking_velocity_match_parallel_sensitivity,
backtracking_velcoity_match_perpendicular_sensitivity, backtracking_velcoity_match_perpendicular_sensitivity,
0, backtracbing_depth_match_threshold,
0 0
] ]

View file

@ -159,7 +159,7 @@ void main()
return; return;
} }
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size; vec2 uvn = vec2(uvi) / render_size;
int iteration_count = int(params.motion_blur_samples); int iteration_count = int(params.motion_blur_samples);
@ -182,7 +182,9 @@ void main()
return; return;
} }
float velocity_step_coef = min(params.motion_blur_intensity, max_dialtion_radius / (length(velocity) * params.motion_blur_intensity)) / max(1.0, params.motion_blur_samples - 1.0) * (1 + (interleaved_gradient_noise(uvi, int(params.frame)) - 0.5)); float noise_offset = (interleaved_gradient_noise(uvi, int(params.frame)) - 1);
float velocity_step_coef = min(params.motion_blur_intensity, max_dialtion_radius / (length(velocity) * params.motion_blur_intensity)) / max(1.0, params.motion_blur_samples - 1.0);
vec3 sample_step = velocity * velocity_step_coef; vec3 sample_step = velocity * velocity_step_coef;
@ -193,7 +195,7 @@ void main()
float total_weight = 1;// max(0.0001, length(naive_velocity)); float total_weight = 1;// max(0.0001, length(naive_velocity));
vec2 offset = vec2(0.0); vec2 offset = vec2(sample_step * noise_offset);
vec4 col = base * total_weight; vec4 col = base * total_weight;

View file

@ -2,7 +2,7 @@
importer="glsl" importer="glsl"
type="RDShaderFile" type="RDShaderFile"
uid="uid://b02ng0mepo13k" uid="uid://cdb8ur8nilc2v"
path="res://.godot/imported/jump_flood_blur.glsl-df0c6b7cc65d8b0520871790f9075253.res" path="res://.godot/imported/jump_flood_blur.glsl-df0c6b7cc65d8b0520871790f9075253.res"
[deps] [deps]

View file

@ -2,7 +2,7 @@
importer="glsl" importer="glsl"
type="RDShaderFile" type="RDShaderFile"
uid="uid://bc2dlayo43x06" uid="uid://dh60de130esmd"
path="res://.godot/imported/jump_flood_overlay.glsl-764d3c488a9e9576eab825591e868325.res" path="res://.godot/imported/jump_flood_overlay.glsl-764d3c488a9e9576eab825591e868325.res"
[deps] [deps]