]> git.sesse.net Git - nageru/commitdiff
Reject motion search if we go beyond the image boundary; seems to fix most of the...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 5 Jul 2018 22:45:53 +0000 (00:45 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 5 Jul 2018 22:45:53 +0000 (00:45 +0200)
motion_search.frag

index a417834ff3fc72c5121fb144c3a373df6d71da3b..262dca53a9bc8aaae7abb30e83b85fdd90c01173 100644 (file)
@@ -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;
        }