Average of the pixels

Dear All,

Is it possible to take average of pixels rendered each time.

Any suggestions
RAJESH.R

Sorry, I mean the average of the pixels rendered at location (i,j) of the framebuffer
Thanks

Yes, it is possible, but not easy.
What you need to do is to keep track of how many pixels you have rendered.
And to do that you need to render everything twice to individual textures, once normally but with (GL_ONE,GL_ONE) blending, and the other one to count how many pixels are rendered(same blending as the first one but with the darkest color above pure black you can get).

then you can combine them in a texture and get the average from that.
As i said, it’s possible, but not easy.

You can use the accumulation buffer. Basically you would be creating a motion blur effect. First clear the accumulationg buffer. Then, draw succesive frames adding into the accumulation buffer and keep track of how many frames you’ve drawn. Then readback from the accumulation buffer and divide by the number of frames you’ve drawn. That should give you pixel averages. The accumulation buffer is usually 16 bit so as long as you don’t add too many frames, you should be getting enough precision.

The accumulation buffer is usually not hardware accelerated. Better use zeoverlords method, but for this you need a float render target to prevent saturation.

You can use the alpha channel to count how often the pixels are rendered, so you don’t need another pass for that.

Dear Overmind,

Thanks a lot, But how to do it with alpha channel.
Please suggest with some code

Thanks a lot
RAJESH