]> git.sesse.net Git - nageru/blobdiff - motion_search.frag
Implement coarse-to-fine. Still too buggy.
[nageru] / motion_search.frag
index ef860b815d9d33624d50d7ccfb23b0dfff054453..e31a673484be9479f71a7428feec4348604bbf5d 100644 (file)
@@ -87,8 +87,16 @@ void main()
 
        mat2 H_inv = inverse(H);
 
-       // Fetch the initial guess for the flow.
-       vec2 initial_u = texture(flow_tex, flow_tc).xy;
+       // Fetch the initial guess for the flow. (We need the normalization step
+       // because densification works by accumulating; see the comments on the
+       // Densify class.)
+       vec3 prev_flow = texture(flow_tex, flow_tc).xyz;
+       vec2 initial_u;
+       if (prev_flow.z < 1e-3) {
+               initial_u = vec2(0.0, 0.0);
+       } else {
+               initial_u = prev_flow.xy / prev_flow.z;
+       }
        vec2 u = initial_u;
 
        for (uint i = 0; i < num_iterations; ++i) {