Skip to content

Commit

Permalink
feat(ffx): correct bt2446a and color spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Dec 5, 2024
1 parent 6462f78 commit 4070ecf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
31 changes: 14 additions & 17 deletions src/games/ffx/06_video_0xA3657554.ps_4_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ Texture2D<float4> VChannel : register(t2);
// 3Dmigoto declarations
#define cmp -

void main(
float4 v0: SV_POSITION0,
float2 v1: TEXCOORD0,
out float4 o0: SV_TARGET0) {
void main(float4 v0 : SV_POSITION0, float2 v1 : TEXCOORD0,
out float4 o0 : SV_TARGET0) {
float4 r0, r1, r2;
uint4 bitmask, uiDest;
float4 fDest;
Expand All @@ -27,22 +25,21 @@ void main(
r1.x = r0.x;
r1.y = r2.x;
r1.w = 1;
o0.y = saturate(dot(float4(1, -0.344000012, -0.713999987, 0.528999984), r1.xyzw));
o0.y = saturate(
dot(float4(1, -0.344000012, -0.713999987, 0.528999984), r1.xyzw));
o0.x = saturate(dot(float3(1, 1.40199995, -0.700999975), r1.xzw));
o0.z = saturate(dot(float3(1, 1.77199996, -0.885999978), r1.xyw));

if (injectedData.toneMapType == 0.f) return;
o0.rgb = renodx::color::srgb::Decode(o0.rgb);

float videoPeak = injectedData.toneMapPeakNits / (injectedData.toneMapGameNits / 203.f);
o0.rgb = renodx::tonemap::inverse::bt2446a::BT709(o0.rgb, 100.f, videoPeak);
o0.rgb /= videoPeak; // Normalize to 1.0f = peak;

// o0.rgb = 1.f;

o0.rgb *= injectedData.toneMapPeakNits / injectedData.toneMapGameNits;

o0.rgb = PostToneMapScale(o0.rgb);
if (injectedData.toneMapType != 0.f) {
float videoPeak =
injectedData.toneMapPeakNits / (injectedData.toneMapGameNits / 203.f);
o0.rgb = renodx::color::gamma::Decode(o0.rgb, 2.4f); // 2.4 for BT2446a
o0.rgb = renodx::tonemap::inverse::bt2446a::BT709(o0.rgb, 100.f, videoPeak);
o0.rgb /= videoPeak; // Normalize to 1.0f = peak;
o0.rgb *= injectedData.toneMapPeakNits /
injectedData.toneMapGameNits; // 1.f = game nits
}
o0.rgb = PostToneMapScale(o0.rgb); // Gamma Correct

return;
}
24 changes: 12 additions & 12 deletions src/games/ffx/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
#define DEBUG_LEVEL_0

#include <deps/imgui/imgui.h>
#include <embed/0x04FDEDF9.h>
#include <embed/0x2BBD74AD.h>
#include <embed/0x4DC74060.h>
#include <embed/0x6DCD7321.h>
#include <embed/0x90C53F9F.h>
#include <embed/0xA3657554.h>
#include <embed/0xB8F57CD5.h>
#include <embed/0xC605FBD5.h>
#include <embed/shaders.h>
#include <include/reshade.hpp>

#include "../../mods/shader.hpp"
Expand All @@ -34,6 +27,7 @@ renodx::mods::shader::CustomShaders custom_shaders = {
CustomShaderEntry(0x2BBD74AD),
CustomShaderEntry(0xC605FBD5),
CustomShaderEntry(0x90C53F9F),
CustomShaderEntry(0x77AB75A9),
};

ShaderInjectData shader_injection;
Expand Down Expand Up @@ -172,19 +166,24 @@ renodx::utils::settings::Settings settings = {
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "colorColorSpace",
.key = "colorGradeColorSpace",
.binding = &shader_injection.colorGradeColorSpace,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "Color Space",
.section = "Color Grading",
.tooltip = "Selects output color space"
"\nModern for BT.709."
"\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)."
"\nJPN Conusmer CRT for ARIB-TR-B09 9300K 27 MPCD (NTSC-J)."
"\nDefault: US CRT",
.labels = {"Modern", "US CRT", "JPN CRT", "JPN Consumer CRT "},
.labels = {
"US Modern",
"JPN Modern",
"US CRT",
"JPN CRT",
},

},
new renodx::utils::settings::Setting{
Expand Down Expand Up @@ -223,6 +222,7 @@ void OnPresetOff() {
renodx::utils::settings::UpdateSetting("colorGradeBlowout", 0.f);
renodx::utils::settings::UpdateSetting("colorGradeLUTStrength", 100.f);
renodx::utils::settings::UpdateSetting("colorGradeLUTScaling", 0.f);
renodx::utils::settings::UpdateSetting("colorGradeColorSpace", 0.f);
}

bool fired_on_init_swapchain = false;
Expand Down
26 changes: 11 additions & 15 deletions src/games/ffx/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,26 @@ float3 FinalizeOutput(float3 color) {
color = min(color, injectedData.toneMapPeakNits); // Clamp UI or Videos

if (injectedData.colorGradeColorSpace == 3.f) {
color = mul(float3x3(
0.742944359f, -0.243619307f, -0.0135331172f,
0.0414674095f, 1.06642627f, 0.00159343972f,
0.00323979160f, 0.0367207527f, 1.47409546f),
color);
} else if (injectedData.colorGradeColorSpace == 2.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);
} else if (injectedData.colorGradeColorSpace == 1.f) {
} else if (injectedData.colorGradeColorSpace == 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.colorGradeColorSpace == 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);
}

color /= 80.f; // or PQ
Expand All @@ -66,17 +69,10 @@ float3 RenoDRTSmoothClamp(float3 untonemapped) {
renodrt_config.dechroma = 0.f;
renodrt_config.flare = 0.f;
renodrt_config.hue_correction_strength = 0.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.working_color_space = 2u;
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));

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

float3 ToneMap(float3 color) {
Expand Down
2 changes: 1 addition & 1 deletion src/games/ffx/xx_screen_fade_0x90C53F9F.ps_4_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ void main(
{
o0.xyzw = ScreenFadeColor.xyzw;
o0.xyz *= injectedData.toneMapGameNits / injectedData.toneMapPeakNits;
o0.w = saturate(o0.w);
// o0.w = saturate(o0.w);
return;
}

0 comments on commit 4070ecf

Please sign in to comment.