[Solved] SRGB textures

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Alundra
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Jun 30, 2014 03:29

[Solved] SRGB textures

Postby Alundra » Wed Mar 29, 2017 18:51

Hi,
CEGUI has an option to set the texture in SRGB format ?
If not, how handle the loading correctly ?
I see in the D3D11 renderer :

Code: Select all

static DXGI_FORMAT toD3DPixelFormat(const Texture::PixelFormat fmt)
{
    switch (fmt)
    {
        case Texture::PixelFormat::Rgba:     return DXGI_FORMAT_R8G8B8A8_UNORM;
        case Texture::PixelFormat::Rgb:      return DXGI_FORMAT_R8G8B8A8_UNORM;
        case Texture::PixelFormat::RgbaDxt1: return DXGI_FORMAT_BC1_UNORM;
        case Texture::PixelFormat::RgbaDxt3: return DXGI_FORMAT_BC2_UNORM;
        case Texture::PixelFormat::RgbaDxt5: return DXGI_FORMAT_BC3_UNORM;
        default: return DXGI_FORMAT_UNKNOWN;
    }
}

So, I guess CEGUI doesn't handle the SRGB format.
I have to modify the code and compile a custom version with the SRGB format ?
The problem is the color is too bright without the SRGB format.
Thanks

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Wed Mar 29, 2017 19:46

That's just pointless in my opinion, but maybe you can give me a good reason why this would be needed? Render CEGUI with gamma correction off.
CrazyEddie: "I don't like GUIs"

Alundra
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Jun 30, 2014 03:29

Re: SRGB textures

Postby Alundra » Wed Mar 29, 2017 21:36

Do you mean on a render target in RGBA8 and then render a full screen triangle again to show this result ?
But also maybe I'm doing wrong the SRGB, it's something I'm adding now, i'm not an expert on the topic for the GPU side.
Maybe the back buffer should not be in SRGB format but only the diffuse texture used in the scene.
But then, if the artist do texture in photoshop in SRGB space, CEGUI will render it wrong.
Message from one developer of Final Fantasy XV :
sRGB is a gamma-corrected color space that cameras apply to photos so that they display properly on your monitor.
Since artists draw through the monitor, their art is going to be in the same color space (since it also ends up looking correct when displayed on a monitor).

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Wed Mar 29, 2017 22:23

I hope I remember correctly how gamma correction works: So since the CEGUI textures are in RGB format, and your FBO is SRGB and you got SRGB enabled in general, the RGB values from the CEGUI textures will be turned from RGB to SRGB when you render to your FBO. This is wrong because all source art is technically in SRGB, so you would just want to use the texel values without conversion. That's the problem right?
CrazyEddie: "I don't like GUIs"

Alundra
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Jun 30, 2014 03:29

Re: SRGB textures

Postby Alundra » Wed Mar 29, 2017 22:43

Correct.
So the only solution I see would be to output in a RGBA8 texture and then render to the back buffer which is in SRGB, since the input is in RGBA8 (the render target) so the conversion is not performed. Would works, but needs extra works on the rendering, using simply the good texture format avoid that.
SRGB texture means in the shader when you sample it does : SRGB -> Linear
SRGB target means the output does : Linear -> SRGB
So basically the hardware convert the sample to Linear, you compute in linear, then the hardware convert to SRGB the result.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Thu Mar 30, 2017 15:37

I suggest we add a field to CEGUI::Renderer that can be changed on construction. So I would add a parameter to the constructor, e.g. useSrgbFormats, with default = false, and no setter since it makes no sense to mix this or change in runtime imho. Or do we ever want to change it after construction or mix formats? I can't think of a use-case.

When the Renderer has m_useSrgbFormats= true then it will use the SRGB formats equivalent to the RGB ones.
CrazyEddie: "I don't like GUIs"

Alundra
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Jun 30, 2014 03:29

Re: SRGB textures

Postby Alundra » Thu Mar 30, 2017 17:41

The flag on the creation looks to be a good solution.
RGBA8, BC1,BC2,BC3 and BC7 have equivalent SRGB format.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Thu Mar 30, 2017 17:49

We can't do this on v0-8 ( 0.8.X ) though because introducing a new field would break ABI. Which version are you using? I would suggest to fix this on default and you integrate the fix into a fork that you create of v0-8.
CrazyEddie: "I don't like GUIs"

Alundra
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Jun 30, 2014 03:29

Re: SRGB textures

Postby Alundra » Thu Mar 30, 2017 19:15

I'm using the version 0.8.7 from the website and I simply recompiled on x86/x64 and debug/release for each.
I can simply change the format of the texture to SRGB and recompile the renderer but for the 1.0 it would be better to have directly the option.
But in reality sRGB should be a property by texture, because you can have linear or sRGB texture depending on the color space used by the artist.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Thu Mar 30, 2017 21:22

Alundra wrote: because you can have linear or sRGB texture depending on the color space used by the artist.

Can you show me an example of artist textures not being in sRGB? I am not aware of anyone's art being actually stored like that so I'd love to know if you actually have examples.
CrazyEddie: "I don't like GUIs"

Alundra
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Jun 30, 2014 03:29

Re: SRGB textures

Postby Alundra » Fri Mar 31, 2017 20:21

In the case of GUI, since it's diffuse texture, it has to be in sRGB, but on a classical rendering you have other type of texture which is not sRGB like normal map, displacement map ... But yea normally when you start on one color space, you do all with this color space, but normally the engine must have it possible to switch from one to another, Unreal for example has one checkbox sRGB in the texture editor to change the format to sRGB, and the color picker also has checkbox to switch to have the preview in sRGB or linear.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Mon Apr 03, 2017 07:19

Ok then I guess we should have it in the Renderer constructor params, have a runtime setter for the Renderer and have a parameter in all texture creation functions as well and the Texture constructor.
CrazyEddie: "I don't like GUIs"

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Sun Apr 09, 2017 21:36

Have you done anything regarding the discussed changes so far? I would be adding the interface for this on default branch next weekend.
CrazyEddie: "I don't like GUIs"

Alundra
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Jun 30, 2014 03:29

Re: SRGB textures

Postby Alundra » Wed May 03, 2017 23:26

I simply changed all format to SRGB since I only want to load SRGB and render to SRGB it's all ok for me but of course the mode to allow SRGB or not is nice a middleware and also allow to load the two color space. But of course all the commercial games allow a gamma setting for the render target because only computer's monitor is SRGB but for TV's you have to set the gamma manually actually. But for the texture loading, you simply have to use the SRGB format to have the hardware conversion on the texture sampling, only on the output the manual gamma enters in game.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: SRGB textures

Postby Ident » Thu May 04, 2017 07:14

Yes, just changing the formats everywhere in the Renderer code is an easy workaround for 0.8.X.

I agree that, since there is a use-case for this feature, CEGUI should have an sRGB option and I will add this for 1.0. This will happen together with the creation of the new Vulkan Renderer.
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 18 guests