]> git.sesse.net Git - nageru/blob - densify.frag
Do patch normalization in densification.
[nageru] / densify.frag
1 #version 450 core
2
3 in vec2 image_pos;
4 flat in vec2 flow_du;
5 flat in float mean_diff;
6 out vec3 flow_contribution;
7
8 uniform sampler2D image0_tex, image1_tex;
9
10 void main()
11 {
12         // Equation (3) from the paper. We're using additive blending, so the
13         // sum will happen automatically for us, and normalization happens on
14         // next read.
15         //
16         // Note that equation (2) says 1 for the minimum error, but the code says 2.0.
17         // And it says L2 norm, but really, the code does absolute value even for
18         // L2 error norm (it uses a square root formula for L1 norm).
19         float diff = texture(image0_tex, image_pos).x - texture(image1_tex, image_pos + flow_du).x;
20         diff -= mean_diff;
21         float weight = 1.0 / max(abs(diff), 2.0 / 255.0);
22         flow_contribution = vec3(flow_du.x * weight, flow_du.y * weight, weight);
23 }