diff options
Diffstat (limited to 'system/shaders')
-rw-r--r-- | system/shaders/guishader_common.hlsl | 31 | ||||
-rw-r--r-- | system/shaders/guishader_default.hlsl | 2 | ||||
-rw-r--r-- | system/shaders/guishader_fonts.hlsl | 2 | ||||
-rw-r--r-- | system/shaders/guishader_multi_texture_blend.hlsl | 4 | ||||
-rw-r--r-- | system/shaders/guishader_texture.hlsl | 2 |
5 files changed, 36 insertions, 5 deletions
diff --git a/system/shaders/guishader_common.hlsl b/system/shaders/guishader_common.hlsl index 0f2a7a7c47..1d8fa10e56 100644 --- a/system/shaders/guishader_common.hlsl +++ b/system/shaders/guishader_common.hlsl @@ -47,8 +47,39 @@ cbuffer cbWorld : register(b0) float4x4 worldViewProj; float blackLevel; float colorRange; + int PQ; }; +inline float3 transferPQ(float3 x) +{ + static const float ST2084_m1 = 2610.0f / (4096.0f * 4.0f); + static const float ST2084_m2 = (2523.0f / 4096.0f) * 128.0f; + static const float ST2084_c1 = 3424.0f / 4096.0f; + static const float ST2084_c2 = (2413.0f / 4096.0f) * 32.0f; + static const float ST2084_c3 = (2392.0f / 4096.0f) * 32.0f; + static const float SDR_peak_lum = 100.0f; + static const float3x3 matx = + { + 0.627402, 0.329292, 0.043306, + 0.069095, 0.919544, 0.011360, + 0.016394, 0.088028, 0.895578 + }; + // REC.709 to linear + x = pow(x, 1.0f / 0.45f); + // REC.709 to BT.2020 + x = mul(matx, x); + // linear to PQ + x = pow(x / SDR_peak_lum, ST2084_m1); + x = (ST2084_c1 + ST2084_c2 * x) / (1.0f + ST2084_c3 * x); + x = pow(x, ST2084_m2); + return x; +} + +inline float4 tonemapHDR(float4 color) +{ + return (PQ) ? float4(transferPQ(color.rgb), color.a) : color; +} + inline float4 adjustColorRange(float4 color) { return float4(blackLevel + colorRange * color.rgb, color.a); diff --git a/system/shaders/guishader_default.hlsl b/system/shaders/guishader_default.hlsl index cf4183a0f9..82b6510c77 100644 --- a/system/shaders/guishader_default.hlsl +++ b/system/shaders/guishader_default.hlsl @@ -22,7 +22,7 @@ float4 PS(PS_INPUT input) : SV_TARGET { - return adjustColorRange(input.color); + return tonemapHDR(adjustColorRange(input.color)); } diff --git a/system/shaders/guishader_fonts.hlsl b/system/shaders/guishader_fonts.hlsl index def887d162..59c2ffec90 100644 --- a/system/shaders/guishader_fonts.hlsl +++ b/system/shaders/guishader_fonts.hlsl @@ -25,7 +25,7 @@ Texture2D texFont : register(t0); float4 PS(PS_INPUT input) : SV_TARGET { input.color.a *= texFont.Sample(LinearSampler, input.tex).r; - return adjustColorRange(input.color); + return tonemapHDR(adjustColorRange(input.color)); } diff --git a/system/shaders/guishader_multi_texture_blend.hlsl b/system/shaders/guishader_multi_texture_blend.hlsl index 33f1f0fbd3..77c2e79255 100644 --- a/system/shaders/guishader_multi_texture_blend.hlsl +++ b/system/shaders/guishader_multi_texture_blend.hlsl @@ -24,8 +24,8 @@ Texture2D txDiffuse[2] : register(t0); float4 PS(PS_INPUT input) : SV_TARGET { - return adjustColorRange(input.color * txDiffuse[0].Sample(LinearSampler, input.tex) - * txDiffuse[1].Sample(LinearSampler, input.tex2)); + return tonemapHDR(adjustColorRange(input.color * txDiffuse[0].Sample(LinearSampler, input.tex) * + txDiffuse[1].Sample(LinearSampler, input.tex2))); } diff --git a/system/shaders/guishader_texture.hlsl b/system/shaders/guishader_texture.hlsl index 845747ec41..665aff0abb 100644 --- a/system/shaders/guishader_texture.hlsl +++ b/system/shaders/guishader_texture.hlsl @@ -24,7 +24,7 @@ Texture2D texMain : register(t0); float4 PS(PS_INPUT input) : SV_TARGET { - return adjustColorRange(input.color * texMain.Sample(LinearSampler, input.tex)); + return tonemapHDR(adjustColorRange(input.color * texMain.Sample(LinearSampler, input.tex))); } |