From a924483dc59077eaf41401a392597aea8c7dd222 Mon Sep 17 00:00:00 2001 From: Filoppi Date: Wed, 28 Jun 2023 02:30:03 +0300 Subject: [PATCH 1/2] Add AutoHDR post process shader --- Data/Sys/Shaders/AutoHDR.glsl | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Data/Sys/Shaders/AutoHDR.glsl diff --git a/Data/Sys/Shaders/AutoHDR.glsl b/Data/Sys/Shaders/AutoHDR.glsl new file mode 100644 index 000000000000..6226d70d7c2d --- /dev/null +++ b/Data/Sys/Shaders/AutoHDR.glsl @@ -0,0 +1,64 @@ +// Based on https://github.com/Filoppi/PumboAutoHDR + +/* +[configuration] + +[OptionRangeFloat] +GUIName = HDR Display Max Nits +OptionName = HDR_DISPLAY_MAX_NITS +MinValue = 80 +MaxValue = 2000 +StepAmount = 1 +DefaultValue = 400 + +[OptionRangeFloat] +GUIName = Shoulder Start Alpha +OptionName = AUTO_HDR_SHOULDER_START_ALPHA +MinValue = 0 +MaxValue = 1 +StepAmount = 0.01 +DefaultValue = 0 + +[OptionRangeFloat] +GUIName = Shoulder Pow +OptionName = AUTO_HDR_SHOULDER_POW +MinValue = 1 +MaxValue = 10 +StepAmount = 0.05 +DefaultValue = 2.5 + +[/configuration] +*/ + +void main() +{ + float4 color = Sample(); + + // Nothing to do here, we are in SDR + if (!OptionEnabled(hdr_output) || !OptionEnabled(linear_space_output)) + { + SetOutput(color); + return; + } + + const float hdr_paper_white = hdr_paper_white_nits / hdr_sdr_white_nits; + + // Restore the original SDR (0-1) brightness (we might or might not restore it later) + color.rgb /= hdr_paper_white; + + // Find the color average + float sdr_ratio = (color.r + color.g + color.b) / 3.0; + + const float auto_hdr_max_white = max(HDR_DISPLAY_MAX_NITS / (hdr_paper_white_nits / hdr_sdr_white_nits), hdr_sdr_white_nits) / hdr_sdr_white_nits; + if (sdr_ratio > AUTO_HDR_SHOULDER_START_ALPHA && AUTO_HDR_SHOULDER_START_ALPHA < 1.0) + { + const float auto_hdr_shoulder_ratio = 1.0 - (max(1.0 - sdr_ratio, 0.0) / (1.0 - AUTO_HDR_SHOULDER_START_ALPHA)); + const float auto_hdr_extra_ratio = pow(auto_hdr_shoulder_ratio, AUTO_HDR_SHOULDER_POW) * (auto_hdr_max_white - 1.0); + const float auto_hdr_total_ratio = sdr_ratio + auto_hdr_extra_ratio; + color.rgb *= auto_hdr_total_ratio / sdr_ratio; + } + + color.rgb *= hdr_paper_white; + + SetOutput(color); +} \ No newline at end of file From bfb90b7eeca2b4991f8ff2cf778090cabb84a481 Mon Sep 17 00:00:00 2001 From: Filoppi Date: Wed, 28 Jun 2023 02:31:14 +0300 Subject: [PATCH 2/2] Video: increase the max HDR brightness multiplier to a more appropriate value (400 nits can be too dark in a bright room) --- Source/Core/Core/Config/GraphicsSettings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/Config/GraphicsSettings.h b/Source/Core/Core/Config/GraphicsSettings.h index e24d47a39bb7..009b219136b3 100644 --- a/Source/Core/Core/Config/GraphicsSettings.h +++ b/Source/Core/Core/Config/GraphicsSettings.h @@ -117,7 +117,7 @@ static constexpr float GFX_CC_DISPLAY_GAMMA_MIN = 2.2f; static constexpr float GFX_CC_DISPLAY_GAMMA_MAX = 2.4f; static constexpr float GFX_CC_HDR_PAPER_WHITE_NITS_MIN = 80.f; -static constexpr float GFX_CC_HDR_PAPER_WHITE_NITS_MAX = 400.f; +static constexpr float GFX_CC_HDR_PAPER_WHITE_NITS_MAX = 500.f; extern const Info GFX_CC_CORRECT_COLOR_SPACE; extern const Info GFX_CC_GAME_COLOR_SPACE;