Skip to content

Commit

Permalink
feat(ff7remake): add blowout and hdr videos
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Dec 20, 2024
1 parent cb5bf57 commit 2ea275c
Show file tree
Hide file tree
Showing 5 changed files with 596 additions and 215 deletions.
41 changes: 23 additions & 18 deletions src/games/ff7remake/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define ImTextureID ImU64

#define DEBUG_LEVEL_0

#define NOMINMAX

#include <chrono>
Expand All @@ -26,6 +25,7 @@ namespace {
renodx::mods::shader::CustomShaders custom_shaders = {
CustomShaderEntry(0x922A71D1),
CustomShaderEntry(0x4D6F937E),
CustomShaderEntry(0xD950DA01),
};

ShaderInjectData shader_injection;
Expand Down Expand Up @@ -99,7 +99,7 @@ renodx::utils::settings::Settings settings = {
.key = "ToneMapHueCorrectionMethod",
.binding = &shader_injection.tone_map_hue_correction_method,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 3.f,
.default_value = 0.f,
.label = "Hue Correction Method",
.section = "Tone Mapping",
.tooltip = "Applies hue shift emulation before tonemapping",
Expand All @@ -110,7 +110,7 @@ renodx::utils::settings::Settings settings = {
new renodx::utils::settings::Setting{
.key = "ToneMapHueCorrection",
.binding = &shader_injection.tone_map_hue_correction,
.default_value = 100.f,
.default_value = 0.f,
.label = "Hue Correction",
.section = "Tone Mapping",
.tooltip = "Hue shifts emulation strength.",
Expand All @@ -131,7 +131,6 @@ renodx::utils::settings::Settings settings = {
.labels = {"Off", "On"},
.is_enabled = []() { return shader_injection.tone_map_type == 3; },
},

new renodx::utils::settings::Setting{
.key = "ColorGradeExposure",
.binding = &shader_injection.color_grade_exposure,
Expand Down Expand Up @@ -186,7 +185,7 @@ renodx::utils::settings::Settings settings = {
.tooltip = "Controls highlight desaturation due to overexposure.",
.max = 100.f,
.is_enabled = []() { return shader_injection.tone_map_type == 3; },
.parse = [](float value) { return value * 0.01f; },
.parse = [](float value) { return value * 0.02f - 1.f; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeFlare",
Expand All @@ -206,17 +205,12 @@ renodx::utils::settings::Settings settings = {
.default_value = 0.f,
.label = "Color Space",
.section = "Color Grading",
.tooltip = "Selects output color space"
.tooltip = "Selects grading color space"
"\nUS Modern for BT.709 D65."
"\nJPN Modern for BT.709 D93."
"\nUS CRT for BT.601 (NTSC-U)."
"\nJPN CRT for BT.601 ARIB-TR-B09 D93 (NTSC-J)."
"\nDefault: US CRT",
"\nJPN Modern for BT.709 D93.",
.labels = {
"US Modern",
"JPN Modern",
"US CRT",
"JPN CRT",
},
},
new renodx::utils::settings::Setting{
Expand Down Expand Up @@ -255,6 +249,16 @@ renodx::utils::settings::Settings settings = {
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "FXHDRVideos",
.binding = &shader_injection.fx_hdr_videos,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 0.f,
.label = "HDR Videos",
.section = "Effects",
.tooltip = "Uses modified BT.2446a to inverse tonemap SDR videos",
.labels = {"Off", "On"},
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::BUTTON,
.label = "Discord",
Expand Down Expand Up @@ -286,18 +290,19 @@ void OnPresetOff() {
renodx::utils::settings::UpdateSetting("ToneMapHueCorrectionMethod", 0.f);
renodx::utils::settings::UpdateSetting("ToneMapHueCorrection", 0.f);
renodx::utils::settings::UpdateSetting("ToneMapPerChannel", 0.f);
renodx::utils::settings::UpdateSetting("ColorGradeExposure", 1.f);
renodx::utils::settings::UpdateSetting("ColorGradeHighlights", 1.f);
renodx::utils::settings::UpdateSetting("ColorGradeShadows", 1.f);
renodx::utils::settings::UpdateSetting("ColorGradeContrast", 1.f);
renodx::utils::settings::UpdateSetting("ColorGradeSaturation", 1.f);
renodx::utils::settings::UpdateSetting("ColorGradeExposure", 50.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", 50.f);
renodx::utils::settings::UpdateSetting("ColorGradeColorSpace", 0.f);
renodx::utils::settings::UpdateSetting("ColorGradeFlare", 50.f);
renodx::utils::settings::UpdateSetting("ColorGradeColorSpace", 0.f);
renodx::utils::settings::UpdateSetting("ColorGradeLutStrength", 100.f);
renodx::utils::settings::UpdateSetting("FXBloom", 50.f);
renodx::utils::settings::UpdateSetting("FXVignette", 50.f);
renodx::utils::settings::UpdateSetting("FXFilmGrain", 0.f);
renodx::utils::settings::UpdateSetting("FXHDRVideos", 0.f);
}

bool fired_on_init_swapchain = false;
Expand Down
154 changes: 154 additions & 0 deletions src/games/ff7remake/common.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#ifndef SRC_FF7REMAKE_COMMON_HLSL_
#define SRC_FF7REMAKE_COMMON_HLSL_

#include "./shared.h"

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.05f;
renodrt_config.saturation = 1.05f;
renodrt_config.dechroma = 0.f;
renodrt_config.flare = 0.f;
renodrt_config.hue_correction_strength = 0.f;
renodrt_config.tone_map_method =
renodx::tonemap::renodrt::config::tone_map_method::DANIELE;
renodrt_config.working_color_space = 2u;

return renodx::tonemap::renodrt::BT709(untonemapped, renodrt_config);
}

float UpgradeToneMapRatio(float ap1_color_hdr, float ap1_color_sdr, float ap1_post_process_color) {
if (ap1_color_hdr < ap1_color_sdr) {
// If substracting (user contrast or paperwhite) scale down instead
// Should only apply on mismatched HDR
return ap1_color_hdr / ap1_color_sdr;
} else {
float ap1_delta = ap1_color_hdr - ap1_color_sdr;
ap1_delta = max(0, ap1_delta); // Cleans up NaN
const float ap1_new = ap1_post_process_color + ap1_delta;

const bool ap1_valid = (ap1_post_process_color > 0); // Cleans up NaN and ignore black
return ap1_valid ? (ap1_new / ap1_post_process_color) : 0;
}
}
float3 UpgradeToneMapPerChannel(float3 color_hdr, float3 color_sdr, float3 post_process_color, float post_process_strength) {
// float ratio = 1.f;

float3 ap1_hdr = max(0, renodx::color::ap1::from::BT709(color_hdr));
float3 ap1_sdr = max(0, renodx::color::ap1::from::BT709(color_sdr));
float3 ap1_post_process = max(0, renodx::color::ap1::from::BT709(post_process_color));

float3 ratio = float3(
UpgradeToneMapRatio(ap1_hdr.r, ap1_sdr.r, ap1_post_process.r),
UpgradeToneMapRatio(ap1_hdr.g, ap1_sdr.g, ap1_post_process.g),
UpgradeToneMapRatio(ap1_hdr.b, ap1_sdr.b, ap1_post_process.b));

float3 color_scaled = max(0, ap1_post_process * ratio);
color_scaled = renodx::color::bt709::from::AP1(color_scaled);
float peak_correction = saturate(1.f - renodx::color::y::from::AP1(ap1_post_process));
color_scaled = renodx::color::correct::Hue(color_scaled, post_process_color, peak_correction);
return lerp(color_hdr, color_scaled, post_process_strength);
}

float3 ToneMap(float3 color, float2 position) {
color *= 1.0f;

renodx::tonemap::Config config = renodx::tonemap::config::Create();
config.type = injectedData.tone_map_type;
config.peak_nits = injectedData.tone_map_peak_nits;
config.game_nits = injectedData.tone_map_game_nits;
config.gamma_correction = injectedData.tone_map_gamma_correction;
config.exposure = injectedData.color_grade_exposure;
config.highlights = injectedData.color_grade_highlights;
config.shadows = injectedData.color_grade_shadows;
config.contrast = injectedData.color_grade_contrast;
config.saturation = injectedData.color_grade_saturation;

config.reno_drt_highlights = 1.20f;
config.reno_drt_shadows = 1.0f;
config.reno_drt_contrast = 1.1f;
config.reno_drt_saturation = 1.0f;
config.reno_drt_dechroma = 0; // 0.80f; // 0.80f
config.reno_drt_blowout = injectedData.color_grade_blowout;
config.reno_drt_flare = 0.10 * injectedData.color_grade_flare;
config.reno_drt_working_color_space = 2u;
config.reno_drt_per_channel = injectedData.tone_map_per_channel != 0;

// config.reno_drt_highlights = 1.00f;
// config.reno_drt_shadows = 1.0f;
// config.reno_drt_contrast = 2.0f;
// config.reno_drt_saturation = 3.0f * .73 * 2.f;
// config.reno_drt_dechroma = 2.f * 0.472f * 2.f * injectedData.colorGradeBlowout;
// config.reno_drt_flare = 0.f;

config.reno_drt_hue_correction_method = (uint)injectedData.tone_map_hue_processor;

config.hue_correction_type =
renodx::tonemap::config::hue_correction_type::CUSTOM;
config.hue_correction_strength = injectedData.tone_map_hue_correction;
config.hue_correction_color = color;
if (injectedData.tone_map_hue_correction_method == 1.f) {
config.hue_correction_color = renodx::tonemap::ACESFittedAP1(color);
} else if (injectedData.tone_map_hue_correction_method == 2.f) {
config.hue_correction_color = renodx::tonemap::uncharted2::BT709(color * 2.f);
} else if (injectedData.tone_map_hue_correction_method == 3.f) {
config.hue_correction_color = RenoDRTSmoothClamp(color);
} else {
config.hue_correction_type =
renodx::tonemap::config::hue_correction_type::INPUT;
}

color = renodx::tonemap::config::Apply(color, config);

if (injectedData.color_grade_color_space == 1.f) {
// BT709 D65 => BT709 D93
color = mul(float3x3(0.941922724f, -0.0795196890f, -0.0160709824f,
0.00374091602f, 1.01361334f, -0.00624059885f,
0.00760519271f, 0.0278747007f, 1.30704438f),
color);
} else if (injectedData.color_grade_color_space == 2.f) {
// BT.709 D65 => BT.601 (NTSC-U)
color = mul(float3x3(0.939542055f, 0.0501813553f, 0.0102765792f,
0.0177722238f, 0.965792834f, 0.0164349135f,
-0.00162159989f, -0.00436974968f, 1.00599133f),
color);
} else if (injectedData.color_grade_color_space == 3.f) {
// BT.709 D65 => ARIB-TR-B09 D93 (NTSC-J)
color = mul(float3x3(0.871554791f, -0.161164566f, -0.0151899587f,
0.0417598634f, 0.980491757f, -0.00258531118f,
0.00544220115f, 0.0462860465f, 1.73763155f),
color);
}

if (injectedData.tone_map_gamma_correction == 1) {
color = renodx::color::correct::GammaSafe(color);
} else if (injectedData.tone_map_gamma_correction == 2) {
color = renodx::color::correct::GammaSafe(color, false, 2.4f);
}

if (injectedData.fx_film_grain != 0) {
color = renodx::effects::ApplyFilmGrainColored(
color.rgb,
position.xy,
float3(
injectedData.random_1,
injectedData.random_2,
injectedData.random_3),
injectedData.fx_film_grain * 0.01f,
1.f);
}

color = renodx::color::bt2020::from::BT709(color);

color = max(0, color);
return color * injectedData.tone_map_game_nits;
}

#endif // SRC_FF7REMAKE_COMMON_HLSL_
Loading

0 comments on commit 2ea275c

Please sign in to comment.