From dcbf929d6ebeef7f93f880d82deed56074a2bc5a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 24 Aug 2018 00:21:48 +0200 Subject: [PATCH] Parametrize patch size and number of iterations. --- flow.cpp | 9 +++++++-- flow.h | 8 +++++--- motion_search.frag | 5 ++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/flow.cpp b/flow.cpp index 95bb154..16af155 100644 --- a/flow.cpp +++ b/flow.cpp @@ -326,7 +326,8 @@ void Sobel::exec(GLint tex_view, GLint grad_tex, int level_width, int level_heig glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, num_layers); } -MotionSearch::MotionSearch() +MotionSearch::MotionSearch(const OperatingPoint &op) + : op(op) { motion_vs_obj = compile_shader(read_file("motion_search.vert"), GL_VERTEX_SHADER); motion_fs_obj = compile_shader(read_file("motion_search.frag"), GL_FRAGMENT_SHADER); @@ -338,6 +339,8 @@ MotionSearch::MotionSearch() uniform_image_tex = glGetUniformLocation(motion_search_program, "image_tex"); uniform_grad_tex = glGetUniformLocation(motion_search_program, "grad_tex"); uniform_flow_tex = glGetUniformLocation(motion_search_program, "flow_tex"); + uniform_patch_size = glGetUniformLocation(motion_search_program, "patch_size"); + uniform_num_iterations = glGetUniformLocation(motion_search_program, "num_iterations"); } void MotionSearch::exec(GLuint tex_view, GLuint grad_tex, GLuint flow_tex, GLuint flow_out_tex, int level_width, int level_height, int prev_level_width, int prev_level_height, int width_patches, int height_patches, int num_layers) @@ -351,6 +354,8 @@ void MotionSearch::exec(GLuint tex_view, GLuint grad_tex, GLuint flow_tex, GLuin glProgramUniform2f(motion_search_program, uniform_inv_image_size, 1.0f / level_width, 1.0f / level_height); glProgramUniform2f(motion_search_program, uniform_inv_prev_level_size, 1.0f / prev_level_width, 1.0f / prev_level_height); glProgramUniform2f(motion_search_program, uniform_out_flow_size, width_patches, height_patches); + glProgramUniform1ui(motion_search_program, uniform_patch_size, op.patch_size_pixels); + glProgramUniform1ui(motion_search_program, uniform_num_iterations, op.search_iterations); glViewport(0, 0, width_patches, height_patches); fbos.render_to(flow_out_tex); @@ -609,7 +614,7 @@ void ResizeFlow::exec(GLuint flow_tex, GLuint out_tex, int input_width, int inpu } DISComputeFlow::DISComputeFlow(int width, int height, const OperatingPoint &op) - : width(width), height(height), op(op), densify(op) + : width(width), height(height), op(op), motion_search(op), densify(op) { // Make some samplers. glCreateSamplers(1, &nearest_sampler); diff --git a/flow.h b/flow.h index 0a6ea20..1cf0b1e 100644 --- a/flow.h +++ b/flow.h @@ -18,8 +18,8 @@ class ScopedTimer; struct OperatingPoint { unsigned coarsest_level; // TODO: Adjust dynamically based on the resolution? unsigned finest_level; - unsigned search_iterations; // TODO: Not implemented yet! Halved from the paper. - unsigned patch_size_pixels; // TODO: Not implemented in the shader yet! + unsigned search_iterations; // Halved from the paper. + unsigned patch_size_pixels; float patch_overlap_ratio; bool variational_refinement; // TODO: Actually disabling this is not implemented yet! @@ -178,10 +178,11 @@ private: // Motion search to find the initial flow. See motion_search.frag for documentation. class MotionSearch { public: - MotionSearch(); + MotionSearch(const OperatingPoint &op); void exec(GLuint tex_view, GLuint grad_tex, GLuint flow_tex, GLuint flow_out_tex, int level_width, int level_height, int prev_level_width, int prev_level_height, int width_patches, int height_patches, int num_layers); private: + const OperatingPoint op; PersistentFBOSet<1> fbos; GLuint motion_vs_obj; @@ -190,6 +191,7 @@ private: GLuint uniform_inv_image_size, uniform_inv_prev_level_size, uniform_out_flow_size; GLuint uniform_image_tex, uniform_grad_tex, uniform_flow_tex; + GLuint uniform_patch_size, uniform_num_iterations; }; // Do “densification”, ie., upsampling of the flow patches to the flow field diff --git a/motion_search.frag b/motion_search.frag index 29417f9..eb4f7c7 100644 --- a/motion_search.frag +++ b/motion_search.frag @@ -35,9 +35,6 @@ be ideal. */ -const uint patch_size = 12; -const uint num_iterations = 8; - in vec3 flow_tc; in vec2 patch_center; flat in int ref_layer, search_layer; @@ -46,6 +43,8 @@ out vec3 out_flow; uniform sampler2DArray flow_tex, image_tex; uniform usampler2DArray grad_tex; // Also contains the corresponding reference image. uniform vec2 inv_image_size, inv_prev_level_size; +uniform uint patch_size; +uniform uint num_iterations; vec3 unpack_gradients(uint v) { -- 2.39.2