Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: color sum in fragment program

  1. #1
    Junior Member Newbie
    Join Date
    May 2004
    Location
    France
    Posts
    7

    color sum in fragment program

    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.

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: color sum in fragment program

    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.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,576

    Re: color sum in fragment program

    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.

  4. #4
    Junior Member Newbie
    Join Date
    May 2004
    Location
    France
    Posts
    7

    Re: color sum in fragment program

    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 ?

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Location
    Belgium
    Posts
    807

    Re: color sum in fragment program

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •