From 46acc517d4fb40a3d2d2b47df9fa9df592d21085 Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Tue, 31 Dec 2024 13:14:13 -0500 Subject: [PATCH] feat(unrealengine): default to HDR10 --- src/games/unrealengine/addon.cpp | 26 +++++++++++++++++++++++--- src/games/unrealengine/common.hlsl | 12 ++++++++++-- src/games/unrealengine/shared.h | 1 + 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/games/unrealengine/addon.cpp b/src/games/unrealengine/addon.cpp index 23e65753..4d76178c 100644 --- a/src/games/unrealengine/addon.cpp +++ b/src/games/unrealengine/addon.cpp @@ -635,7 +635,7 @@ void AddAdvancedSettings() { .is_global = true, .is_visible = []() { return settings[0]->GetValue() >= 2; }, }; - reshade::get_config_value(nullptr, renodx::utils::settings::global_name.c_str(), ("Upgrade_" + key).c_str(), new_setting->value); + reshade::get_config_value(nullptr, renodx::utils::settings::global_name.c_str(), ("Upgrade_" + key).c_str(), new_setting->value_as_int); settings.push_back(new_setting); } @@ -653,10 +653,30 @@ void AddAdvancedSettings() { .is_global = true, .is_visible = []() { return settings[0]->GetValue() >= 2; }, }; - reshade::get_config_value(nullptr, renodx::utils::settings::global_name.c_str(), "Upgrade_SwapChainCompatibility", swapchain_setting->value); + reshade::get_config_value(nullptr, renodx::utils::settings::global_name.c_str(), "Upgrade_SwapChainCompatibility", swapchain_setting->value_as_int); renodx::mods::swapchain::swapchain_proxy_compatibility_mode = swapchain_setting->GetValue() != 0; settings.push_back(swapchain_setting); + auto* scrgb_setting = new renodx::utils::settings::Setting{ + .key = "Upgrade_UseSCRGB", + .binding = &shader_injection.processingUseSCRGB, + .value_type = renodx::utils::settings::SettingValueType::INTEGER, + .default_value = 0.f, + .label = "Swap Chain Format", + .section = "Resource Upgrades", + .tooltip = "Selects use of HDR10 or scRGB swapchain.", + .labels = { + "HDR10", + "scRGB", + }, + .is_global = true, + .is_visible = []() { return settings[0]->GetValue() >= 2; }, + }; + reshade::get_config_value(nullptr, renodx::utils::settings::global_name.c_str(), "Upgrade_UseSCRGB", scrgb_setting->value_as_int); + shader_injection.processingUseSCRGB = scrgb_setting->GetValue(); + renodx::mods::swapchain::SetUseHDR10(scrgb_setting->GetValue() == 0); + settings.push_back(scrgb_setting); + auto* lut_dump_setting = new renodx::utils::settings::Setting{ .key = "DumpLUTShaders", .binding = &g_dump_shaders, @@ -672,7 +692,7 @@ void AddAdvancedSettings() { .is_global = true, .is_visible = []() { return settings[0]->GetValue() >= 2; }, }; - reshade::get_config_value(nullptr, renodx::utils::settings::global_name.c_str(), "DumpLUTShaders", lut_dump_setting->value); + reshade::get_config_value(nullptr, renodx::utils::settings::global_name.c_str(), "DumpLUTShaders", lut_dump_setting->value_as_int); g_dump_shaders = lut_dump_setting->GetValue(); settings.push_back(lut_dump_setting); diff --git a/src/games/unrealengine/common.hlsl b/src/games/unrealengine/common.hlsl index f9cfa8ce..67edd1aa 100644 --- a/src/games/unrealengine/common.hlsl +++ b/src/games/unrealengine/common.hlsl @@ -84,9 +84,17 @@ float3 FinalizeOutput(float3 color) { color *= injectedData.toneMapUINits; color = min(color, injectedData.toneMapPeakNits); // Clamp UI or Videos - color = renodx::color::bt709::clamp::BT2020(color); + // Always clamp to BT2020 + color = renodx::color::bt2020::from::BT709(color); + color = max(0, color); + + if (injectedData.processingUseSCRGB == 1.f) { + color = renodx::color::bt709::from::BT2020(color); + color = color / 80.f; + } else { + color = renodx::color::pq::Encode(color, 1.f); + } - color /= 80.f; return color; } diff --git a/src/games/unrealengine/shared.h b/src/games/unrealengine/shared.h index 297f4185..5fdc3360 100644 --- a/src/games/unrealengine/shared.h +++ b/src/games/unrealengine/shared.h @@ -29,6 +29,7 @@ struct ShaderInjectData { float colorGradeBlowout; float colorGradeFlare; float colorGradeColorSpace; + float processingUseSCRGB; };