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);
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)
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);
}
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);
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!
// 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;
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
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;
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)
{