I am finding a need for a more specialized analyze function for a TOP. I would like to basically get an average of my image, but I’d like to throw away pixels from the average based on either their alpha, or on values in a corresponding TOP using the same texture coordinates.

I tried to make my own analyze functionality, and clearly there is optimization going on in the analyze TOP because iterating over every pixel of a 512 square and then dividing the total by 512X512 brings my system to its knees. I’ve gone through and removed all division and am just multiplying by fractions and trying not to do anything too intensive within the iteration but i imagine there must be some kind of buffer optimization that allows the Analyze TOP to perform as it does that is not available in the GLSL TOP…

I am putting a 1x1 constant into the first input and the 512x512 top to be analyzed in the second. I haven’t even gotten to adding in the selective averaging part yet, just trying to recreate the analyze TOP functionality first. Here is the code as I have it now:

```
uniform vec2 uRes;
layout(location = 0) out vec4 fragColor;
// constants for 1/512, previously was using uTD2DInfos[1].res.x and y
// using constants instead of the buildt in uniforms seems to make no difference
const float rx = float(0.00195313);
const float ry = float(0.00195313);
void main() {
vec4 colAvg = vec4(0.);
vec2 nUV = vec2(0.);
for (int i = 0; i < int(uRes.x); i++){
nUV.s = rx * i;
for (int j = 0; j < int(uRes.y); j++){
nUV.t = ry * j;
colAvg += texture(sTD2DInputs[1], nUV);
}
}
colAvg *= (rx * ry);
fragColor = colAvg;
}
```

Does anyone have any thoughts on this? I figure Malcolm knows this best, but perhaps others have looked into something of this sort as well.

Cheers

P