Page 1 of 1

Gamma correction & cegui

Posted: Tue Jun 26, 2018 5:13 pm
by zvd2
Ogre Version: 2.1
Render System: GL3Plus

When I'm not using gamma correction on my renderwindow my textures appear too dark but when I am using gamma correction cegui assets appear too bright. What's the proper way of doing this?

Image

Re: Gamma correction & cegui

Posted: Wed Jun 27, 2018 1:28 pm
by zvd2
While I'm at it, shouldn't it be possible to automatically detect whether gamma correction is necessary? At the very least I've never seen any other 3D program require this to be set manually.

Re: Gamma correction & cegui

Posted: Wed Jun 27, 2018 3:00 pm
by dark_sylinc
zvd2 wrote:
Wed Jun 27, 2018 1:28 pm
While I'm at it, shouldn't it be possible to automatically detect whether gamma correction is necessary? At the very least I've never seen any other 3D program require this to be set manually.
Hi!

I don't like the term "gamma correction" but I rather prefer "sRGB space". Colour can be in linear space or sRGB space (there are more). Just like in 3D transformations there's local, world and view space (among many others, possibly arbitrary spaces, because in Einstein terms, it's all relative).

Photorealistic rendering, which is what we commonly use PBR for, definitely needs "gamma correction" to be enabled, always. However if you're not doing photorealistic rendering, you may or may not want to turn it off depending on your artistic needs.

I do agree gamma correction should be on by default, rather than off. It's just something that slipped by and has historically been optional, being off the default (mostly because Ogre is now a 18 year old engine).

As for your problem, i.e. CEGUI not working fine with sRGB, I thought it would be fixed by now.. sigh.
Find OgreTexture::createEmptyOgreTexture and OgreTextureTarget::declareRenderSize in CEGUI's source code, and right after creating the Textures, call setHardwareGammaEnabled:

cegui/src/RendererModules/Ogre/TextureTarget.cpp

Code: Select all

//----------------------------------------------------------------------------//
void OgreTexture::createEmptyOgreTexture()
{
    // try to create a Ogre::Texture with given dimensions
    d_texture = Ogre::TextureManager::getSingleton().createManual(
        getUniqueName(), "General", Ogre::TEX_TYPE_2D,
        1, 1, 0,
        Ogre::PF_A8B8G8R8);
    d_texture->setHardwareGammaEnabled( true );
}
cegui/src/RendererModules/Ogre/TextureTarget.cpp

Code: Select all

//----------------------------------------------------------------------------//
void OgreTextureTarget::declareRenderSize(const Sizef& sz)
{
    // exit if current size is enough
    if ((d_area.getWidth() >= sz.d_width) && (d_area.getHeight() >=sz.d_height))
        return;

    Ogre::TexturePtr rttTex = Ogre::TextureManager::getSingleton().createManual(
        OgreTexture::getUniqueName(),
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D, sz.d_width, sz.d_height, 1, 0, Ogre::PF_A8R8G8B8,
        Ogre::TU_RENDERTARGET);

     rttTex->setHardwareGammaEnabled( true );
You could try to get clever and enable hw gamma correction only when it was enabled in Ogre, but given that you'll very likely need it always on, this will get you started.

Cheers
Matias

Re: Gamma correction & cegui

Posted: Thu Jun 28, 2018 11:10 am
by zvd2
Thank you very much for the extensive reply, your suggestion worked perfectly.

Re: Gamma correction & cegui

Posted: Thu Jul 26, 2018 2:46 am
by areay
Late to the party but the first cegui source that needs editting is cegui/src/RendererModules/Ogre/Texture.cpp