PDA

View Full Version : How to prevent blending with background?



dorpez
01-31-2011, 05:03 AM
Hello,

I am trying to create a selective blending. The intention is to render some textured planes (containing semi-translucent alpha values). If there is nothing between the planes and the background no blending should take place to ensure a correct color value of the result. The result is read from the buffer and saved to an image.

Currently I am using this code:

//clear depthbuffer and render only planes being further in the background
glClearDepth( 0.0 );
glClear( GL_DEPTH_BUFFER_BIT );
glDepthFunc( GL_GREATER );

//disable blending and render only color of the planes
glDisable( GL_BLEND );
glColorMask( true, true, true, false );

//--> RENDER CONTENT

//reset depthbuffer
glClearDepth( 1.0 );
glClear( GL_DEPTH_BUFFER_BIT );
glDepthFunc( GL_LESS );

//reset to standard blending
glEnable( GL_BLEND );
glColorMask( true, true, true, true );

//--> RENDER CONTENT

Actually this retrieves a correct result, but forces me to render the planes/content twice. Has someone a better solution or does someone knows an extension to achieve the result in one step?

ZbuffeR
01-31-2011, 08:22 AM
You really need the color value ? Or you can get away with pre-multiplied alpha ?

dorpez
02-01-2011, 02:36 AM
No, pre-multiplied alpha is not an option. The rendering results is afterwards composed on a video background by a DVE-Engine.

ZbuffeR
02-01-2011, 02:46 AM
I always though professional video compositing did the right thing and were able to use pre-multiplied alpha ... guess I was wrong.

No better idea, sorry.