X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=splat.vert;h=08462315264261ac9b3d230ca4c91d187f20394c;hb=3795723be95f2fe82f3c8b8b45b1a905b2c811fd;hp=4a1ecd7496cc870749f87f08ce8f3dbc52463f6b;hpb=a19f7e1c7efbea4b9fbf631156e3de51d62ac477;p=nageru diff --git a/splat.vert b/splat.vert index 4a1ecd7..0846231 100644 --- a/splat.vert +++ b/splat.vert @@ -1,25 +1,32 @@ #version 450 core -in vec2 position; +layout(location=0) in vec2 position; 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 { @@ -27,7 +34,7 @@ void main() } 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;