]> git.sesse.net Git - nageru/blob - hole_blend.frag
Allow symlinked frame files. Useful for testing.
[nageru] / hole_blend.frag
1 #version 450 core
2
3 in vec2 tc;
4 out vec2 out_flow;
5
6 uniform sampler2D left_tex, right_tex, up_tex, down_tex;
7
8 void main()
9 {
10         // Some of these may contain “junk”, in the sense that they were
11         // not written in the given pass, if they came from an edge.
12         // Most of the time, this is benign, since it means we'll get
13         // the previous value (left/right/up) again. However, if it were
14         // bogus on the very first pass, we need to exclude it.
15         // Thus the test for 100.0f (invalid flows are initialized to 1000,
16         // all valid ones are less than 1).
17         vec2 left = texture(left_tex, tc).xy;
18         vec2 right = texture(right_tex, tc).xy;
19         vec2 up = texture(up_tex, tc).xy;
20         vec2 down = texture(down_tex, tc).xy;
21
22         vec2 sum = vec2(0.0f);
23         float num = 0.0f;
24         if (left.x < 100.0f) {
25                 sum = left;
26                 num = 1.0f;
27         }
28         if (right.x < 100.0f) {
29                 sum += right;
30                 num += 1.0f;
31         }
32         if (up.x < 100.0f) {
33                 sum += up;
34                 num += 1.0f;
35         }
36         if (down.x < 100.0f) {
37                 sum += down;
38                 num += 1.0f;
39         }
40
41         // If _all_ of them were 0, this would mean the entire row _and_ column
42         // would be devoid of flow. If so, the zero flow is fine for our purposes.
43         if (num == 0.0f) {
44                 out_flow = vec2(0.0f);
45         } else {
46                 out_flow = sum / num;
47         }
48 }