Custom Alpha Blending?

If one were to want to create a custom method of alpha blending, say one that did a gamma 2.2 -> gamma 1.0 conversion, blend per alpha / 1 - alpha, then a gamma 1.0 -> gamma 2.2 conversion, is there a good way (e.g., via a shader) to accomplish this?

We have researched EXT_texture_sRGB and while this is definitely in the right ballpark it doesn’t cover everything we need.

Thanks.

-Noel

Have you investigated ARB_framebuffer_sRGB?

Thanks for your response.

Unfortunately ARB_framebuffer_sRGB a little too new and we need to reach a wider market than those who have updated systems that support it.

Our current approach is that we’re changing OpenGL to do its rendering entirely in gamma 1.0 space, and we’re developing a fragment shader to increase the gamma.

We’re still laying the ground work for adding the shader today… Do you know if we’re likely to see a big performance hit by applying a pow function to every pixel? I am not too clear on how much power is available inside the GPU for such complex math operations. I know there’s quite a lot.

-Noel

What’s stopping you from rendering to a regular FBO then doing a post-pass with color = pow(OldColor, 1.0/2.2); ?

We have been rendering in linear (1.0 gamma) space for many years. pow() is used to convert to 2.2 gamma just before the fragment shader writes the output color. Accurate linear blending is not critical in our application and occurs in the 2.2 gamma space. Blending is not part of a fragment shader’s function. pow() performance has not been an issue because we use only the most powerful ATI and NVIDIA GPU’s.

Accurate linear alpha blending could be implemented by rendering to a linear high precision frame buffer object and converting the final results to 2.2 gamma in a second pass. ARB_framebuffer_sRGB provides linear blending without requiring the intermediate frame buffer object or second pass.

Yes, that’s the approach we’re taking.

Sorry if this is a naive question, but is “post-pass” or “second pass” just a matter of rendering something inconsequential over the entire image (e.g., a fully transparent object) when the gamma altering fragment shader has been put into place?

Thanks.

-Noel

Yes, that’s the approach we’re taking.

Sorry if this is a naive question, but is “post-pass” or “second pass” just a matter of rendering something inconsequential over the entire image (e.g., a fully transparent object) when the gamma altering fragment shader has been put into place?

Thanks.

-Noel[/QUOTE]
The first pass renders into a texture attached as the frame buffer of a frame buffer object. The second pass renders a full screen quad using the texture produced in the first pass as input. The gamma transformation from 1.0 -> 2.2 occurs in the second pass fragment shader. No blending occurs in the second pass.