I am using GLSL shaders to compare textures. In one of my alghoritm's steps I want to sum up pixel values (using shaders) or calculate average of them and then read it to CPU. It may look like (shader runs on 1x1 testure, calculations only for R channel, texture2 size 1x500):
uniform sampler2D texture2;
void main()
{
float sumR = 0.0;
float step = 1.f / 500.f;
for(int i = 0; i<500; i++)
{
vec2 pos = gl_TexCoord[0].st;
sumR += (texture2D(texture2, vec2(pos.x, i * step))).r;
}
gl_FragColor.r = sumR;
}
My problem is: how to store such a big number in one pixel which is 32bit (8bit for one channel only)? Or how to store and read float number with good precision in pixel?