]> git.sesse.net Git - nageru/blob - densify.vert
Correct the sampling of the flow in the densification vertex shader.
[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         flow_du = texelFetch(flow_tex, ivec2(patch_x, patch_y), 0).xy;
23
24         // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
25         //
26         //   2.000  0.000  0.000 -1.000
27         //   0.000  2.000  0.000 -1.000
28         //   0.000  0.000 -2.000 -1.000
29         //   0.000  0.000  0.000  1.000
30         gl_Position = vec4(2.0 * image_pos.x - 1.0, 2.0 * image_pos.y - 1.0, -1.0, 1.0);
31 }