]> git.sesse.net Git - nageru/blobdiff - densify.vert
Share VAOs between all the passes. Much less code, less rebinding overhead.
[nageru] / densify.vert
index f32b9d4151cbe3a4f587c2a6cf5225be426c7673..50d230f2f4fd46ae82f4adee4c7c7c1c6cf0006a 100644 (file)
@@ -1,19 +1,22 @@
 #version 450 core
 
-in vec2 position;
+layout(location=0) in vec2 position;
 out vec2 image_pos;
 flat out vec2 flow_du;
 flat out float mean_diff;
 
-uniform int width_patches;
 uniform vec2 patch_size;  // In 0..1 coordinates.
-uniform vec2 patch_spacing;  // In 0..1 coordinates.
 uniform sampler2D flow_tex;
 
 void main()
 {
-       int patch_x = gl_InstanceID % width_patches;
-       int patch_y = gl_InstanceID / width_patches;
+       int patch_x = gl_InstanceID % textureSize(flow_tex, 0).x;
+       int patch_y = gl_InstanceID / 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) / (textureSize(flow_tex, 0) - 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,
@@ -22,11 +25,11 @@ void main()
        // this is measured without variational refinement, so it might be moot
        // with it.
        //
-       // Tihs maps [0.0,1.0] to [-0.25 to 1.25), ie. extends the patch by 25% in
+       // This maps [0.0,1.0] to [-0.25,1.25], ie. extends the patch by 25% in
        // all directions.
-       vec2 grown_pos = (position * 1.5) - vec2(0.25, 0.25);
+       vec2 grown_pos = (position * 1.5) - 0.25;
 
-       image_pos = patch_spacing * ivec2(patch_x, patch_y) + patch_size * grown_pos;
+       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;