Sign in to follow this  
directNoob

[SOLVED]Problem to blend two rendered images together.[Fixed Function Pipe]

Recommended Posts

Good evening. Currently I try to fade two rendered images together, with a smooth transition, but it doesnt work propperly. I do it like this. It is possible to choose among some cameras. When the camera is switched, the scene gets blended from the first camera image, to the currently choosen camera picture. So, if the camera is switched, alpha blending is enabled. Then, I put a staring fading factor into the constant color slot, which gets decreased every frame. Here is the code.
/**
	Do the camera blending.
	If one camera is switched to another, apply 
	alpha blending between to camera pictures.
*/
void CApplication::DoCameraBlending( DWORD dwFlag  )
{	
	// now, set the initial values for blending in 
	// the constant color/alpha register.
	float f = GetCurScene()->GetFadeFactor() ;
        glBlendColor( f,f,f,f ) ;
	
	switch( dwFlag )
	{
		// first render screen
	case CAPP_BLEND_ONE:
		glBlendEquation( GL_ADD) ;
		// blend the screens
		glBlendFunc( GL_CONSTANT_COLOR, GL_ZERO ) ;
		
		break;

		// second render screen
	case CAPP_BLEND_TWO:
		
		//glBlendEquation( GL_LOGIC_OP );
		//glLogicOp(GL_OR) ;
		//glBlendEquation( GL_FUNC_SUBTRACT );
		// blend the screens
		glBlendEquation( GL_LOGIC_OP );
		glLogicOp(GL_INVERT) ;
		glBlendFunc( GL_ONE_MINUS_CONSTANT_COLOR, GL_SRC_COLOR ) ;
		//glBlendEquation( GL_FUNC_SUBTRACT ) ;

		break ;

	}
}





CAPP_BLEND_ONE means, that the first camera picture is rendered. CAPP_BLEND_TWO means, that the second, the recently choosen or the newest cameras picture is rendered. You can ignore these lines
glBlendEquation( GL_LOGIC_OP );
glLogicOp(GL_INVERT) ;





These lines have absolutly no effect!!! I have no idea why?!?! (Depth buffer problem???) The effect works just nice, but the problem is, that the older camera picture leaves its volume on the newly rendered image. This means, the effect of fading works just fine, but there is a volume, which just disappears when the fading is finished. Examples:



The next one looks extream bad! It looks like a depth buffer problem.


Maybe someone could give me some hint, how I can solve this ugly problem!?!? Grateful Alex [Edited by - directNoob on May 23, 2007 6:46:24 PM]

Share this post


Link to post
Share on other sites
You might be right with the depth buffer idea. You could always test that by enabling the depth test and setting the depth test function to allow everything.

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);


Hope that helps.

Share this post


Link to post
Share on other sites
I don't fully understand what you're trying to accomplish...are you trying to do a dissolve between two camera views, a la filmography?

If so, why not simply overlay the old view atop the new one, then drop the alpha only on the old view until it fades to nothing, fully revealing the new view. Since as it's blending out it will be occluding the lower image, it may appear as if they're trading places? Or is this not the effect you desire?

Share this post


Link to post
Share on other sites
Hi and thanks.

I found a solution.

It is to use glDepthMask()...

First of all.
First i thought to render to a separate texture. This means, rendering onto a texture for every camera. And than, just alpha blend them!
Very simple...

But, I dont have alpha values at hand right now, and I'm also not allowed to
program shaders, so the only availible solution to me is, using color blending with the fixed function pipe.

@serratemplar:
This is what I initially thought, but with the glDepthMask, you have to do it
vice versa. This means, first draw the camera view from the newest camera choosen with glDepthMask( GL_TRUE) and than, draw the old camera view, with glDepthMask(GL_FALSE). This worked perfectly and still works. But you still have to set the propper blending factors with glBlendFunc and, but not necessarily, glBlendEquation() with GL_FUNC_ADD.

When I'm allowed to use shaders, I will try render every camera view onto a separate texture and blend them together.

The effect looks great! This looks much better as just simply flip through the cameras and render sudden pictures.

You know what I mean?!

Thanks again
Alex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this