X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=densify.vert;h=181c7f32b72203ed16244253097e0223fe4493c2;hb=3795723be95f2fe82f3c8b8b45b1a905b2c811fd;hp=b7f78d74edad1d6ca30e7304f221e9018c5cfeba;hpb=200cfe3a0b9633d785a4ca5fb51147f937278448;p=nageru diff --git a/densify.vert b/densify.vert index b7f78d7..181c7f3 100644 --- a/densify.vert +++ b/densify.vert @@ -1,25 +1,26 @@ #version 450 core +#extension GL_ARB_shader_viewport_layer_array : require -in vec2 position; +layout(location=0) in vec2 position; out vec2 image_pos; flat out vec2 flow_du; flat out float mean_diff; +flat out int image0_layer, image1_layer; -uniform int width_patches; uniform vec2 patch_size; // In 0..1 coordinates. -uniform vec2 patch_spacing; // In 0..1 coordinates. -uniform sampler2D flow_tex; -uniform vec2 flow_size; +uniform sampler2DArray flow_tex; void main() { - int patch_x = gl_InstanceID % width_patches; - int patch_y = gl_InstanceID / width_patches; + int num_patches = textureSize(flow_tex, 0).x * textureSize(flow_tex, 0).y; + int patch_layer = gl_InstanceID / num_patches; + int patch_x = gl_InstanceID % textureSize(flow_tex, 0).x; + int patch_y = (gl_InstanceID % num_patches) / textureSize(flow_tex, 0).x; // Convert the patch index to being the full 0..1 range, to match where // the motion search puts the patches. We don't bother with the locking // to texel centers, though. - vec2 patch_center = ivec2(patch_x, patch_y) / (flow_size - 1.0); + vec2 patch_center = ivec2(patch_x, patch_y) / (textureSize(flow_tex, 0).xy - 1.0); // Increase the patch size a bit; since patch spacing is not necessarily // an integer number of pixels, and we don't use conservative rasterization, @@ -35,7 +36,7 @@ void main() image_pos = patch_center + patch_size * (grown_pos - 0.5f); // Find the flow value for this patch, and send it on to the fragment shader. - vec3 flow_du_and_mean_diff = texelFetch(flow_tex, ivec2(patch_x, patch_y), 0).xyz; + vec3 flow_du_and_mean_diff = texelFetch(flow_tex, ivec3(patch_x, patch_y, patch_layer), 0).xyz; flow_du = flow_du_and_mean_diff.xy; mean_diff = flow_du_and_mean_diff.z; @@ -46,4 +47,9 @@ void main() // 0.000 0.000 -2.000 -1.000 // 0.000 0.000 0.000 1.000 gl_Position = vec4(2.0 * image_pos.x - 1.0, 2.0 * image_pos.y - 1.0, -1.0, 1.0); + gl_Layer = patch_layer; + + // Forward flow (0) goes from 0 to 1. Backward flow (1) goes from 1 to 0. + image0_layer = patch_layer; + image1_layer = 1 - patch_layer; }