]> git.sesse.net Git - nageru/blob - densify.vert
In densification, grow the patch a bit. Seemingly helps a lot on the EPE.
[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         // Increase the patch size a bit; since patch spacing is not necessarily
18         // an integer number of pixels, and we don't use conservative rasterization,
19         // we could be missing the outer edges of the patch. And it seemingly helps
20         // a little bit in general to have some more candidates as well -- although
21         // this is measured without variational refinement, so it might be moot
22         // with it.
23         //
24         // Tihs maps [0.0,1.0] to [-0.25 to 1.25), ie. extends the patch by 25% in
25         // all directions.
26         vec2 grown_pos = (position * 1.5) - vec2(0.25, 0.25);
27
28         image_pos = patch_spacing * ivec2(patch_x, patch_y) + patch_size * grown_pos;
29
30         // Find the flow value for this patch, and send it on to the fragment shader.
31         flow_du = texelFetch(flow_tex, ivec2(patch_x, patch_y), 0).xy;
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 * image_pos.x - 1.0, 2.0 * image_pos.y - 1.0, -1.0, 1.0);
40 }