]> git.sesse.net Git - nageru/blob - futatabi/blend.frag
Log a warning when we kill a client that is not keeping up.
[nageru] / futatabi / blend.frag
1 #version 450 core
2
3 in vec3 tc;
4
5 #ifdef SPLIT_YCBCR_OUTPUT
6 out float Y;
7 out vec2 CbCr;
8 #else
9 out vec4 rgba;
10 #endif
11
12 uniform sampler2DArray image_tex;
13 uniform sampler2D flow_tex;
14 uniform float alpha;
15
16 void main()
17 {
18         vec2 flow = texture(flow_tex, tc.xy).xy;
19         vec4 I_0 = texture(image_tex, vec3(tc.xy - alpha * flow, 0));
20         vec4 I_1 = texture(image_tex, vec3(tc.xy + (1.0f - alpha) * flow, 1));
21
22         // Occlusion reasoning:
23
24         vec2 size = textureSize(image_tex, 0).xy;
25
26         // Follow the flow back to the initial point (where we sample I_0 from), then forward again.
27         // See how well we match the point we started at, which is out flow consistency.
28         float d0 = alpha * length(size * (texture(flow_tex, vec2(tc.xy - alpha * flow)).xy - flow));
29
30         // Same for d1.
31         float d1 = (1.0f - alpha) * length(size * (texture(flow_tex, vec2(tc.xy + (1.0f - alpha) * flow)).xy - flow));
32
33         vec4 result;
34         if (max(d0, d1) < 3.0f) {  // Arbitrary constant, not all that tuned. The UW paper says 1.0 is fine for ground truth.
35                 // Both are visible, so blend.
36                 result = I_0 + alpha * (I_1 - I_0);
37         } else if (d0 < d1) {
38                 result = I_0;
39         } else {
40                 result = I_1;
41         }
42
43 #ifdef SPLIT_YCBCR_OUTPUT
44         Y = result.r;
45         CbCr = result.gb;
46 #else
47         rgba = result;
48 #endif
49 }