Skip to content

Commit

Permalink
Merge branch 'clshortfuse:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marat569 authored Dec 21, 2024
2 parents 124a799 + 448be1c commit 216c92b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
52 changes: 37 additions & 15 deletions src/games/crisiscoreff7reunion/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
namespace {

renodx::mods::shader::CustomShaders custom_shaders = {
CustomSwapchainShader(0xAC791084),
CustomShaderEntry(0xC1BCC6B5),
CustomShaderEntry(0x61C2EA30),
CustomShaderEntry(0xE6EB2840),
CustomShaderEntry(0xBBA0606A),
CustomSwapchainShader(0xAC791084), // fmv
CustomShaderEntry(0xC1BCC6B5), // lutbuilder1
CustomShaderEntry(0xE6EB2840), // lutbuilder2
CustomShaderEntry(0x61C2EA30), // lutbuilder3
};

ShaderInjectData shader_injection;
Expand Down Expand Up @@ -85,27 +84,39 @@ renodx::utils::settings::Settings settings = {
.labels = {"Off", "LCD", "CRT"},
},
new renodx::utils::settings::Setting{
.key = "toneMapHueCorrectionMethod",
.binding = &shader_injection.toneMapHueCorrectionMethod,
.key = "ToneMapHueProcessor",
.binding = &shader_injection.toneMapHueProcessor,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 3.f,
.label = "Hue Correction Method",
.default_value = 0.f,
.label = "Hue Processor",
.section = "Tone Mapping",
.tooltip = "Applies hue shift emulation before tonemapping",
.labels = {"None", "SDR Clip", "Filmic", "RenoDRT"},
.tooltip = "Selects hue processor",
.labels = {"OKLab", "ICtCp", "darkTable UCS"},
.is_enabled = []() { return shader_injection.toneMapType == 3; },
},
new renodx::utils::settings::Setting{
.key = "toneMapHueCorrection",
.key = "ToneMapHueCorrection",
.binding = &shader_injection.toneMapHueCorrection,
.default_value = 100.f,
.default_value = 0.f,
.label = "Hue Correction",
.section = "Tone Mapping",
.tooltip = "Emulates Vanilla hue shifts.",
.tooltip = "Corrects Vanilla hue shifts.",
.min = 0.f,
.max = 100.f,
.is_enabled = []() { return shader_injection.toneMapHueCorrectionMethod != 0; },
.is_enabled = []() { return shader_injection.toneMapType == 3; },
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "ToneMapPerChannel",
.binding = &shader_injection.toneMapPerChannel,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "Per Channel",
.section = "Tone Mapping",
.tooltip = "Applies tonemapping per-channel instead of by luminance",
.labels = {"Off", "On"},
.is_enabled = []() { return shader_injection.toneMapType == 3; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeExposure",
.binding = &shader_injection.colorGradeExposure,
Expand Down Expand Up @@ -162,6 +173,17 @@ renodx::utils::settings::Settings settings = {
.is_enabled = []() { return shader_injection.toneMapType == 3; },
.parse = [](float value) { return value * 0.02f - 1.f; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeFlare",
.binding = &shader_injection.colorGradeFlare,
.default_value = 50.f,
.label = "Flare",
.section = "Color Grading",
.tooltip = "Flare/Glare",
.max = 100.f,
.is_enabled = []() { return shader_injection.toneMapType == 3; },
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeColorSpace",
.binding = &shader_injection.colorGradeColorSpace,
Expand Down
39 changes: 32 additions & 7 deletions src/games/crisiscoreff7reunion/lutbuilder1_0xC1BCC6B5.ps_5_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void main(
float3 log_input_color = r1.rgb;

r0.xyz = r0.zzz ? r0.xyw : r1.xyz;
r0.rgb = pq_input_color;

// r0.rgb = pq_input_color; use log2lin

float3 lut_input_color = r0.rgb;

Expand Down Expand Up @@ -240,15 +241,15 @@ void main(
r2.xyz = float3(-0.00200000009, -0.00200000009, -0.00200000009) + r2.xyz;

} else {
ap1_graded_color = r0.xyz;

// Blue correct -- r0 is still ap1, r1 is sRGB
r3.x = dot(float3(0.938639402, 1.02359565e-10, 0.0613606237), r0.xyz);
r3.y = dot(float3(8.36008554e-11, 0.830794156, 0.169205874), r0.xyz);
r3.z = dot(float3(2.13187367e-12, -5.63307213e-12, 1), r0.xyz);
r3.xyz = r3.xyz + -r0.xyz;
r0.xyz = cb0[66].xxx * r3.xyz + r0.xyz;

ap1_graded_color = r0.xyz;

// start of film tonemap
// AP1 => AP0
// start working here
Expand Down Expand Up @@ -369,8 +370,6 @@ void main(
config.shadows = injectedData.colorGradeShadows;
config.contrast = injectedData.colorGradeContrast;
config.saturation = injectedData.colorGradeSaturation;
config.hue_correction_color = ap1_aces_colored;


config.reno_drt_highlights = 1.0f;
config.reno_drt_shadows = 1.0f;
Expand All @@ -380,12 +379,17 @@ void main(
config.reno_drt_blowout = injectedData.colorGradeBlowout;
config.reno_drt_flare = 0.05f;
config.reno_drt_per_channel = true;
config.reno_drt_working_color_space = 2u;
config.reno_drt_per_channel = injectedData.toneMapPerChannel != 0;

config.reno_drt_hue_correction_method = (uint)injectedData.toneMapHueProcessor;

float3 config_color = renodx::color::bt709::from::AP1(ap1_graded_color);
float3 bt709_graded_color = renodx::color::bt709::from::AP1(ap1_graded_color);
float3 bt709_aces_color = renodx::color::bt709::from::AP1(ap1_aces_colored);

config.hue_correction_strength = injectedData.toneMapHueCorrection;

renodx::tonemap::config::DualToneMap dual_tone_map = renodx::tonemap::config::ApplyToneMaps(config_color, config);
renodx::tonemap::config::DualToneMap dual_tone_map = renodx::tonemap::config::ApplyToneMaps(bt709_graded_color, config);
hdr_color = dual_tone_map.color_hdr;
sdr_color = dual_tone_map.color_sdr;
sdr_ap1_color = renodx::color::ap1::from::BT709(sdr_color);
Expand Down Expand Up @@ -497,6 +501,27 @@ void main(
if (injectedData.toneMapType != 0.f) {
final_color = renodx::tonemap::UpgradeToneMap(hdr_color, sdr_color, final_color, 1.f);
}

// Scale for final shader gamma fix

if (injectedData.toneMapGammaCorrection == 2.f) {
final_color = renodx::color::srgb::EncodeSafe(final_color);
final_color = renodx::color::gamma::DecodeSafe(final_color, 2.4f);
final_color *= injectedData.toneMapGameNits / injectedData.toneMapUINits;
final_color = renodx::color::gamma::EncodeSafe(final_color, 2.4f);
} else if (injectedData.toneMapGammaCorrection == 1.f) {
final_color = renodx::color::srgb::EncodeSafe(final_color);
final_color = renodx::color::gamma::DecodeSafe(final_color, 2.2f);
final_color *= injectedData.toneMapGameNits / injectedData.toneMapUINits;
final_color = renodx::color::gamma::EncodeSafe(final_color, 2.2f);
} else {
final_color *= injectedData.toneMapGameNits / injectedData.toneMapUINits;
final_color = renodx::color::srgb::EncodeSafe(final_color);
}

// Scale for UE decoding
final_color *= 1.f / 1.05f;

o0.rgba = float4(final_color.rgb, 0);
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/games/crisiscoreff7reunion/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ struct ShaderInjectData {
float toneMapGammaCorrection;
float toneMapHueCorrectionMethod;
float toneMapHueCorrection;
float toneMapPerChannel;
float toneMapHueProcessor;
float colorGradeExposure;
float colorGradeHighlights;
float colorGradeShadows;
float colorGradeContrast;
float colorGradeSaturation;
float colorGradeBlowout;
float colorGradeFlare;
float colorGradeColorSpace;
};

Expand Down

0 comments on commit 216c92b

Please sign in to comment.