3 layout(location=0) in vec2 position;
5 flat out vec2 flow, I_0_check_offset, I_1_check_offset;
7 uniform vec2 splat_size; // In 0..1 coordinates.
8 uniform vec2 inv_flow_size;
10 uniform sampler2DArray flow_tex; // 0 = forward flow, 1 = backward flow.
14 int instance = gl_InstanceID;
15 int num_pixels_per_layer = textureSize(flow_tex, 0).x * textureSize(flow_tex, 0).y;
17 if (instance >= num_pixels_per_layer) {
18 instance -= num_pixels_per_layer;
23 int x = instance % textureSize(flow_tex, 0).x;
24 int y = instance / textureSize(flow_tex, 0).x;
26 // Find out where to splat this to.
27 vec2 full_flow = texelFetch(flow_tex, ivec3(x, y, src_layer), 0).xy;
29 if (src_layer == 1) { // Reverse flow.
30 full_flow = -full_flow;
31 splat_alpha = 1.0f - alpha;
35 full_flow *= inv_flow_size;
37 vec2 patch_center = (ivec2(x, y) + 0.5) * inv_flow_size + full_flow * splat_alpha;
38 image_pos = patch_center + splat_size * (position - 0.5);
41 I_0_check_offset = full_flow * -alpha;
42 I_1_check_offset = full_flow * (1.0f - alpha);
44 // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
46 // 2.000 0.000 0.000 -1.000
47 // 0.000 2.000 0.000 -1.000
48 // 0.000 0.000 -2.000 -1.000
49 // 0.000 0.000 0.000 1.000
50 gl_Position = vec4(2.0 * image_pos.x - 1.0, 2.0 * image_pos.y - 1.0, -1.0, 1.0);