New blending functions to support downstream alpha keying

I’m working on television VR applications where both the colour and alpha components from the frame buffer are passed downstream for keying/compositing.

This is because I need to do back to front rendering, based on destination alpha. So after rendering the following needs to be true:

  • the alpha component in the frame buffer must represent the opacity of the computer’s output;
  • the colour components must always be full intensity - since it is the alpha component that will be used to fade content out downstream.

The upshot is, I need an extra mode for glBendFunc, such as:

(A<dest>, A<dest>, A<dest>, 1)

What specific equation are you looking for in terms of alpha blending? Given a source color/alpha and destination color/alpha, what do you need?

r = (r<src> * (1 - a<dest>)) + (r<dest> * a<dest>)
g = (g<src> * (1 - a<dest>)) + (g<dest> * a<dest>)
b = (b<src> * (1 - a<dest>)) + (b<dest> * a<dest>)

a = (a<src> * (1 - a<dest>)) + a<dest>

where for a given pixel being rendered:

r<src>,g<src>,b<src>,a<src> is the colour of the fragment being rendered

r<dest>,g<dest>,b<dest>,a<dest> is the colour currently in the frame buffer

r,g,b,a are the new values to be written into the frame buffer.

Ah ha!

I’ve just discovered the OpenGL 1.4 specification which seems to provide the means to do it:

glBlendFuncSeparate() on P169 of the specification.

I guess I’ll just have to wait for someone to release drivers that support it … unless anyone can think of a way to achieve the same effect without having to render multiple passes, masking colour/alpha bits in the frame buffer!


according to delph3d.nets HW registry the Radeon 8500 supports the blend_func_separate extension, so you could use it just now.