[2.2] myGui Yflipping when add pass for overlays

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

[2.2] myGui Yflipping when add pass for overlays

Post by xrgo » Fri Apr 05, 2019 5:22 pm

Hello! I recently integrated aces tonemapping in my engine, since that's a post process, the overlays (fps count and others) which where rendered in the same pass as the scene they look very dark... so I just separate the overlays to another pass in the same target of the post process:
Before:

Code: Select all

        {
            Ogre::CompositorTargetDef *targetDef = renderNodeDef->addTargetPass( "renderAux" );
            targetDef->setNumPasses( 1 );

            //SCENE
            mPassSceneDef = static_cast<Ogre::CompositorPassSceneDef*>( targetDef->addPass( Ogre::PASS_SCENE ) );
            mPassSceneDef->mExposedTextures.push_back( "TerraShadowTexture" );
            if( !mDisableShadows ){
                mPassSceneDef->mShadowNode = "MainEngineShadowNode";
            }
            mPassSceneDef->mProfilingId = "MAIN_SCENE_PASS";
            mPassSceneDef->mIdentifier = 25001;
            mPassSceneDef->setAllClearColours( Ogre::ColourValue::Black );
            mPassSceneDef->setAllLoadActions( Ogre::LoadAction::Clear );
            mPassSceneDef->setAllStoreActions( Ogre::StoreAction::Store );
        }
        {
            Ogre::CompositorTargetDef *targetDef = renderNodeDef->addTargetPass( "renderwindow" );
            targetDef->setNumPasses( 1 );

            //QUAD
            Ogre::CompositorPassQuadDef *passQuadDef = static_cast<Ogre::CompositorPassQuadDef*>( targetDef->addPass( Ogre::PASS_QUAD ) );
            passQuadDef->setAllLoadActions( Ogre::LoadAction::DontCare );
            passQuadDef->mMaterialName = "FinalProcessingMat";
            passQuadDef->addQuadTextureSource( 0, "renderAux" );
            passQuadDef->mProfilingId = "MAIN_FINAL_PROCESSING_QUAD_PASS";

        }
After

Code: Select all

        {
            Ogre::CompositorTargetDef *targetDef = renderNodeDef->addTargetPass( "renderAux" );
            targetDef->setNumPasses( 1 );

            //SCENE
            mPassSceneDef = static_cast<Ogre::CompositorPassSceneDef*>( targetDef->addPass( Ogre::PASS_SCENE ) );
            mPassSceneDef->mExposedTextures.push_back( "TerraShadowTexture" );
            if( !mDisableShadows ){
                mPassSceneDef->mShadowNode = "MainEngineShadowNode";
            }
            mPassSceneDef->mProfilingId = "MAIN_SCENE_PASS";
            mPassSceneDef->mIdentifier = 25001;
            mPassSceneDef->setAllClearColours( Ogre::ColourValue::Black );
            mPassSceneDef->setAllLoadActions( Ogre::LoadAction::Clear );
            mPassSceneDef->setAllStoreActions( Ogre::StoreAction::Store );
            mPassSceneDef->mLastRQ = 254;
        }
        {
            Ogre::CompositorTargetDef *targetDef = renderNodeDef->addTargetPass( "renderwindow" );
            targetDef->setNumPasses( 2 );

            //QUAD
            Ogre::CompositorPassQuadDef *passQuadDef = static_cast<Ogre::CompositorPassQuadDef*>( targetDef->addPass( Ogre::PASS_QUAD ) );
            passQuadDef->setAllLoadActions( Ogre::LoadAction::DontCare );
            passQuadDef->mMaterialName = "FinalProcessingMat";
            passQuadDef->addQuadTextureSource( 0, "renderAux" );
            passQuadDef->mProfilingId = "MAIN_FINAL_PROCESSING_QUAD_PASS";

            //OVERLAY SCENE
            Ogre::CompositorPassSceneDef *overlayPassSceneDef = static_cast<Ogre::CompositorPassSceneDef*>( targetDef->addPass( Ogre::PASS_SCENE ) );
            overlayPassSceneDef->mProfilingId = "MAIN_OVERLAY_PASS";
            overlayPassSceneDef->mFirstRQ = 254;
            overlayPassSceneDef->mLastRQ = 255;

        }
it works, but for some reason this makes all the MyGui stuffs flip vertically, I have no idea why might be related, its a totally different workspace.
its a bug? is there any way I can flip a workspace to workaround this?

thanks!
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4063
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: [2.2] myGui Yflipping when add pass for overlays

Post by dark_sylinc » Fri Apr 05, 2019 8:22 pm

I suspect you're using OpenGL?

FBOs (basically RenderTextures), RenderWindows and regular textures in GL have inconsistent origin (upper left vs lower left) thus require flipping.

Normally if you rely on the projection matrix sent by us this gets taken care automatically (because even when you request an identity projection matrix, it may not actually be identity matrix as we tweak it to flip the Y component).

But if you're rendering things entirely by yourself, then you need to handle flipping by yourself.
The relevant thing you're looking for is in RenderPassDescriptor::getCurrentPassDescriptor(), for example from OgreHlmsPbs.cpp:

Code: Select all

Matrix4 projectionMatrix = cameras.renderingCamera->getProjectionMatrixWithRSDepth();
RenderPassDescriptor *renderPassDesc = mRenderSystem->getCurrentPassDescriptor();

if( renderPassDesc->requiresTextureFlipping() )
{
    projectionMatrix[1][0] = -projectionMatrix[1][0];
    projectionMatrix[1][1] = -projectionMatrix[1][1];
    projectionMatrix[1][2] = -projectionMatrix[1][2];
    projectionMatrix[1][3] = -projectionMatrix[1][3];
}
If you're not using projection matrices, then a simple fix is to send the boolean to the vertex shader and perform:

Code: Select all

if( flipY )
    gl_Position.y = -gl_Position.y;
Cheers
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

Re: [2.2] myGui Yflipping when add pass for overlays

Post by xrgo » Fri Apr 05, 2019 10:45 pm

Thanks but now I noticed that its random, sometimes looks good, so those fixes, that seems to be persistent, wont work..

so I tried to get back to not using a separated pass, and add something like this:
since the problem is that overlays are dark I just:

Code: Select all

@piece( custom_ps_posExecution )
@property( !mygui )
	outColour.xyz *= 20;
@end
@end
but I need set a property for when its mygui, since those look good, and I found TextureGpu::setHlmsProperties, but its not implemented =/
I don't want to customize hlmsunlit too overkill just to brighten overlays :S

I'll keep looking a way to workaround this, thanks!
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4063
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: [2.2] myGui Yflipping when add pass for overlays

Post by dark_sylinc » Sat Apr 06, 2019 6:56 am

If you're using unlit, just set the color of the datablock above 1.0f

Though that will probably screw luminance calculations
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

Re: [2.2] myGui Yflipping when add pass for overlays

Post by xrgo » Sat Apr 06, 2019 4:49 pm

thanks that should work enough
but how do I get the datablock used by the overlay? I tried:

Code: Select all

        Ogre::v1::TextAreaOverlayElement* textArea= static_cast<Ogre::v1::TextAreaOverlayElement*>( manager.createOverlayElement( "TextArea", "myTextArea" ) );
        static_cast<Ogre::HlmsUnlitDatablock*>( textArea->getDatablock() )->setColour( Ogre::ColourValue::White*20 );
but it crashed, might be that the datablock itself is not yet created?
and if I later do this:

Code: Select all

        Ogre::Hlms::HlmsDatablockMap::const_iterator itor = Ogre::Root::getSingletonPtr()->getHlmsManager()->getHlms( Ogre::HLMS_UNLIT )->getDatablockMap().begin();
        Ogre::Hlms::HlmsDatablockMap::const_iterator end  = Ogre::Root::getSingletonPtr()->getHlmsManager()->getHlms( Ogre::HLMS_UNLIT )->getDatablockMap().end();
        while( itor != end )
        {
            std::cout<<"datablockName  "<<itor->second.datablock->getNameStr()<<std::endl;
            static_cast<Ogre::HlmsUnlitDatablock*>( itor->second.datablock )->setColour( Ogre::ColourValue::White*20 );
            ++itor;
        }
I get names like 0000017FB013FF78, but still I am doing the setColour to every datablock and its not changing anything =(
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4063
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: [2.2] myGui Yflipping when add pass for overlays

Post by dark_sylinc » Sat Apr 06, 2019 4:58 pm

xrgo wrote:
Sat Apr 06, 2019 4:49 pm
thanks that should work enough
but how do I get the datablock used by the overlay? I tried:

Code: Select all

        Ogre::v1::TextAreaOverlayElement* textArea= static_cast<Ogre::v1::TextAreaOverlayElement*>( manager.createOverlayElement( "TextArea", "myTextArea" ) );
        static_cast<Ogre::HlmsUnlitDatablock*>( textArea->getDatablock() )->setColour( Ogre::ColourValue::White*20 );
but it crashed, might be that the datablock itself is not yet created?
Most likely. Either nullptr or an assert
xrgo wrote:
Sat Apr 06, 2019 4:49 pm
and if I later do this:

Code: Select all

        Ogre::Hlms::HlmsDatablockMap::const_iterator itor = Ogre::Root::getSingletonPtr()->getHlmsManager()->getHlms( Ogre::HLMS_UNLIT )->getDatablockMap().begin();
        Ogre::Hlms::HlmsDatablockMap::const_iterator end  = Ogre::Root::getSingletonPtr()->getHlmsManager()->getHlms( Ogre::HLMS_UNLIT )->getDatablockMap().end();
        while( itor != end )
        {
            std::cout<<"datablockName  "<<itor->second.datablock->getNameStr()<<std::endl;
            static_cast<Ogre::HlmsUnlitDatablock*>( itor->second.datablock )->setColour( Ogre::ColourValue::White*20 );
            ++itor;
        }
I get names like 0000017FB013FF78, but still I am doing the setColour to every datablock and its not changing anything =(
You must call setUseColour( true ) first but I thought you knew that :P
1 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

Re: [2.2] myGui Yflipping when add pass for overlays

Post by xrgo » Sat Apr 06, 2019 5:11 pm

You must call setUseColour( true ) first but I thought you knew that
xD never really used unlit tbh
its working thanks!
0 x

Post Reply