out vec2 image_pos;
flat out vec2 flow, I_0_check_offset, I_1_check_offset;
-uniform bool invert_flow;
uniform vec2 splat_size; // In 0..1 coordinates.
uniform vec2 inv_flow_size;
uniform float alpha;
-uniform sampler2D flow_tex;
+uniform sampler2DArray flow_tex; // 0 = forward flow, 1 = backward flow.
void main()
{
- int x = gl_InstanceID % textureSize(flow_tex, 0).x;
- int y = gl_InstanceID / textureSize(flow_tex, 0).x;
+ int instance = gl_InstanceID;
+ int num_pixels_per_layer = textureSize(flow_tex, 0).x * textureSize(flow_tex, 0).y;
+ int src_layer;
+ if (instance >= num_pixels_per_layer) {
+ instance -= num_pixels_per_layer;
+ src_layer = 1;
+ } else {
+ src_layer = 0;
+ }
+ int x = instance % textureSize(flow_tex, 0).x;
+ int y = instance / textureSize(flow_tex, 0).x;
// Find out where to splat this to.
- // TODO: See if we can move some of these calculations into uniforms.
- vec2 full_flow = texelFetch(flow_tex, ivec2(x, y), 0).xy;
+ vec2 full_flow = texelFetch(flow_tex, ivec3(x, y, src_layer), 0).xy;
float splat_alpha;
- if (invert_flow) {
+ if (src_layer == 1) { // Reverse flow.
full_flow = -full_flow;
splat_alpha = 1.0f - alpha;
} else {
}
full_flow *= inv_flow_size;
- vec2 patch_center = (ivec2(x, y) + 0.5) / textureSize(flow_tex, 0) + full_flow * splat_alpha;
+ vec2 patch_center = (ivec2(x, y) + 0.5) * inv_flow_size + full_flow * splat_alpha;
image_pos = patch_center + splat_size * (position - 0.5);
flow = full_flow;