Sign in to follow this  
Alundra

Correct SRGB for different pass (also SSAO)

Recommended Posts

Hi,
Using the SRGB format you have the free conversion made without any thinking, but the good values has to be set to achieve the best result.
For texture format you have BC1,BC2,BC3 and BC7 which have to be set to SRGB and if RGBA8 texture are used, the SRGB format has to be set here too.

Now the full process with thinking and questions for each pass :
- GBuffer (3 targets) is stored in RGBA16F format for each target, SRGB format here is not possible
   --> That means the SRGB will be converted to linear if i'm correct
- Lighting is stored in RGBA16F, again SRGB format here is not possible
  --> That uses the targets from GBuffer so no conversions are made and linear is outputed
- SSAO targets are in RGBA8 not the SRGB format
  --> Correct to not use SRGB here ?
- Combine SSAO with the lighting in RGBA16F, no one conversion used, all is in linear space
- Full bloom process in RGBA16F, SRGB format not possible
- Tone mapping in RGBA8 not the SRGB format
   --> SRGB should be used ?
- FXAA using the tonemapping target on the Backbuffer which is in RGBA8
   --> Backbuffer format needs to be in SRGB ?

The goal is to understand and convert the whole process to be correct about the SRGB.
Thanks

Edited by Alundra

Share this post


Link to post
Share on other sites

- GBuffer (3 targets) is stored in RGBA16F format for each target, SRGB format here is not possible

GBuffer should be as small as possible. If your source colour textures are 8bit sRGB, then your GBufer colour data should be 8bit sRGB too.

- Tone mapping in RGBA8 not the SRGB format    --> SRGB should be used ? - FXAA using the tonemapping target on the Backbuffer which is in RGBA8    --> Backbuffer format needs to be in SRGB ?

Never go between 8bit sRGB and 8bit non-sRGB (or vice versa) -- that's a great way to simply throw away precision.
The simplest rule is:
8 bit colour channels? Use sRGB.
16 bit colour channels? Use linear. 
Any kind of data channel? Use linear.

Share this post


Link to post
Share on other sites

I followed the simplest rule and the result is correct apparently but how work for custom generated texture on the pixel shader to be correct for the SRGB backbuffer ?
Is it needed to convert at the end of the pixel shader using the same code as for image processing :

float LinearToSRGB( in float x )
{
  return ( x <= 0.0031308f ) ? x * 12.92f : 1.055f * pow( x, 1.0f / 2.4f ) - 0.055f;
}

Or one way for the GPU side exists ? Because the result is a very bright color.
But I still have the very bright color compared to before.
But using SRGB to Linear on the rgb color values :

float SRGBToLinear( in float x )
{
  return ( x <= 0.04045f ) ? x * ( 1.0f / 12.92f ) : pow( ( x + 0.055f ) * ( 1.0f / 1.055f ), 2.4f );
}

I have a comparable result, not very bright.
Any explanation ?
Here my swapchain settings :

DXGI_SWAP_CHAIN_DESC SwapChainDesc;
SwapChainDesc.BufferCount  = 2;
SwapChainDesc.BufferDesc.Width  = Width;
SwapChainDesc.BufferDesc.Height  = Height;
SwapChainDesc.BufferDesc.Format  = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
SwapChainDesc.BufferDesc.RefreshRate.Numerator  = 60;
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
SwapChainDesc.BufferDesc.Scaling  = DXGI_MODE_SCALING_UNSPECIFIED;
SwapChainDesc.BufferDesc.ScanlineOrdering  = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
SwapChainDesc.BufferUsage  = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.Flags  = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
SwapChainDesc.OutputWindow  = SysWMInfo.info.win.window;
SwapChainDesc.SampleDesc.Count  = 1;
SwapChainDesc.SampleDesc.Quality  = 0;
SwapChainDesc.SwapEffect  = DXGI_SWAP_EFFECT_DISCARD;
SwapChainDesc.Windowed  = TRUE;
Edited by Alundra

Share this post


Link to post
Share on other sites

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).

Anything else should be considered linear.  Generated textures should be in linear space.  These will include normal maps, height maps, shininess maps, alpha channels, etc., as well as anything you generate on-the-fly (clouds, fog, etc.)

You always want to work in linear space so your process should be to immediately convert specific textures to linear (which of course can be done for you with flags), do all your work, and then convert back at the end of the frame (which can also be done for you with flags).

Whatever you are generating, make it in linear, use it in linear.  The only thing you convert back to sRGB is the final rendered scene.


L. Spiro

Share this post


Link to post
Share on other sites

Do you mean, if I understand correctly, all diffuse texture (artist made on photoshop) used everywhere only should be in sRGB but the back buffer and SSAO should be in Linear ?
It's not very clear actually, but I was sure the back buffer format needs to be in SRGB, surely I misunderstand this point.
Maybe the bright value I have is correct and I just need to adjust all the values with the gamma-correct.
About SSAO, this paper : https://fr.slideshare.net/naughty_dog/lighting-shading-by-john-hable
Says page 49 :

In linear space but probably should be gamma

Using the simplest rule from Hodgman, I simply set it SRGB on the last test I made.
For the font I create the texture dynamicly not using SRGB, surely the loaded bitmap should be converted to SRGB to have a font texture in SRGB maybe.
Or it's correct to stay not using SRGB here.

Edited by Alundra

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this