Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YS10] Fix Vanilla Tonemapper #39

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/games/ys10/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void OnPresetOff() {
renodx::utils::settings::UpdateSetting("toneMapType", 0.f);
renodx::utils::settings::UpdateSetting("toneMapPeakNits", 203.f);
renodx::utils::settings::UpdateSetting("toneMapGameNits", 203.f);
renodx::utils::settings::UpdateSetting("gamma", 1.f);
renodx::utils::settings::UpdateSetting("colorGradeExposure", 1.f);
renodx::utils::settings::UpdateSetting("colorGradeHighlights", 50.f);
renodx::utils::settings::UpdateSetting("colorGradeShadows", 50.f);
Expand Down
2 changes: 1 addition & 1 deletion src/games/ys10/tonemapper.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ float3 applyUserTonemap(float3 untonemapped) {

if (injectedData.toneMapType == 0.f) { // If vanilla is selected
outputColor = saturate(untonemapped);
outputColor = max(0, untonemapped); // clamps to 709/no negative colors for the vanilla tonemapper
outputColor = max(0, outputColor); // clamps to 709/no negative colors for the vanilla tonemapper
} else {
outputColor = untonemapped;
}
Expand Down
21 changes: 10 additions & 11 deletions src/shaders/colorcorrect.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,20 @@ float3 Hue(float3 incorrect_color, float3 correct_color, float strength = 1.f) {
if (strength == 0.f) return incorrect_color;

float3 correct_lab = renodx::color::oklab::from::BT709(correct_color);
float3 correct_lch = renodx::color::oklch::from::OkLab(correct_lab);

float3 incorrect_lab = renodx::color::oklab::from::BT709(incorrect_color);
float3 incorrect_lch = renodx::color::oklch::from::OkLab(incorrect_lab);
if (strength == 1.f) {
incorrect_lch[2] = correct_lch[2];
} else {
float old_chroma = incorrect_lch[1];

incorrect_lab.yz = lerp(incorrect_lab.yz, correct_lab.yz, strength);
incorrect_lch = renodx::color::oklch::from::OkLab(incorrect_lab);
incorrect_lch[1] = old_chroma;

float chrominance_pre_adjust = distance(incorrect_lab.yz, 0);

incorrect_lab.yz = lerp(incorrect_lab.yz, correct_lab.yz, strength);

float chrominance_post_adjust = distance(incorrect_lab.yz, 0);

if (chrominance_post_adjust != 0.f) {
incorrect_lab.yz *= chrominance_pre_adjust / chrominance_post_adjust;
}

float3 color = renodx::color::bt709::from::OkLCh(incorrect_lch);
float3 color = renodx::color::bt709::from::OkLab(incorrect_lab);
color = renodx::color::bt709::clamp::AP1(color);
return color;
}
Expand Down
Loading