X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=motion_search.frag;h=e31a673484be9479f71a7428feec4348604bbf5d;hb=bcdff7b1a183d7ff138a920997182d00f2decf0e;hp=ef860b815d9d33624d50d7ccfb23b0dfff054453;hpb=829dce6fdc27782617c7a8fb0fc0177e2d232067;p=nageru diff --git a/motion_search.frag b/motion_search.frag index ef860b8..e31a673 100644 --- a/motion_search.frag +++ b/motion_search.frag @@ -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) {