]> git.sesse.net Git - nageru/commitdiff
Parametrize patch size and number of iterations.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 23 Aug 2018 22:21:48 +0000 (00:21 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 15 Sep 2018 17:39:49 +0000 (19:39 +0200)
flow.cpp
flow.h
motion_search.frag

index 95bb1547b64b1095559632bd798a5f5fc9c8fe81..16af1558e000fed8c126dccca16b17cf2573a0a4 100644 (file)
--- 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 0a6ea203c31517b9624cb8bb732e7a81136ac93f..1cf0b1e765b78283747fa8c244c366b1829c26e5 100644 (file)
--- 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
index 29417f944d374df466982cfcb75a25cf0e31fdb7..eb4f7c77fe2c6f8cb056a46caeaa89d58f0ee486 100644 (file)
@@ -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)
 {