mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 17:40:39 +00:00
Implement proper accurate sRGB conversion, instead of pow(2.2) approx
This commit is contained in:
@@ -25,6 +25,14 @@
|
||||
|
||||
layout (location = 0) out vec4 color_out;
|
||||
|
||||
float ConvertSRGBToLinear(float srgb)
|
||||
{
|
||||
if (srgb <= 0.04045f)
|
||||
return srgb / 12.92f;
|
||||
else
|
||||
return pow(( clamp(srgb, 0.0f, 1.0f) + 0.055f) / 1.055f, 2.4f);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
#if UINT_TEX
|
||||
@@ -162,7 +170,7 @@ void main(void)
|
||||
|
||||
if((OutputDisplayFormat & TEXDISPLAY_GAMMA_CURVE) > 0)
|
||||
{
|
||||
col.rgb = pow(clamp(col.rgb, 0.0f.xxx, 1.0f.xxx), 2.2f.xxx);
|
||||
col.rgb = vec3(ConvertSRGBToLinear(col.r), ConvertSRGBToLinear(col.g), ConvertSRGBToLinear(col.b));
|
||||
}
|
||||
|
||||
color_out = col;
|
||||
|
||||
@@ -57,6 +57,14 @@ v2f RENDERDOC_DebugVS(uint vertID : SV_VertexID)
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float ConvertSRGBToLinear(float srgb)
|
||||
{
|
||||
if (srgb <= 0.04045f)
|
||||
return srgb / 12.92f;
|
||||
else
|
||||
return pow(saturate(srgb + 0.055f) / 1.055f, 2.4f);
|
||||
}
|
||||
|
||||
// main texture display shader, used for the texture viewer. It samples the right resource
|
||||
// for the type and applies things like the range check and channel masking.
|
||||
// It also does a couple of overlays that we can get 'free' like NaN/inf checks
|
||||
@@ -169,7 +177,7 @@ float4 RENDERDOC_TexDisplayPS(v2f IN) : SV_Target0
|
||||
|
||||
if(OutputDisplayFormat & TEXDISPLAY_GAMMA_CURVE)
|
||||
{
|
||||
col.rgb = pow(saturate(col.rgb), 2.2f);
|
||||
col.rgb = float3(ConvertSRGBToLinear(col.r), ConvertSRGBToLinear(col.g), ConvertSRGBToLinear(col.b));
|
||||
}
|
||||
|
||||
return col;
|
||||
|
||||
@@ -26,6 +26,14 @@ layout (location = 0) out vec4 color_out;
|
||||
|
||||
//#include "texsample.h" // while includes aren't supported in glslang, this will be added in code
|
||||
|
||||
float ConvertSRGBToLinear(float srgb)
|
||||
{
|
||||
if (srgb <= 0.04045f)
|
||||
return srgb / 12.92f;
|
||||
else
|
||||
return pow(( clamp(srgb, 0.0f, 1.0f) + 0.055f) / 1.055f, 2.4f);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
bool uintTex = (texdisplay.OutputDisplayFormat & TEXDISPLAY_UINT_TEX) != 0;
|
||||
@@ -166,7 +174,7 @@ void main(void)
|
||||
|
||||
if((texdisplay.OutputDisplayFormat & TEXDISPLAY_GAMMA_CURVE) > 0)
|
||||
{
|
||||
col.rgb = pow(clamp(col.rgb, 0.0f.xxx, 1.0f.xxx), 2.2f.xxx);
|
||||
col.rgb = vec3(ConvertSRGBToLinear(col.r), ConvertSRGBToLinear(col.g), ConvertSRGBToLinear(col.b));
|
||||
}
|
||||
|
||||
color_out = col;
|
||||
|
||||
Reference in New Issue
Block a user