I have 15 tubes all with different diameters. Each one will spin according to motion that is detected in optical flow. I need to split the optical flow texture into 15 blocks whose widths correspond to the diameter of each tube. I have a GLSL TOP (set to a resolution of 15x1) that does this, however it is super slow when optical flow is a high resolution (720p+).
uniform float uTotalWidth;
uniform samplerBuffer sWidth;
out vec4 fragColor;
void main()
{
vec4 color = vec4(0.0,0.0,0.0,1.0);
vec2 texRes = uTD2DInfos[0].res.zw;
float thisWidth = texelFetch(sWidth, int(gl_FragCoord.s - 0.5)).r;
thisWidth / uTotalWidth;
thisWidth *= texRes.x;
float prevWidths = 0.0;
for(int i = 0; i < gl_FragCoord.s - 0.5; i++){
prevWidths += texelFetch(sWidth, i).r;
}
prevWidths /= uTotalWidth;
prevWidths *= texRes.x;
for(int x = 0; x < thisWidth; x++){
for(int y = 0; y < texRes.y; y++){
ivec2 sampleOffset = ivec2(x + prevWidths,y);
color.r += texelFetch(sTD2DInputs[0], sampleOffset, 0).r;
}
}
color.r /= (thisWidth * texRes.y);
fragColor = TDOutputSwizzle(color);
}
It’s obvious why it’s slow, it’s sampling every pixel and then adding it all together. So if I put a Fit TOP or Res TOP before it and scale down the resolution, it performs better. What I’m wondering is there a way I can do it without a Fit/Res TOP? Or rather what’s the glsl behind those two TOPs so I can include it in my shader?
irregular_sampling.toe (40.0 KB)