diff --git a/MainScene.tscn b/MainScene.tscn index 6859e96..c37928c 100644 --- a/MainScene.tscn +++ b/MainScene.tscn @@ -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://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="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="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://bc2dlayo43x06" path="res://MyJumpFloodIteration/jump_flood_overlay.glsl" id="19_7g3lb"] +[ext_resource type="RDShaderFile" uid="uid://4q34gu55e05b" path="res://MyJumpFloodIteration/jfp_backtracking_experimental.glsl" id="18_opepq"] +[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="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"] @@ -97,9 +97,10 @@ overlay_shader_file = ExtResource("19_7g3lb") construction_pass = ExtResource("18_opepq") perpen_error_threshold = 0.3 sample_step_multiplier = 8.0 -backtracking_velocity_match_threshold = 0.49 -backtracking_velocity_match_parallel_sensitivity = 0.5 -backtracking_velcoity_match_perpendicular_sensitivity = 0.1 +backtracking_velocity_match_threshold = 0.9 +backtracking_velocity_match_parallel_sensitivity = 1.0 +backtracking_velcoity_match_perpendicular_sensitivity = 0.05 +backtracbing_depth_match_threshold = 0.001 JFA_pass_count = 3 framerate_independent = true uncapped_independence = false diff --git a/MyJumpFloodIteration/jfp_backtracking_experimental.glsl b/MyJumpFloodIteration/jfp_backtracking_experimental.glsl index b614956..c7eaf39 100644 --- a/MyJumpFloodIteration/jfp_backtracking_experimental.glsl +++ b/MyJumpFloodIteration/jfp_backtracking_experimental.glsl @@ -23,7 +23,7 @@ layout(push_constant, std430) uniform Params float velocity_match_threshold; float parallel_sensitivity; float perpendicular_sensitivity; - float nan3; + float depth_match_threshold; float nan4; } 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); + 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++) { 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; } - 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.)) { @@ -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; - 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_sample_fitness.x = velocity_multiplier; - return vec4(chosen_uv, best_sample_fitness.x, 0); + best_uv = new_sample; + if(steps_to_compare == 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; } - vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size; + vec2 uvn = (vec2(uvi)) / render_size; int iteration_index = params.iteration_index; diff --git a/MyJumpFloodIteration/jfp_backtracking_experimental.glsl.import b/MyJumpFloodIteration/jfp_backtracking_experimental.glsl.import index 57c2ad2..744c889 100644 --- a/MyJumpFloodIteration/jfp_backtracking_experimental.glsl.import +++ b/MyJumpFloodIteration/jfp_backtracking_experimental.glsl.import @@ -2,7 +2,7 @@ importer="glsl" type="RDShaderFile" -uid="uid://ei3ro3axdl8y" +uid="uid://4q34gu55e05b" path="res://.godot/imported/jfp_backtracking_experimental.glsl-d67307f6899fed647164be410a7debc8.res" [deps] diff --git a/MyJumpFloodIteration/jump_flood_blur.gd b/MyJumpFloodIteration/jump_flood_blur.gd index c196ec7..05c063e 100644 --- a/MyJumpFloodIteration/jump_flood_blur.gd +++ b/MyJumpFloodIteration/jump_flood_blur.gd @@ -35,15 +35,19 @@ class_name MotionBlurSphynxJumpFlood @export var sample_step_multiplier : float = 8 ## 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 ## 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 ## 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, ## 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_parallel_sensitivity, backtracking_velcoity_match_perpendicular_sensitivity, - 0, + backtracbing_depth_match_threshold, 0 ] diff --git a/MyJumpFloodIteration/jump_flood_blur.glsl b/MyJumpFloodIteration/jump_flood_blur.glsl index da7c695..263ad19 100644 --- a/MyJumpFloodIteration/jump_flood_blur.glsl +++ b/MyJumpFloodIteration/jump_flood_blur.glsl @@ -159,7 +159,7 @@ void main() return; } - vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size; + vec2 uvn = vec2(uvi) / render_size; int iteration_count = int(params.motion_blur_samples); @@ -182,7 +182,9 @@ void main() 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; @@ -193,7 +195,7 @@ void main() 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; diff --git a/MyJumpFloodIteration/jump_flood_blur.glsl.import b/MyJumpFloodIteration/jump_flood_blur.glsl.import index 4cb76a6..d6a71fa 100644 --- a/MyJumpFloodIteration/jump_flood_blur.glsl.import +++ b/MyJumpFloodIteration/jump_flood_blur.glsl.import @@ -2,7 +2,7 @@ importer="glsl" type="RDShaderFile" -uid="uid://b02ng0mepo13k" +uid="uid://cdb8ur8nilc2v" path="res://.godot/imported/jump_flood_blur.glsl-df0c6b7cc65d8b0520871790f9075253.res" [deps] diff --git a/MyJumpFloodIteration/jump_flood_overlay.glsl.import b/MyJumpFloodIteration/jump_flood_overlay.glsl.import index 2a2a142..c420cea 100644 --- a/MyJumpFloodIteration/jump_flood_overlay.glsl.import +++ b/MyJumpFloodIteration/jump_flood_overlay.glsl.import @@ -2,7 +2,7 @@ importer="glsl" type="RDShaderFile" -uid="uid://bc2dlayo43x06" +uid="uid://dh60de130esmd" path="res://.godot/imported/jump_flood_overlay.glsl-764d3c488a9e9576eab825591e868325.res" [deps]