Color sum in fragment program


I’m trying to do a simple summation in a fragment program between all the fragments located at one pixel. Fragment program doesn’t allow us to write in a texture or in a hardware buffer, so is there a solution ? For information, i don’t know how many fragments i have at one pixel.


Blending with a floating point 16 bit buffer comes to mind, but that needs a GeForce 6800 today.
If the overdraw count helps and there are no more than 255, you can count them per pixel in the stencil buffer.

You can render to a texture, then have a fragment program go and read from 2x2 or 3x3 blocks of that texture to create a lower-resolution version of that texture. Repeat this process until you have a 1x1 texture. If the “filtering” algorithm is a summation of the 2x2 or 3x3 blocks, then the 1x1 texture result will be the sum of all pixel values.

I’m going to re-explain my issue:

There is no depth test. I’m working at a pixel. Before having the final pixel color, there are some fragments depending on the facets of objects. For each of this fragments (noted k) i have to compute a value Vk that is used in the computation of values V of others fragments (always at the same pixel). And the final pixel color is equal to the value of the last treated fragment. It’s like an iterative sum :

sum = 0
for each fragments at pixel p do {
V = compute_value(sum);
sum += V;

I want to write a fragment program (and/or vertex program if needed) to do this. How can i do ?

To get access to each fragment that covers a particular framebuffer location, you can use depth peeling. To get the value of the previous fragment to serve as input for the color calculation of the current fragment, you’d have to use peel N-1 as a texture when rendering for peel N.

– Tom

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.