6 uniform sampler2D diff_flow_tex, smoothness_x_tex, smoothness_y_tex;
7 uniform usampler2D equation_tex;
11 uvec4 equation = texture(equation_tex, tc);
12 float inv_A11 = uintBitsToFloat(equation.x);
13 float A12 = uintBitsToFloat(equation.y);
14 float inv_A22 = uintBitsToFloat(equation.z);
15 vec2 b = unpackHalf2x16(equation.w);
17 // Subtract the missing terms from the right-hand side
18 // (it couldn't be done earlier, because we didn't know
19 // the values of the neighboring pixels; they change for
20 // each SOR iteration).
21 // TODO: Multiply by some gamma.
22 float smooth_l = textureOffset(smoothness_x_tex, tc, ivec2(-1, 0)).x;
23 float smooth_r = texture(smoothness_x_tex, tc).x;
24 float smooth_d = textureOffset(smoothness_y_tex, tc, ivec2( 0, -1)).x;
25 float smooth_u = texture(smoothness_y_tex, tc).x;
26 b -= smooth_l * textureOffset(diff_flow_tex, tc, ivec2(-1, 0)).xy;
27 b -= smooth_r * textureOffset(diff_flow_tex, tc, ivec2( 1, 0)).xy;
28 b -= smooth_d * textureOffset(diff_flow_tex, tc, ivec2( 0, -1)).xy;
29 b -= smooth_u * textureOffset(diff_flow_tex, tc, ivec2( 0, 1)).xy;
31 const float omega = 1.6;
32 diff_flow = texture(diff_flow_tex, tc).xy;
34 // From https://en.wikipedia.org/wiki/Successive_over-relaxation.
35 float sigma_u = A12 * diff_flow.y;
36 diff_flow.x += omega * ((b.x - sigma_u) * inv_A11 - diff_flow.x);
37 float sigma_v = A12 * diff_flow.x;
38 diff_flow.y += omega * ((b.y - sigma_v) * inv_A22 - diff_flow.y);