diff --git a/renderdoc/data/glsl/texdisplay.frag b/renderdoc/data/glsl/texdisplay.frag index 8f6cf4f07..90f6b5f4a 100644 --- a/renderdoc/data/glsl/texdisplay.frag +++ b/renderdoc/data/glsl/texdisplay.frag @@ -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; diff --git a/renderdoc/data/hlsl/debugdisplay.hlsl b/renderdoc/data/hlsl/debugdisplay.hlsl index 1b00950a0..9dfe216e4 100644 --- a/renderdoc/data/hlsl/debugdisplay.hlsl +++ b/renderdoc/data/hlsl/debugdisplay.hlsl @@ -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; diff --git a/renderdoc/data/spv/texdisplay.frag b/renderdoc/data/spv/texdisplay.frag index de6988006..853193438 100644 --- a/renderdoc/data/spv/texdisplay.frag +++ b/renderdoc/data/spv/texdisplay.frag @@ -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;