PDA

View Full Version : color sum in fragment program



Ewik
05-28-2004, 05:54 AM
Hi,

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.

thanks.

Relic
05-28-2004, 07:33 AM
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.

Korval
05-28-2004, 10:21 AM
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.

Ewik
06-01-2004, 03:28 AM
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 ?

Tom Nuydens
06-01-2004, 04:39 AM
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