From 500c418e3b9e03bb3c8f72b9afd6e108ad857c07 Mon Sep 17 00:00:00 2001 From: marat569 Date: Sat, 11 Jan 2025 22:28:15 -0500 Subject: [PATCH] [MULTIPLE] Add JPN ColorSpace - YS10 + Daybreak 1, add JPN colorspace - Daybreak 1 -- increase stability --- src/games/trailsdaybreak1/addon.cpp | 65 +++++++++---------- .../final_0xAD51B4B0.ps_5_0.hlsl | 13 ++-- src/games/trailsdaybreak1/shared.h | 1 + src/games/trailsdaybreak1/tonemapper.hlsl | 28 ++++---- src/games/ys10/addon.cpp | 17 ++++- src/games/ys10/final_0xAD51B4B0.ps_5_0.hlsl | 4 ++ src/games/ys10/shared.h | 1 + 7 files changed, 77 insertions(+), 52 deletions(-) diff --git a/src/games/trailsdaybreak1/addon.cpp b/src/games/trailsdaybreak1/addon.cpp index a827360f..06b19ff7 100644 --- a/src/games/trailsdaybreak1/addon.cpp +++ b/src/games/trailsdaybreak1/addon.cpp @@ -7,7 +7,7 @@ #define DEBUG_LEVEL_0 -// #define DEBUG_LEVEL_1 //added +// #define DEBUG_LEVEL_1 // added #include //ui -- overworld hud @@ -134,9 +134,25 @@ renodx::utils::settings::Settings settings = { .parse = [](float value) { return value * 0.02f; }, }, + new renodx::utils::settings::Setting{ + .key = "ColorGradeColorSpace", + .binding = &shader_injection.ColorGradeColorSpace, + .value_type = renodx::utils::settings::SettingValueType::INTEGER, + .default_value = 0.f, + .label = "Color Space", + .section = "Color Grading", + .tooltip = "Selects output color space" + "\nUS Modern for BT.709 D65." + "\nJPN Modern for BT.709 D93.", + .labels = { + "US Modern", + "JPN Modern", + }, + }, + new renodx::utils::settings::Setting{ .value_type = renodx::utils::settings::SettingValueType::TEXT, - .label = " - Please enable Native HDR in game! \r\n - Use the game's UI slider to control the UI! \r\n - This mod is still in beta, please report issues on Discord!", + .label = " - Please enable Native HDR in game! \r\n - Use the game's UI slider to control the UI! \r\n - FXAA/Anti-Aliasing High does not work, use anything else \r\n - MSAA/SGSSAA has very high VRAM usage \r\n - This mod is still in beta, please report issues on Discord!", .section = "Instructions", }, @@ -182,6 +198,8 @@ void OnPresetOff() { renodx::utils::settings::UpdateSetting("colorGradeShadows", 50.f); renodx::utils::settings::UpdateSetting("colorGradeContrast", 50.f); renodx::utils::settings::UpdateSetting("colorGradeSaturation", 50.f); + renodx::utils::settings::UpdateSetting("ColorGradeColorSpace", 0.f); + // Start PostProcess effects on/off } @@ -190,7 +208,7 @@ void OnPresetOff() { // NOLINTBEGIN(readability-identifier-naming) extern "C" __declspec(dllexport) const char* NAME = "RenoDX"; -extern "C" __declspec(dllexport) const char* DESCRIPTION = "RenoDX for The Legend of Heroes Trails through Daybreak"; +extern "C" __declspec(dllexport) const char* DESCRIPTION = "RenoDX for The Legend of Heroes Trails through Daybreak 1"; // NOLINTEND(readability-identifier-naming) @@ -207,45 +225,26 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) { renodx::mods::swapchain::force_borderless = false; // needed for stability renodx::mods::swapchain::prevent_full_screen = false; // needed for stability - // RGBA8_UNORM + // We don't really need to upgrade + // Upgrades cause artifacts; might be a to-do in the future + // Upgrades would fix FXAA + + // // RGBA8_UNORM // renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({ // .old_format = reshade::api::format::r8g8b8a8_unorm, // .new_format = reshade::api::format::r16g16b16a16_float, // }); - // RGBA8_UNORM 512x512 + // // r8g8b8a8_unorm -- new usage_include -- looks good, but game hangs // renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({ // .old_format = reshade::api::format::r8g8b8a8_unorm, // .new_format = reshade::api::format::r16g16b16a16_float, - // .dimensions = {512, 512}, - // }); + // .ignore_size = true, + // .use_resource_view_cloning = true, + // .use_resource_view_hot_swap = true, + // .usage_include = reshade::api::resource_usage::render_target | reshade::api::resource_usage::unordered_access, - // r8g8b8a8_unorm -- view upgrades - renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({ - .old_format = reshade::api::format::r8g8b8a8_unorm, - .new_format = reshade::api::format::r16g16b16a16_float, - .ignore_size = true, - .use_resource_view_cloning = true, - .use_resource_view_hot_swap = true, - .usage_include = reshade::api::resource_usage::render_target | reshade::api::resource_usage::unordered_access, - }); - - // // r8g8b8a8_unorm -- view upgrades - // renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({.old_format = reshade::api::format::r8g8b8a8_unorm, - // .new_format = reshade::api::format::r16g16b16a16_float, - // .ignore_size = true, - // .usage_include = reshade::api::resource_usage::render_target | reshade::api::resource_usage::unordered_access, - // .view_upgrades = { - // {{reshade::api::resource_usage::shader_resource, - // reshade::api::format::r8g8b8a8_unorm}, - // reshade::api::format::r16g16b16a16_float}, - // {{reshade::api::resource_usage::unordered_access, - // reshade::api::format::r8g8b8a8_unorm}, - // reshade::api::format::r16g16b16a16_float}, - // {{reshade::api::resource_usage::render_target, - // reshade::api::format::r8g8b8a8_unorm}, - // reshade::api::format::r16g16b16a16_float}, - // }}); + // }); // R11G11B10 // renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({.old_format = reshade::api::format::r11g11b10_float, diff --git a/src/games/trailsdaybreak1/final_0xAD51B4B0.ps_5_0.hlsl b/src/games/trailsdaybreak1/final_0xAD51B4B0.ps_5_0.hlsl index babe1d39..bada506e 100644 --- a/src/games/trailsdaybreak1/final_0xAD51B4B0.ps_5_0.hlsl +++ b/src/games/trailsdaybreak1/final_0xAD51B4B0.ps_5_0.hlsl @@ -18,9 +18,9 @@ Texture2D tex : register(t0); #define cmp - void main( - float4 v0: SV_Position0, - float2 v1: TEXCOORD0, - out float4 o0: SV_Target0) { + float4 v0 : SV_Position0, + float2 v1 : TEXCOORD0, + out float4 o0 : SV_Target0) { float4 r0; uint4 bitmask, uiDest; float4 fDest; @@ -29,7 +29,12 @@ void main( r0.rgb = injectedData.gamma ? renodx::math::PowSafe(r0.rgb, 2.3f) : renodx::math::PowSafe(r0.rgb, 2.2f); // The game does 2.3 gamma default - r0.rgb = applyUserTonemap(r0.rgb); // Send our color to tonemapper.hlsl to get processed! + r0.rgb = applyUserTonemap(r0.rgb); // Send our color to tonemapper.hlsl to get processed! + + if (injectedData.ColorGradeColorSpace == 1.f) { + r0.rgb = renodx::color::bt709::from::BT709D93(r0.rgb); + } + r0.rgb *= injectedData.toneMapGameNits / 80.f; // paper white o0.rgb = r0.rgb; diff --git a/src/games/trailsdaybreak1/shared.h b/src/games/trailsdaybreak1/shared.h index e22c9b36..e7a6fd50 100644 --- a/src/games/trailsdaybreak1/shared.h +++ b/src/games/trailsdaybreak1/shared.h @@ -19,6 +19,7 @@ struct ShaderInjectData { float colorGradeSaturation; float gamma; float toneMapHueCorrection; + float ColorGradeColorSpace; }; #ifndef __cplusplus diff --git a/src/games/trailsdaybreak1/tonemapper.hlsl b/src/games/trailsdaybreak1/tonemapper.hlsl index 68fc7b44..72129b3c 100644 --- a/src/games/trailsdaybreak1/tonemapper.hlsl +++ b/src/games/trailsdaybreak1/tonemapper.hlsl @@ -14,8 +14,8 @@ float3 applyUserTonemap(float3 untonemapped) { } if (injectedData.toneMapType != 0) { // UserColorGrading, pre-tonemap - outputColor.rgb = renodx::color::grade::UserColorGrading( - outputColor.rgb, + outputColor = renodx::color::grade::UserColorGrading( + outputColor, injectedData.colorGradeExposure, // exposure injectedData.colorGradeHighlights, // highlights injectedData.colorGradeShadows, // shadows @@ -38,7 +38,7 @@ float3 applyUserTonemap(float3 untonemapped) { } else if (injectedData.toneMapType == 3.f) { // baby reinhard float ReinhardPeak = injectedData.toneMapPeakNits / injectedData.toneMapGameNits; - outputColor.rgb = renodx::tonemap::ReinhardScalable(outputColor.rgb, ReinhardPeak); + outputColor = renodx::tonemap::ReinhardScalable(outputColor, ReinhardPeak); } else if (injectedData.toneMapType == 4.f) { // Frostbite float frostbitePeak = injectedData.toneMapPeakNits / injectedData.toneMapGameNits; @@ -46,19 +46,19 @@ float3 applyUserTonemap(float3 untonemapped) { } if (injectedData.toneMapType != 0) { // UserColorGrading, post-tonemap - outputColor.rgb = renodx::color::grade::UserColorGrading( - outputColor.rgb, - 1.f, // exposure - 1.f, // highlights - 1.f, // shadows - 1.f, // contrast - injectedData.colorGradeSaturation, // saturation - 0.f, // dechroma, we don't need it - injectedData.toneMapHueCorrection, // Hue Correction - renodx::tonemap::Reinhard(untonemapped)); + outputColor = renodx::color::grade::UserColorGrading( + outputColor, + 1.f, // exposure + 1.f, // highlights + 1.f, // shadows + 1.f, // contrast + injectedData.colorGradeSaturation, // saturation + 0.f, // dechroma, we don't need it + injectedData.toneMapHueCorrection, // Hue Correction Strength + renodx::tonemap::Reinhard(untonemapped)); // Hue Correction Type } - outputColor = renodx::color::bt709::clamp::BT2020(outputColor); // Clamp to BT2020 to avoid negative colorsF + outputColor = renodx::color::bt709::clamp::BT2020(outputColor); // Clamp to BT2020 to avoid negative colors return outputColor; } \ No newline at end of file diff --git a/src/games/ys10/addon.cpp b/src/games/ys10/addon.cpp index eeea1ec1..0e373f61 100644 --- a/src/games/ys10/addon.cpp +++ b/src/games/ys10/addon.cpp @@ -20,7 +20,6 @@ #include "../../utils/settings.hpp" #include "./shared.h" - namespace { renodx::mods::shader::CustomShaders custom_shaders = { @@ -124,6 +123,22 @@ renodx::utils::settings::Settings settings = { .parse = [](float value) { return value * 0.02f; }, }, + new renodx::utils::settings::Setting{ + .key = "ColorGradeColorSpace", + .binding = &shader_injection.ColorGradeColorSpace, + .value_type = renodx::utils::settings::SettingValueType::INTEGER, + .default_value = 0.f, + .label = "Color Space", + .section = "Color Grading", + .tooltip = "Selects output color space" + "\nUS Modern for BT.709 D65." + "\nJPN Modern for BT.709 D93.", + .labels = { + "US Modern", + "JPN Modern", + }, + }, + new renodx::utils::settings::Setting{ .value_type = renodx::utils::settings::SettingValueType::TEXT, .label = " - Please enable Native HDR in game! \r\n - Use the game's UI slider to control the UI!", diff --git a/src/games/ys10/final_0xAD51B4B0.ps_5_0.hlsl b/src/games/ys10/final_0xAD51B4B0.ps_5_0.hlsl index 01f464df..8149a04c 100644 --- a/src/games/ys10/final_0xAD51B4B0.ps_5_0.hlsl +++ b/src/games/ys10/final_0xAD51B4B0.ps_5_0.hlsl @@ -32,6 +32,10 @@ void main( r0.rgb = applyUserTonemap(r0.rgb); // Send our color to tonemapper.hlsl to get processed! r0.rgb *= injectedData.toneMapGameNits / 80.f; // paper white + if (injectedData.ColorGradeColorSpace == 1.f) { + r0.rgb = renodx::color::bt709::from::BT709D93(r0.rgb); + } + o0.rgb = r0.rgb; o0.w = 1; return; diff --git a/src/games/ys10/shared.h b/src/games/ys10/shared.h index 43416c9b..437ff63a 100644 --- a/src/games/ys10/shared.h +++ b/src/games/ys10/shared.h @@ -18,6 +18,7 @@ struct ShaderInjectData { float colorGradeContrast; float colorGradeSaturation; float gamma; + float ColorGradeColorSpace; }; #ifndef __cplusplus