# sRGB

This topic is 2151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all,

ToneMapping has to be applied on a sRGB render target.

Two options exist to have sRGB, Use the texture state sRGB or use the calcule pow(color,1/gamma).

Is it stable to use the texture state or is it better to use the calcule ?

Maybe the texture state doesn't allow to add setting to change the gamma (default 2.2).

Thanks

Edited by Alundra

##### Share on other sites

ToneMapping has to be applied on a sRGB render target.

Tone mapping can be applied to any image, not just sRGB.

Modern HW supports sRGB resources(both textures and render-targets). There's really no need for you to do the conversion yourself.

##### Share on other sites

Tone mapping can be applied to any image, not just sRGB.

I read from the paper of Uncharted 2 that to be correct it must be converted to sRGB.

Edited by Alundra

##### Share on other sites

Tone mapping can be applied to any image, not just sRGB.

I read from the paper of Uncharted 2 that to be correct it must be converted to sRGB.

Tone mapping maps from scene linear lighting values (basically, luminances from 0 to infinity) to display linear (range from [0, 1] for display on a monitor). After that, the display linear image is put back in sRGB space before being sent to the monitor. Tone mapping itself does not have to be in sRGB space (and in fact, tone mapping in sRGB kind of doesn't make sense, because sRGB only ranges from [0, 1] to begin with).

##### Share on other sites

Tone mapping can be applied to any image, not just sRGB.

I read from the paper of Uncharted 2 that to be correct it must be converted to sRGB.

I assume you are referring to John Hable's slides, and the filmic tone mapping he presented there. If your HW supports sRGB (and it probably does), you don't need the sRGB conversion, as long as you create your resources with an sRGB format.

[EDIT] This is how I implemented Hable's tone mapping in one of my demos - if I recall correctly it's based on some slides by AMD, but I can't really remember.

[EDIT2] Actually, this is from Hable's slides - slide 142,143. As he mentions, sRGB conversion is not baked into the values.

float3 HableToneMap(float3 color)
{
float A = 0.22;//Shoulder Strength
float B = 0.30;//Linear Strength
float C = 0.10;//Linear Angle
float D = 0.20;//Toe Strength
float E = 0.01;//Toe Numerator
float F = 0.30;//Toe Denominator

color = max(0, color - 0.004f);
color = ((color * (A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-(E/F);
return color;
}

float4 ToneMapPass(float2 TexC : TEXCOORD) : SV_TARGET
{
// Get average luminance
float3 Color = gImage.Sample(gPointSampler, TexC).xyz;

// This should be a per-vertex opeartion, since it's constant
float AvgLuminance = exp(gLuminanceMap.SampleLevel(gPointSampler, float2(0, 0), 9));
AvgLuminance = max(AvgLuminance, 0.001f);
Color *= gMiddleGray / AvgLuminance;

float TonedWhite = HableToneMap(gWhiteLevel.xxx);
Color = HableToneMap(Color)/TonedWhite.xxx;
}


As you can see, unlike the formula from the slides, this version uses the average scene luminance, as well as configurable white level and middle gray parameters. It looks really good (and as I just noticed, it's not optimized...)

Edited by N.I.B.

##### Share on other sites

If you do it in the shader it costs.

##### Share on other sites

I read on the doc of D3D11 :

DXGI_FORMAT_R8G8B8A8_UNORM_SRGB

A four-component, 32-bit unsigned-normalized integer sRGB format that supports 8 bits per channel including alpha.

so, the final render target need to be DXGI_FORMAT_R32G32B32A32_FLOAT and the result of tonemap DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ?

but, to allow arbitrary gamma curve so the result of the tonemap must be DXGI_FORMAT_R8G8B8A8_UNORM.

That mean all targets on the post-process need to be DXGI_FORMAT_R32G32B32A32_FLOAT that cost too much or it's ok on today's computer ?

##### Share on other sites

I read on the doc of D3D11 :

DXGI_FORMAT_R8G8B8A8_UNORM_SRGB

A four-component, 32-bit unsigned-normalized integer sRGB format that supports 8 bits per channel including alpha.

so, the final render target need to be DXGI_FORMAT_R32G32B32A32_FLOAT and the result of tonemap DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ?

but, to allow arbitrary gamma curve so the result of the tonemap must be DXGI_FORMAT_R8G8B8A8_UNORM.

That mean all targets on the post-process need to be DXGI_FORMAT_R32G32B32A32_FLOAT that cost too much or it's ok on today's computer ?

Kind of.

For HDR you need high-dynamic range format, which is either R32G32B32A32_FLOAT, R16G16B16A16_FLOAT, R11G11B10_FLOAT or R9G9B9E5_SHAREDEXP. From my experience the float16 format gives pretty good results, but depending on the values you are storing, the size of your RT and other parameters, any of the other formats can work as well.

Unrelated to HDR, I use R8G8B8A8_UNORM_SRGB as my back-buffer format. Also, the diffuse textures are usually in sRGB space.

If you want arbitrary gamma curve, then use DXGI_FORMAT_R8G8B8A8_UNORM. Normally, you wouldn't want it for the back-buffer since the HW will not know how to present it correctly.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11