]> git.sesse.net Git - nageru/blob - densify.vert
Add the densification step, in theory now providing us with flow. But still too buggy...
[nageru] / densify.vert
1 #version 450 core
2
3 in vec2 position;
4 out vec2 image_pos;
5 flat out vec2 flow_du;
6
7 uniform int width_patches;
8 uniform vec2 patch_size;  // In 0..1 coordinates.
9 uniform vec2 patch_spacing;  // In 0..1 coordinates.
10 uniform sampler2D flow_tex;
11
12 void main()
13 {
14         int patch_x = gl_InstanceID % width_patches;
15         int patch_y = gl_InstanceID / width_patches;
16
17         // TODO: Lock the bottom left of the patch to an integer number of pixels?
18
19         image_pos = patch_spacing * ivec2(patch_x, patch_y) + patch_size * position;
20
21         // Find the flow value for this patch, and send it on to the fragment shader.
22         vec2 patch_center = patch_spacing * ivec2(patch_x, patch_y) + patch_size * vec2(0.5, 0.5);
23         flow_du = texture(flow_tex, patch_center).xy;
24
25         // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
26         //
27         //   2.000  0.000  0.000 -1.000
28         //   0.000  2.000  0.000 -1.000
29         //   0.000  0.000 -2.000 -1.000
30         //   0.000  0.000  0.000  1.000
31         gl_Position = vec4(2.0 * image_pos.x - 1.0, 2.0 * image_pos.y - 1.0, -1.0, 1.0);
32 }