]> git.sesse.net Git - nageru/blobdiff - motion_search.frag
Fix the texel centers for motion search. Helps a whole lot.
[nageru] / motion_search.frag
index a417834ff3fc72c5121fb144c3a373df6d71da3b..927ecc5634ef10488925bd4f5695cff2f02a614e 100644 (file)
@@ -49,7 +49,7 @@ void main()
 {
        // Lock patch_bottom_left_texel to an integer, so that we never get
        // any bilinear artifacts for the gradient.
-       vec2 base = round(patch_bottom_left_texel * image_size)
+       vec2 base = (round(patch_bottom_left_texel * image_size - vec2(0.5, 0.5)) + vec2(0.5, 0.5))
                * inv_image_size;
 
        // First, precompute the pseudo-Hessian for the template patch.
@@ -137,8 +137,14 @@ void main()
                u -= (H_inv * du) * inv_image_size;
        }
 
-       // Reject if we moved too far.
-       if (length((u - initial_u) * image_size) > patch_size) {
+       // Reject if we moved too far. Also reject if the patch goes out-of-bounds
+       // (the paper does not mention this, but the code does, and it seems to be
+       // critical to avoid really bad behavior at the edges).
+       if ((length((u - initial_u) * image_size) > patch_size) ||
+            u.x * image_size.x < -(patch_size * 0.5f) ||
+            (1.0 - u.x) * image_size.x < -(patch_size * 0.5f) ||
+            u.y * image_size.y < -(patch_size * 0.5f) ||
+            (1.0 - u.y) * image_size.y < -(patch_size * 0.5f)) {
                u = initial_u;
        }