]> git.sesse.net Git - nageru/blob - futatabi/motion_search.vert
Log a warning when we kill a client that is not keeping up.
[nageru] / futatabi / motion_search.vert
1 #version 450 core
2 #extension GL_ARB_shader_viewport_layer_array : require
3
4 layout(location=0) in vec2 position;
5 out vec3 flow_tc;
6 out vec2 patch_center;
7 flat out int ref_layer, search_layer;
8
9 uniform sampler2DArray flow_tex;
10 uniform vec2 out_flow_size;
11
12 void main()
13 {
14         // Patch placement: We want the outermost patches to have centers exactly in the
15         // image corners, so that the bottom-left patch has centre (0,0) and the
16         // upper-right patch has center (1,1). The position we get in is _almost_ there;
17         // since the quad's corners are in (0,0) and (1,1), the fragment shader will get
18         // centers in x=0.5/w, x=1.5/w and so on (and similar for y).
19         //
20         // In other words, find some f(x) = ax + b so that
21         //
22         //   a 0.5 / w + b = 0
23         //   a (1.0 - 0.5 / w) + b = 1
24         //
25         // which gives
26         //
27         //   a = 1 / (w - 1)
28         //   b = w / 2 (w - 1)
29         vec2 a = out_flow_size / (out_flow_size - 1);
30         vec2 b = -1.0 / (2 * (out_flow_size - 1.0));
31         patch_center = a * position + b;
32
33         // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
34         //
35         //   2.000  0.000  0.000 -1.000
36         //   0.000  2.000  0.000 -1.000
37         //   0.000  0.000 -2.000 -1.000
38         //   0.000  0.000  0.000  1.000
39         gl_Position = vec4(2.0 * position.x - 1.0, 2.0 * position.y - 1.0, -1.0, 1.0);
40         flow_tc = vec3(position, gl_InstanceID);
41
42         gl_Layer = gl_InstanceID;
43
44         // Forward flow (0) goes from 0 to 1. Backward flow (1) goes from 1 to 0.
45         ref_layer = gl_InstanceID;
46         search_layer = 1 - gl_InstanceID;
47 }