What I want is (basically) the same as "sum all the pixels of an image". However it seems that this can not be achieved by shader (I think that is why I'm asking ;-)):
I want to pass the image + a parameter "treeshold" and check for each pixel of the image if that pixel(R,G,B) IS IN the treshold (R+/-,G+/-,B+/-).
The IS IN operation is ok, nothing complicated.
The thing is I need the SUM of all pixel (the count) that accomplished this in the image.
The idea of using shader is minimize this calculation because in CPU is very expensive (besides, we have to repeat this caculation several times).
One Idea is to put as an output a vector (0,0,0) if the pixel not achieves and a (1,0,0) if the pixel achieves, then in software summ all the first channel.
Even when this is faster that using only software, we are still traveling an NXM image for the sum.
Another way (not so accuracy) is to do this for (for example) 10 neighbor pixels (and omitting the calculation if "im a neighbor"). Then we only will sum array each 10 position. We make 10 times faster, however, we still have O(N*M).
Also, i believe we can use something like this, but i quite do not understand how to use this in pixel bender Efficient pixel shader sum of all pixels
Thanks in advance for any other solution.