Gamma correction & cegui Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
zvd2
Gnoblar
Posts: 14
Joined: Mon Jun 25, 2018 7:05 pm
x 3

Gamma correction & cegui

Post by zvd2 » Tue Jun 26, 2018 5:13 pm

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
0 x

zvd2
Gnoblar
Posts: 14
Joined: Mon Jun 25, 2018 7:05 pm
x 3

Re: Gamma correction & cegui

Post by zvd2 » 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.
0 x

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

Re: Gamma correction & cegui

Post by dark_sylinc » Wed Jun 27, 2018 3:00 pm

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
2 x

zvd2
Gnoblar
Posts: 14
Joined: Mon Jun 25, 2018 7:05 pm
x 3

Re: Gamma correction & cegui

Post by zvd2 » Thu Jun 28, 2018 11:10 am

Thank you very much for the extensive reply, your suggestion worked perfectly.
0 x

User avatar
areay
Bugbear
Posts: 816
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ

Re: Gamma correction & cegui

Post by areay » Thu Jul 26, 2018 2:46 am

Late to the party but the first cegui source that needs editting is cegui/src/RendererModules/Ogre/Texture.cpp
0 x

Post Reply