Skip to content

Commit

Permalink
feat(ff7remake): default to new tonemap by luminance
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Jan 5, 2025
1 parent 1c38860 commit f85eb3c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/games/ff7remake/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 0.f,
.default_value = 100.f,
.label = "Hue Correction",
.section = "Tone Mapping",
.tooltip = "Hue shifts emulation strength.",
Expand All @@ -124,7 +124,7 @@ renodx::utils::settings::Settings settings = {
.key = "ToneMapPerChannel",
.binding = &shader_injection.tone_map_per_channel,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.default_value = 0.f,
.label = "Per Channel",
.section = "Tone Mapping",
.tooltip = "Applies tonemapping per-channel instead of by luminance",
Expand Down Expand Up @@ -290,7 +290,7 @@ 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", 50.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);
Expand Down
18 changes: 18 additions & 0 deletions src/games/ff7remake/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ float3 UpgradeToneMapPerChannel(float3 color_hdr, float3 color_sdr, float3 post_
return lerp(color_hdr, color_scaled, post_process_strength);
}

float3 UpgradeToneMapByLuminance(float3 color_hdr, float3 color_sdr, float3 post_process_color, float post_process_strength) {
// float ratio = 1.f;

float3 bt2020_hdr = max(0, renodx::color::bt2020::from::BT709(color_hdr));
float3 bt2020_sdr = max(0, renodx::color::bt2020::from::BT709(color_sdr));
float3 bt2020_post_process = max(0, renodx::color::bt2020::from::BT709(post_process_color));

float ratio = UpgradeToneMapRatio(
renodx::color::y::from::BT2020(bt2020_hdr),
renodx::color::y::from::BT2020(bt2020_sdr),
renodx::color::y::from::BT2020(bt2020_post_process));

float3 color_scaled = max(0, bt2020_post_process * ratio);
color_scaled = renodx::color::bt709::from::BT2020(color_scaled);
color_scaled = renodx::color::correct::Hue(color_scaled, post_process_color);
return lerp(color_hdr, color_scaled, post_process_strength);
}

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

Expand Down
7 changes: 6 additions & 1 deletion src/games/ff7remake/output2_0xD950DA01.ps_5_1.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ void main(

graded_aces = renodx::color::bt709::from::BT2020(r2.xyz / (250.f));

float3 color_graded = UpgradeToneMapPerChannel(color, reference_aces, graded_aces, 1);
float3 color_graded;
if (injectedData.tone_map_per_channel == 1.f) {
color_graded = UpgradeToneMapPerChannel(color, reference_aces, graded_aces, 1);
} else {
color_graded = UpgradeToneMapByLuminance(color, reference_aces, graded_aces, 1);
}

float3 lut_color = color_graded;
// lut_color = corrected;
Expand Down
8 changes: 6 additions & 2 deletions src/games/ff7remake/output_0x922A71D1.ps_5_1.hlsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "./common.hlsl"
#include "./shared.h"


Texture3D<float4> t0 : register(t0);
Texture2D<float4> t1 : register(t1);
Texture3D<float4> t2 : register(t2);
Expand Down Expand Up @@ -195,7 +194,12 @@ void main(

graded_aces = renodx::color::bt709::from::BT2020(r2.xyz / (250.f));

float3 color_graded = UpgradeToneMapPerChannel(color, reference_aces, graded_aces, 1);
float3 color_graded;
if (injectedData.tone_map_per_channel == 1.f) {
color_graded = UpgradeToneMapPerChannel(color, reference_aces, graded_aces, 1);
} else {
color_graded = UpgradeToneMapByLuminance(color, reference_aces, graded_aces, 1);
}

float3 lut_color = color_graded;
// lut_color = corrected;
Expand Down

0 comments on commit f85eb3c

Please sign in to comment.