]> git.sesse.net Git - nageru/blob - densify.vert
Small syntactic tweak.
[nageru] / densify.vert
1 #version 450 core
2
3 in vec2 position;
4 out vec2 image_pos;
5 flat out vec2 flow_du;
6 flat out float mean_diff;
7
8 uniform int width_patches;
9 uniform vec2 patch_size;  // In 0..1 coordinates.
10 uniform vec2 patch_spacing;  // In 0..1 coordinates.
11 uniform sampler2D flow_tex;
12
13 void main()
14 {
15         int patch_x = gl_InstanceID % width_patches;
16         int patch_y = gl_InstanceID / width_patches;
17
18         // Increase the patch size a bit; since patch spacing is not necessarily
19         // an integer number of pixels, and we don't use conservative rasterization,
20         // we could be missing the outer edges of the patch. And it seemingly helps
21         // a little bit in general to have some more candidates as well -- although
22         // this is measured without variational refinement, so it might be moot
23         // with it.
24         //
25         // This maps [0.0,1.0] to [-0.25,1.25], ie. extends the patch by 25% in
26         // all directions.
27         vec2 grown_pos = (position * 1.5) - 0.25;
28
29         image_pos = patch_spacing * ivec2(patch_x, patch_y) + patch_size * grown_pos;
30
31         // Find the flow value for this patch, and send it on to the fragment shader.
32         vec3 flow_du_and_mean_diff = texelFetch(flow_tex, ivec2(patch_x, patch_y), 0).xyz;
33         flow_du = flow_du_and_mean_diff.xy;
34         mean_diff = flow_du_and_mean_diff.z;
35
36         // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
37         //
38         //   2.000  0.000  0.000 -1.000
39         //   0.000  2.000  0.000 -1.000
40         //   0.000  0.000 -2.000 -1.000
41         //   0.000  0.000  0.000  1.000
42         gl_Position = vec4(2.0 * image_pos.x - 1.0, 2.0 * image_pos.y - 1.0, -1.0, 1.0);
43 }