]> git.sesse.net Git - nageru/blob - futatabi/densify.vert
Log a warning when we kill a client that is not keeping up.
[nageru] / futatabi / densify.vert
1 #version 450 core
2 #extension GL_ARB_shader_viewport_layer_array : require
3
4 layout(location=0) in vec2 position;
5 out vec2 image_pos;
6 flat out vec2 flow_du;
7 flat out float mean_diff;
8 flat out int image0_layer, image1_layer;
9
10 uniform vec2 patch_size;  // In 0..1 coordinates.
11 uniform sampler2DArray flow_tex;
12
13 void main()
14 {
15         int num_patches = textureSize(flow_tex, 0).x * textureSize(flow_tex, 0).y;
16         int patch_layer = gl_InstanceID / num_patches;
17         int patch_x = gl_InstanceID % textureSize(flow_tex, 0).x;
18         int patch_y = (gl_InstanceID % num_patches) / textureSize(flow_tex, 0).x;
19
20         // Convert the patch index to being the full 0..1 range, to match where
21         // the motion search puts the patches. We don't bother with the locking
22         // to texel centers, though.
23         vec2 patch_center = ivec2(patch_x, patch_y) / (textureSize(flow_tex, 0).xy - 1.0);
24
25         // Increase the patch size a bit; since patch spacing is not necessarily
26         // an integer number of pixels, and we don't use conservative rasterization,
27         // we could be missing the outer edges of the patch. And it seemingly helps
28         // a little bit in general to have some more candidates as well -- although
29         // this is measured without variational refinement, so it might be moot
30         // with it.
31         //
32         // This maps [0.0,1.0] to [-0.25,1.25], ie. extends the patch by 25% in
33         // all directions.
34         vec2 grown_pos = (position * 1.5) - 0.25;
35
36         image_pos = patch_center + patch_size * (grown_pos - 0.5f);
37
38         // Find the flow value for this patch, and send it on to the fragment shader.
39         vec3 flow_du_and_mean_diff = texelFetch(flow_tex, ivec3(patch_x, patch_y, patch_layer), 0).xyz;
40         flow_du = flow_du_and_mean_diff.xy;
41         mean_diff = flow_du_and_mean_diff.z;
42
43         // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
44         //
45         //   2.000  0.000  0.000 -1.000
46         //   0.000  2.000  0.000 -1.000
47         //   0.000  0.000 -2.000 -1.000
48         //   0.000  0.000  0.000  1.000
49         gl_Position = vec4(2.0 * image_pos.x - 1.0, 2.0 * image_pos.y - 1.0, -1.0, 1.0);
50         gl_Layer = patch_layer;
51
52         // Forward flow (0) goes from 0 to 1. Backward flow (1) goes from 1 to 0.
53         image0_layer = patch_layer;
54         image1_layer = 1 - patch_layer;
55 }