+ // Reject if we moved too far. Note that the paper says “too far” is the
+ // patch size, but the DIS code uses half of a patch size. The latter seems
+ // to give much better overall results.
+ //
+ // 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).
+ vec2 patch_center = (base * image_size - 0.5f) + patch_size * 0.5f + u;
+ if (length(u - initial_u) > (patch_size * 0.5f) ||
+ patch_center.x < -(patch_size * 0.5f) ||
+ image_size.x - patch_center.x < -(patch_size * 0.5f) ||
+ patch_center.y < -(patch_size * 0.5f) ||
+ image_size.y - patch_center.y < -(patch_size * 0.5f)) {