PDA

View Full Version : Blending function for maximum alpha estimation

AnselmG
01-22-2008, 12:53 AM
Hi,

I want to set the blending function in such a way that only the color values of the fragment with the maximum alpha values are written into the frambuffer - all other fragments should ber not considered at all...

It sounds like a question for the beginners forum, but I really don't find the correct solution...

ZbuffeR
01-22-2008, 01:27 AM
With "maximum alpha" you mean a known fixed value, such as 1.0 in float or 255 int ? Or an unknown value determined by scanning the whole scene or object ?

In the first case it is trivially done with alpha testing (http://gpwiki.org/index.php/OpenGL_Tutorial_Framework:Ortho_and_Alpha#Alpha_Te sting) set to >= 1.0, otherwise you need to calculate or read back the alpha threshold.

AnselmG
01-22-2008, 04:30 AM
I'll try to explain my problem a little bit more in detal:

I am using a vertex shader to calculate a series of function values (256-therefore I render 256 points) - the result should be transfered to exactly the same fragment position and finally - as a result - I want to get the maximum value for free (that's why I was thinking about using alpha blending)
However - maybe I could just change the point's z-value according to its value (normalized) and set the depth test to get the largest one...

-NiCo-
01-22-2008, 04:37 AM
In that case you should use
glBlendEquation(GL_MAX)

But if I were you I would probably implement it using a for loop in a fragment shader...

N.

V-man
01-22-2008, 10:30 PM
I'll try to explain my problem a little bit more in detal:

I am using a vertex shader to calculate a series of function values (256-therefore I render 256 points) - the result should be transfered to exactly the same fragment position and finally - as a result - I want to get the maximum value for free (that's why I was thinking about using alpha blending)
However - maybe I could just change the point's z-value according to its value (normalized) and set the depth test to get the largest one...

Your better off using the depth value.

If you backbuffer color is 32 bpp, then you can use blending. If it is 128 bit floating point buffer, blending would not work. With 64 bit floating point buffer, the NV 6x000 and up can do blending.

-NiCo-
01-23-2008, 01:10 AM
I haven't tried it myself yet, but I believe the Geforce 8 series support 128 bpp fp blending.

N.

AnselmG
01-23-2008, 01:52 AM
thanks for all information - I will try both solutions (max and depth) and choose the faster/more precise one...