uniform sampler2D beta_0_tex;
uniform sampler2D smoothness_x_tex, smoothness_y_tex;
+// Relative weighting of intensity term.
+uniform float delta;
+
+// Relative weighting of gradient term.
+uniform float gamma;
+
// TODO: Consider a specialized version for the case where we know that du = dv = 0,
// since we run so few iterations.
//
// TODO: Evaluate squaring β_0.
// FIXME: Should the penalizer be adjusted for 0..1 intensity range instead of 0..255?
- // TODO: Multiply by some alpha.
float beta_0 = texture(beta_0_tex, tc).x;
- float k1 = beta_0 * inversesqrt(beta_0 * (I_x * du + I_y * dv + I_t) * (I_x * du + I_y * dv + I_t) + 1e-6);
+ float k1 = delta * beta_0 * inversesqrt(beta_0 * (I_x * du + I_y * dv + I_t) * (I_x * du + I_y * dv + I_t) + 1e-6);
float A11 = k1 * I_x * I_x;
float A12 = k1 * I_x * I_y;
float A22 = k1 * I_y * I_y;
// (see derivatives.frag).
float beta_x = 1.0 / (I_xx * I_xx + I_xy * I_xy + 1e-7);
float beta_y = 1.0 / (I_xy * I_xy + I_yy * I_yy + 1e-7);
- float k2 = inversesqrt(
+ float k2 = gamma * inversesqrt(
beta_x * (I_xx * du + I_xy * dv + I_xt) * (I_xx * du + I_xy * dv + I_xt) +
beta_y * (I_xy * du + I_yy * dv + I_yt) * (I_xy * du + I_yy * dv + I_yt) +
1e-6);
b2 -= k_x * I_xy * I_xt + k_y * I_yy * I_yt;
// E_S term, sans the part on the right-hand side that deals with
- // the neighboring pixels.
- // TODO: Multiply by some gamma.
+ // the neighboring pixels. The gamma is multiplied in in smoothness.frag.
float smooth_l = textureOffset(smoothness_x_tex, tc, ivec2(-1, 0)).x;
float smooth_r = texture(smoothness_x_tex, tc).x;
float smooth_d = textureOffset(smoothness_y_tex, tc, ivec2( 0, -1)).x;
constexpr unsigned finest_level = 1;
constexpr unsigned patch_size_pixels = 12;
+// Weighting constants for the different parts of the variational refinement.
+// These don't correspond 1:1 to the values given in the DIS paper,
+// since we have different normalizations and ranges in some cases.
+float vr_gamma = 10.0f, vr_delta = 5.0f, vr_alpha = 10.0f;
+
// Some global OpenGL objects.
GLuint nearest_sampler, linear_sampler, smoothness_sampler;
GLuint vertex_vbo;
GLuint smoothness_vao;
GLuint uniform_flow_tex, uniform_diff_flow_tex;
+ GLuint uniform_alpha;
};
ComputeSmoothness::ComputeSmoothness()
uniform_flow_tex = glGetUniformLocation(smoothness_program, "flow_tex");
uniform_diff_flow_tex = glGetUniformLocation(smoothness_program, "diff_flow_tex");
+ uniform_alpha = glGetUniformLocation(smoothness_program, "alpha");
}
void ComputeSmoothness::exec(GLuint flow_tex, GLuint diff_flow_tex, GLuint smoothness_x_tex, GLuint smoothness_y_tex, int level_width, int level_height)
bind_sampler(smoothness_program, uniform_flow_tex, 0, flow_tex, nearest_sampler);
bind_sampler(smoothness_program, uniform_diff_flow_tex, 1, diff_flow_tex, nearest_sampler);
+ glProgramUniform1f(smoothness_program, uniform_alpha, vr_alpha);
GLuint smoothness_fbo; // TODO: cleanup
glCreateFramebuffers(1, &smoothness_fbo);
GLuint uniform_diff_flow_tex, uniform_base_flow_tex;
GLuint uniform_beta_0_tex;
GLuint uniform_smoothness_x_tex, uniform_smoothness_y_tex;
+ GLuint uniform_gamma, uniform_delta;
};
SetupEquations::SetupEquations()
uniform_beta_0_tex = glGetUniformLocation(equations_program, "beta_0_tex");
uniform_smoothness_x_tex = glGetUniformLocation(equations_program, "smoothness_x_tex");
uniform_smoothness_y_tex = glGetUniformLocation(equations_program, "smoothness_y_tex");
+ uniform_gamma = glGetUniformLocation(equations_program, "gamma");
+ uniform_delta = glGetUniformLocation(equations_program, "delta");
}
void SetupEquations::exec(GLuint I_x_y_tex, GLuint I_t_tex, GLuint diff_flow_tex, GLuint base_flow_tex, GLuint beta_0_tex, GLuint smoothness_x_tex, GLuint smoothness_y_tex, GLuint equation_tex, int level_width, int level_height)
bind_sampler(equations_program, uniform_beta_0_tex, 4, beta_0_tex, nearest_sampler);
bind_sampler(equations_program, uniform_smoothness_x_tex, 5, smoothness_x_tex, smoothness_sampler);
bind_sampler(equations_program, uniform_smoothness_y_tex, 6, smoothness_y_tex, smoothness_sampler);
+ glProgramUniform1f(equations_program, uniform_delta, vr_delta);
+ glProgramUniform1f(equations_program, uniform_gamma, vr_gamma);
GLuint equations_fbo; // TODO: cleanup
glCreateFramebuffers(1, &equations_fbo);
uniform sampler2D flow_tex, diff_flow_tex;
+// Relative weighting of smoothness term.
+uniform float alpha;
+
// This must be a macro, since the offset needs to be a constant expression.
#define get_flow(x_offs, y_offs) \
(textureOffset(flow_tex, tc, ivec2((x_offs), (y_offs))).xy + \
float diffusivity(float u_x, float u_y, float v_x, float v_y)
{
- return inversesqrt(u_x * u_x + u_y * u_y + v_x * v_x + v_y * v_y + eps_sq);
+ return alpha * inversesqrt(u_x * u_x + u_y * u_y + v_x * v_x + v_y * v_y + eps_sq);
}
void main()