diff --git a/src/games/dbzspark/addon.cpp b/src/games/dbzspark/addon.cpp index 0ac5e5c2..73ba4544 100644 --- a/src/games/dbzspark/addon.cpp +++ b/src/games/dbzspark/addon.cpp @@ -63,7 +63,7 @@ renodx::utils::settings::Settings settings = { .key = "toneMapType", .binding = &shader_injection.toneMapType, .value_type = renodx::utils::settings::SettingValueType::INTEGER, - .default_value = 0.f, + .default_value = 3.f, .can_reset = true, .label = "Tone Mapper", .section = "Tone Mapping", @@ -95,7 +95,7 @@ renodx::utils::settings::Settings settings = { new renodx::utils::settings::Setting{ .key = "toneMapGameNits", .binding = &shader_injection.toneMapGameNits, - .default_value = 60.f, + .default_value = 150.f, .can_reset = true, .label = "Game Brightness", .section = "Tone Mapping", @@ -173,17 +173,6 @@ renodx::utils::settings::Settings settings = { .is_enabled = []() { return shader_injection.toneMapType != 1; }, .parse = [](float value) { return value * 0.02f; }, }, - new renodx::utils::settings::Setting{ - .key = "colorGradeBlowout", - .binding = &shader_injection.colorGradeBlowout, - .default_value = 0.f, - .label = "Blowout", - .section = "Color Grading", - .tooltip = "Controls highlight desaturation due to overexposure.", - .max = 100.f, - .is_enabled = []() { return shader_injection.toneMapType == 3; }, - .parse = [](float value) { return value * 0.01f; }, - }, new renodx::utils::settings::Setting{ .value_type = renodx::utils::settings::SettingValueType::TEXT, .label = " - Please enable Native HDR in game! \r\n - Use a low paper white with Vanilla+, and high with others! \r\n - Consider lowering peak to reduce sharp highlights", @@ -244,17 +233,16 @@ renodx::utils::settings::Settings settings = { void OnPresetOff() { renodx::utils::settings::UpdateSetting("toneMapType", 0.f); - renodx::utils::settings::UpdateSetting("toneMapDisplay", 1.f); + renodx::utils::settings::UpdateSetting("toneMapDisplay", 0.f); renodx::utils::settings::UpdateSetting("toneMapPeakNits", 400.f); renodx::utils::settings::UpdateSetting("toneMapGameNits", 60.f); renodx::utils::settings::UpdateSetting("toneMapUINits", 120.f); - renodx::utils::settings::UpdateSetting("toneMapGammaCorrection", 1.f); + renodx::utils::settings::UpdateSetting("toneMapGammaCorrection", 0.f); renodx::utils::settings::UpdateSetting("colorGradeExposure", 1.f); renodx::utils::settings::UpdateSetting("colorGradeHighlights", 50.f); 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("colorGradeBlowout", 0.f); } } // namespace diff --git a/src/games/dbzspark/colorcorrect_0x5975CAFA.ps_5_1.hlsl b/src/games/dbzspark/colorcorrect_0x5975CAFA.ps_5_1.hlsl index 5cb88bb0..0a7a0f8b 100644 --- a/src/games/dbzspark/colorcorrect_0x5975CAFA.ps_5_1.hlsl +++ b/src/games/dbzspark/colorcorrect_0x5975CAFA.ps_5_1.hlsl @@ -54,7 +54,7 @@ void main( tonemappedPQ = r1.rgb; // Hacky fix for shop - float customDecode = 203.f; + float customDecode = 0.f; r1.rgb = pqTosRGB(tonemappedPQ, customDecode, true); r0.zw = r0.xy * cb1[129].xy + cb1[128].xy; @@ -249,7 +249,7 @@ void main( post_srgb = o0.rgb; o0.w = 0; - o0.rgb = upgradeSRGBtoPQ(tonemappedPQ, post_srgb, customDecode, 1.f); + o0.rgb = upgradeSRGBtoPQ(tonemappedPQ, post_srgb, customDecode); return; } diff --git a/src/games/dbzspark/final00_0x4156562D.ps_5_1.hlsl b/src/games/dbzspark/final00_0x4156562D.ps_5_1.hlsl index 97418c71..afd307ba 100644 --- a/src/games/dbzspark/final00_0x4156562D.ps_5_1.hlsl +++ b/src/games/dbzspark/final00_0x4156562D.ps_5_1.hlsl @@ -52,7 +52,12 @@ void main( injectedData.colorGradeContrast, 1.f); // We'll do saturation post tonemap - r1.rgb = displayTonemap(r1.rgb); + if (injectedData.toneMapGammaCorrection == 1.f) { + r0.rgb = renodx::color::correct::GammaSafe(r0.rgb); + r1.rgb = renodx::color::correct::GammaSafe(r1.rgb); + } + + r0.rgb *= injectedData.toneMapUINits / 203.f; // Value found so it matches tonemapUINits r1.rgb = renodx::color::grade::UserColorGrading( r1.rgb, @@ -62,12 +67,11 @@ void main( 1.f, injectedData.colorGradeSaturation); - if (injectedData.toneMapGammaCorrection == 1.f) { - r0.rgb = renodx::color::correct::GammaSafe(r0.rgb); - r1.rgb = renodx::color::correct::GammaSafe(r1.rgb); - } + // Fix NaN + r1.rgb = renodx::color::bt709::clamp::BT709(r1.rgb); + r0.rgb = renodx::color::bt709::clamp::BT709(r0.rgb); - r0.rgb *= injectedData.toneMapUINits / 203.f; // Value found so it matches tonemapUINits + r1.rgb = displayTonemap(r1.rgb); r1.rgb = renodx::color::bt2020::from::BT709(r1.rgb); r1.rgb = renodx::color::pq::Encode(r1.rgb, injectedData.toneMapGameNits); diff --git a/src/games/dbzspark/lutbuilder_0x31FE4421.ps_5_1.hlsl b/src/games/dbzspark/lutbuilder_0x31FE4421.ps_5_1.hlsl index a8028792..2c96138b 100644 --- a/src/games/dbzspark/lutbuilder_0x31FE4421.ps_5_1.hlsl +++ b/src/games/dbzspark/lutbuilder_0x31FE4421.ps_5_1.hlsl @@ -511,6 +511,8 @@ void main( r5.rgb = max(0, r5.rgb); float3 lut_input_color = r5.rgb; + float3 lut_input_color_sdr = saturate(renoDRTSmoothClamp(lut_input_color)); + float3 post_lut_color; if (false) { @@ -522,9 +524,10 @@ void main( renodx::lut::config::type::SRGB, 16.f); - post_lut_color = renodx::lut::Sample(t0, lut_config, lut_input_color); + post_lut_color = renodx::lut::Sample(t0, lut_config, lut_input_color_sdr); } else { - r5.rgb = saturate(r5.rgb); // Better picture + r5.rgb = lut_input_color_sdr; + // r5.rgb = saturate(r5.rgb); // Better picture r1.xyz = float3(12.9200001, 12.9200001, 12.9200001) * r5.xyz; r6.xyz = cmp(r5.xyz >= float3(0.00313066994, 0.00313066994, 0.00313066994)); r5.xyz = log2(r5.xyz); @@ -557,7 +560,7 @@ void main( post_lut_color = r1.rgb; } // CustomEdit r1.rgb = post_lut_color; - r1.rgb = renodx::tonemap::UpgradeToneMap(lut_input_color, saturate(lut_input_color), r1.rgb, 1.f); + r1.rgb = renodx::tonemap::UpgradeToneMap(lut_input_color, lut_input_color_sdr, r1.rgb, 1.f); r5.xyz = r1.xyz * r1.xyz; r1.xyz = cb0[39].yyy * r1.xyz; diff --git a/src/games/dbzspark/lutbuilder_0x36E3A438.ps_5_1.hlsl b/src/games/dbzspark/lutbuilder_0x36E3A438.ps_5_1.hlsl index 71319a97..8053aa83 100644 --- a/src/games/dbzspark/lutbuilder_0x36E3A438.ps_5_1.hlsl +++ b/src/games/dbzspark/lutbuilder_0x36E3A438.ps_5_1.hlsl @@ -402,6 +402,7 @@ void main( r5.rgb = max(0, r5.rgb); float3 lut_input_color = r5.rgb; + float3 lut_input_color_sdr = saturate(renoDRTSmoothClamp(lut_input_color)); float3 post_lut_color; // It's sampling two LUTs and lerping, so we just use vanilla @@ -414,9 +415,10 @@ void main( renodx::lut::config::type::SRGB, 16.f); - post_lut_color = renodx::lut::Sample(t0, lut_config, lut_input_color); + post_lut_color = renodx::lut::Sample(t0, lut_config, lut_input_color_sdr); } else { - r5.rgb = saturate(r5.rgb); // Better picture + r5.rgb = lut_input_color_sdr; + // r5.rgb = saturate(r5.rgb); // Better picture r1.xyz = float3(12.9200001, 12.9200001, 12.9200001) * r5.xyz; r6.xyz = cmp(r5.xyz >= float3(0.00313066994, 0.00313066994, 0.00313066994)); r5.xyz = log2(r5.xyz); @@ -453,7 +455,7 @@ void main( post_lut_color = r1.rgb; } // CustomEdit r1.rgb = post_lut_color; - r1.rgb = renodx::tonemap::UpgradeToneMap(lut_input_color, saturate(lut_input_color), r1.rgb, 1.f); + r1.rgb = renodx::tonemap::UpgradeToneMap(lut_input_color, lut_input_color_sdr, r1.rgb, 1.f); r5.xyz = r1.xyz * r1.xyz; r1.xyz = cb0[39].yyy * r1.xyz; diff --git a/src/games/dbzspark/lutbuilder_0xC2A711CC.ps_5_1.hlsl b/src/games/dbzspark/lutbuilder_0xC2A711CC.ps_5_1.hlsl index ba551bb6..658b1f6f 100644 --- a/src/games/dbzspark/lutbuilder_0xC2A711CC.ps_5_1.hlsl +++ b/src/games/dbzspark/lutbuilder_0xC2A711CC.ps_5_1.hlsl @@ -397,6 +397,8 @@ void main( r5.rgb = max(0, r5.rgb); float3 lut_input_color = r5.rgb; + float3 lut_input_color_sdr = saturate(renoDRTSmoothClamp(r5.rgb)); + float3 post_lut_color; // Vanilla sampler looks better @@ -409,9 +411,10 @@ void main( renodx::lut::config::type::SRGB, 16.f); - post_lut_color = renodx::lut::Sample(t0, lut_config, lut_input_color); + post_lut_color = renodx::lut::Sample(t0, lut_config, lut_input_color_sdr); } else { - r5.rgb = saturate(r5.rgb); // Better picture + r5.rgb = lut_input_color_sdr; + // r5.rgb = saturate(r5.rgb); // Better picture r1.xyz = float3(12.9200001, 12.9200001, 12.9200001) * r5.xyz; r6.xyz = cmp(r5.xyz >= float3(0.00313066994, 0.00313066994, 0.00313066994)); r5.xyz = log2(r5.xyz); @@ -443,7 +446,7 @@ void main( post_lut_color = r1.rgb; } // CustomEdit r1.rgb = post_lut_color; - r1.rgb = renodx::tonemap::UpgradeToneMap(lut_input_color, saturate(lut_input_color), r1.rgb, 1.f); + r1.rgb = renodx::tonemap::UpgradeToneMap(lut_input_color, lut_input_color_sdr, r1.rgb, 1.f); r5.xyz = r1.xyz * r1.xyz; r1.xyz = cb0[39].yyy * r1.xyz; diff --git a/src/games/dbzspark/shared.h b/src/games/dbzspark/shared.h index 7376fdb1..c33d9287 100644 --- a/src/games/dbzspark/shared.h +++ b/src/games/dbzspark/shared.h @@ -19,7 +19,6 @@ struct ShaderInjectData { float colorGradeShadows; float colorGradeContrast; float colorGradeSaturation; - float colorGradeBlowout; }; #ifndef __cplusplus @@ -27,10 +26,10 @@ cbuffer injectedBuffer : register(b0, space50) { ShaderInjectData injectedData : packoffset(c0); } /* static const ShaderInjectData injectedData = { - 0.f, // toneMapType + 3.f, // toneMapType 1.f, // toneMapDisplay - 300.f, // toneMapPeakNits - 60.f, // toneMapGameNits + 500.f, // toneMapPeakNits + 150.f, // toneMapGameNits 120.f, // toneMapUINits 1.f, // toneMapGammaCorrection 1.f, // colorGradeExposure @@ -38,7 +37,6 @@ cbuffer injectedBuffer : register(b0, space50) { 1.f, // colorGradeShadows 1.f, // colorGradeContrast 1.f, // colorGradeSaturation - 0.f, // colorGradeBlowout }; */ #endif diff --git a/src/games/dbzspark/tonemapper.hlsl b/src/games/dbzspark/tonemapper.hlsl index 2db899b5..192246b7 100644 --- a/src/games/dbzspark/tonemapper.hlsl +++ b/src/games/dbzspark/tonemapper.hlsl @@ -13,7 +13,6 @@ renodx::tonemap::Config getCommonConfig() { float renoDRTContrast = 1.f; float renoDRTFlare = 0.f; float renoDRTShadows = 1.f; - float renoDRTDechroma = injectedData.colorGradeBlowout; float renoDRTSaturation = 1.f; float renoDRTHighlights = 1.f; @@ -22,12 +21,11 @@ renodx::tonemap::Config getCommonConfig() { config.peak_nits = injectedData.toneMapPeakNits; config.game_nits = injectedData.toneMapGameNits; config.gamma_correction = injectedData.toneMapGammaCorrection; + config.saturation = renoDRTSaturation; + config.highlights = renoDRTHighlights; + config.shadows = renoDRTShadows; + config.contrast = renoDRTContrast; - config.reno_drt_highlights = renoDRTHighlights; - config.reno_drt_shadows = renoDRTShadows; - config.reno_drt_contrast = renoDRTContrast; - config.reno_drt_saturation = renoDRTSaturation; - config.reno_drt_dechroma = renoDRTDechroma; config.mid_gray_value = vanillaMidGray; config.mid_gray_nits = vanillaMidGray * 100.f; config.reno_drt_flare = renoDRTFlare; @@ -35,11 +33,44 @@ renodx::tonemap::Config getCommonConfig() { return config; } +/// Applies a customized version of RenoDRT tonemapper that tonemaps down to 1.0. +/// This function is used to compress HDR color to SDR range for use alongside `UpgradeToneMap`. +/// +/// @param lutInputColor The color input that needs to be tonemapped. +/// @return The tonemapped color compressed to the SDR range, ensuring that it can be applied to SDR color grading with `UpgradeToneMap`. +float3 renoDRTSmoothClamp(float3 untonemapped) { + renodx::tonemap::renodrt::Config renodrt_config = renodx::tonemap::renodrt::config::Create(); + renodrt_config.nits_peak = 100.f; + renodrt_config.mid_gray_value = 0.18f; + renodrt_config.mid_gray_nits = 18.f; + renodrt_config.exposure = 1.f; + renodrt_config.highlights = 1.f; + renodrt_config.shadows = 1.f; + renodrt_config.contrast = 1.f; + renodrt_config.saturation = 1.04f; + renodrt_config.dechroma = 0.f; + renodrt_config.flare = 0.f; + // renodrt_config.hue_correction_strength = 1.f; + renodrt_config.hue_correction_source = renodx::tonemap::uncharted2::BT709(untonemapped); + renodrt_config.hue_correction_method = renodx::tonemap::renodrt::config::hue_correction_method::OKLAB; + renodrt_config.tone_map_method = renodx::tonemap::renodrt::config::tone_map_method::DANIELE; + renodrt_config.hue_correction_type = renodx::tonemap::renodrt::config::hue_correction_type::INPUT; + renodrt_config.per_channel = false; + + float3 renoDRTColor = renodx::tonemap::renodrt::BT709(untonemapped, renodrt_config); + renoDRTColor = lerp(untonemapped, renoDRTColor, saturate(renodx::color::y::from::BT709(untonemapped) / renodrt_config.mid_gray_value)); + // renoDRTColor = renodx::tonemap::UpgradeToneMap(untonemapped, saturate(untonemapped), renoDRTColor, saturate(renodx::color::y::from::BT709(untonemapped) / renodrt_config.mid_gray_value)); + // renoDRTColor = renodx::tonemap::UpgradeToneMap(untonemapped, saturate(untonemapped), renoDRTColor, 1.f); + + return renoDRTColor; +} + // Here so we have a central function once we figure out a better way float3 clampForSRGB(float3 color) { // clamp so colors don't go NaN, and didn't want to clamp to 1 // value derived from testing main menu - return min(float3(1.f, 1.f, 1.f) * 10.f, color); + // return min(float3(1.f, 1.f, 1.f) * 10.f, color); + return renoDRTSmoothClamp(color); } // input is always PQ, even for vanilla+ @@ -73,7 +104,7 @@ float3 upgradeSRGBtoPQ(float3 tonemapped, float3 post_srgb, float customDecode = post = renodx::color::srgb::Decode(post); output = renodx::tonemap::UpgradeToneMap(hdr, saturate(hdr), post, strength); - output = renodx::color::bt2020::from::BT709(output); // Maybe change this to post + output = renodx::color::bt2020::from::BT709(output); output = renodx::color::pq::Encode(output, customDecode != 0.f ? customDecode : injectedData.toneMapGameNits); }