setAlphaOperation and setColourOperationEx d3d vs opengl

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
manowar
Orc
Posts: 419
Joined: Thu Apr 07, 2005 2:11 pm
Location: UK
Contact:

setAlphaOperation and setColourOperationEx d3d vs opengl

Post by manowar »

I am rendering splash screens in my application using overlays. I simply fade from/to black/white using:

Code: Select all

mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL,Ogre::ColourValue::White,Ogre::ColourValue(mColour,mColour,mColour) );
At the same time in some cases I also blend the overlay with the scene using something like this:

Code: Select all

mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, mAlpha, 1 - mAlpha);
New values for mAlpha and mColours are computed each frame depending of the wanted effect.

After a few blending operations, I have some issues with setColourOperationEx(...). Changing mColour has no effect at all. I spent hours trying to understand what was wrong and how to fix it with no luck.

Just to test I tried to use opengl rendersystem instead of d3d9. I was really surprised to see that everything was working fine exactly like I wanted!

Are opengl and d3d9 blending operations supposed to work exactly the same way in Ogre ? Are there any limitations ?

Thanks a lot
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

They're meant to be the same. Do you mean that you get the colour you want the first time, but not on changing it?
User avatar
manowar
Orc
Posts: 419
Joined: Thu Apr 07, 2005 2:11 pm
Location: UK
Contact:

Post by manowar »

Yes, the fading from white to black does not work anymore with d3d, everything is fine with opengl. Basically calling

Code: Select all

mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL,Ogre::ColourValue::White,Ogre::ColourValue(mColour,mColour,mColour) );
and changing mColour has no effect at all after changing the alpha blending parameters.

I found a fix now, I simply call

Code: Select all

mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);
when there is no alpha fading instead of calling

Code: Select all

mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1,  mAlpha);
with mAlpha = 1

Restoring the default alpha blending parameters makes the colour blending working again with d3d.

I will try to do some more testing to find when the problem occurs exactly.
User avatar
manowar
Orc
Posts: 419
Joined: Thu Apr 07, 2005 2:11 pm
Location: UK
Contact:

Post by manowar »

Well, I got rid of all the fading effects...and did the most simple test ever.

Code: Select all

mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL,Ogre::ColourValue::White,Ogre::ColourValue(1,0,0) );	mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1.0, 1.0);
With opengl my texture is getting reddish...it stays 'original' with d3d

If I do not call setAlphaOperation, it works with both.

Am I missing something ?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Ok, it's bug, I've found and fixed it. Tiny slip of the keyboard, would only affect using manual as source2 and only when doing both colour and alpha manual blending (since it affected the merging of the constant):

Code: Select all

Index: RenderSystems/Direct3D9/src/OgreD3D9RenderSystem.cpp
===================================================================
RCS file: /cvsroot/ogre/ogrenew/RenderSystems/Direct3D9/src/OgreD3D9RenderSystem.cpp,v
retrieving revision 1.178.2.9
diff -u -r1.178.2.9 OgreD3D9RenderSystem.cpp
--- RenderSystems/Direct3D9/src/OgreD3D9RenderSystem.cpp	28 Aug 2007 14:27:42 -0000	1.178.2.9
+++ RenderSystems/Direct3D9/src/OgreD3D9RenderSystem.cpp	22 Oct 2007 16:59:02 -0000
@@ -2014,7 +2014,7 @@
 		{
 			tss = D3DTSS_COLORARG2;
 			manualD3D = D3DXCOLOR( bm.colourArg2.r, bm.colourArg2.g, bm.colourArg2.b, bm.colourArg2.a );
-			mManualBlendColours[stage][1] = bm.colourArg1;
+			mManualBlendColours[stage][1] = bm.colourArg2;
 		}
 		else if( bm.blendType == LBT_ALPHA )
 		{
User avatar
manowar
Orc
Posts: 419
Joined: Thu Apr 07, 2005 2:11 pm
Location: UK
Contact:

Post by manowar »

Thanks a lot.
Post Reply