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