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 Nov 23, 2024
2 parents 7da1146 + e5088d2 commit 44febdf
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 23 deletions.
102 changes: 88 additions & 14 deletions src/games/seaofstars/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#define DEBUG_LEVEL_0

#include <algorithm>

#include <embed/0x552A4A60.h>
#include <embed/0x67758842.h>
#include <embed/0x72B31CDE.h>
Expand Down Expand Up @@ -39,7 +41,6 @@ renodx::utils::settings::Settings settings = {
.binding = &shader_injection.toneMapType,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 3.f,
.can_reset = false,
.label = "Tone Mapper",
.section = "Tone Mapping",
.tooltip = "Sets the tone mapper type",
Expand All @@ -49,43 +50,58 @@ renodx::utils::settings::Settings settings = {
.key = "toneMapPeakNits",
.binding = &shader_injection.toneMapPeakNits,
.default_value = 1000.f,
.can_reset = false,
.label = "Peak Brightness",
.section = "Tone Mapping",
.tooltip = "Sets the value of peak white in nits",
.min = 48.f,
.tooltip =
"Sets the value of peak white in nits."
"\nDefault: Display peak brightness",
.min = 80.f,
.max = 4000.f,
},
new renodx::utils::settings::Setting{
.key = "toneMapGameNits",
.binding = &shader_injection.toneMapGameNits,
.default_value = 203.f,
.can_reset = false,
.label = "Game Brightness",
.section = "Tone Mapping",
.tooltip = "Sets the value of 100% white in nits",
.min = 48.f,
.tooltip = "Sets the value of 100% white in nits."
"\nDefault: Reference white value for display peak brightness",
.min = 80.f,
.max = 500.f,
},
new renodx::utils::settings::Setting{
.key = "toneMapUINits",
.binding = &shader_injection.toneMapUINits,
.default_value = 203.f,
.can_reset = false,
.label = "UI Brightness",
.section = "Tone Mapping",
.tooltip = "Sets the brightness of UI and HUD elements in nits",
.min = 48.f,
.tooltip =
"Sets the brightness of UI and HUD elements in nits."
"\nDefault: Windows SDR content brightness",
.min = 80.f,
.max = 500.f,
},
new renodx::utils::settings::Setting{
.key = "toneMapGammaCorrection",
.binding = &shader_injection.toneMapGammaCorrection,
.value_type = renodx::utils::settings::SettingValueType::BOOLEAN,
.can_reset = false,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "Gamma Correction",
.section = "Tone Mapping",
.tooltip = "Emulates a 2.2 EOTF (use with HDR or sRGB)",
.tooltip = "Emulates a 2.2 EOTF"
"\nDefault: On with HDR",
.labels = {"Off", "On"},
},
new renodx::utils::settings::Setting{
.key = "toneMapHueCorrection",
.binding = &shader_injection.toneMapHueCorrection,
.default_value = 50.f,
.label = "Hue Correction",
.section = "Tone Mapping",
.tooltip = "Emulates Vanilla hue shifts.",
.min = 0.f,
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeExposure",
Expand Down Expand Up @@ -132,6 +148,28 @@ renodx::utils::settings::Settings settings = {
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeBlowout",
.binding = &shader_injection.colorGradeBlowout,
.default_value = 0.f,
.label = "Blowout",
.section = "Color Grading",
.tooltip = "Controls highlight desaturation due to overexposure.",
.max = 100.f,
.is_enabled = []() { return shader_injection.toneMapType == 3; },
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeFlare",
.binding = &shader_injection.colorGradeFlare,
.default_value = 0.f,
.label = "Flare",
.section = "Color Grading",
.tooltip = "Flare/Glare Compensation",
.max = 100.f,
.is_enabled = []() { return shader_injection.toneMapType == 3; },
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeLUTStrength",
.binding = &shader_injection.colorGradeLUTStrength,
Expand Down Expand Up @@ -204,11 +242,45 @@ void OnPresetOff() {
renodx::utils::settings::UpdateSetting("colorGradeLUTStrength", 100.f);
renodx::utils::settings::UpdateSetting("colorGradeLUTScaling", 0.f);
renodx::utils::settings::UpdateSetting("fxBloom", 50.f);
renodx::utils::settings::UpdateSetting("fxVignette", 50.f);
renodx::utils::settings::UpdateSetting("fxHeroLight", 100.f);
renodx::utils::settings::UpdateSetting("processingInternalSampling", 0.f);

}

auto last_is_hdr = false;

float ComputeReferenceWhite(float peak_nits) {
return std::clamp(roundf(powf(10.f, 0.03460730900256f + (0.757737096673107f * log10f(peak_nits)))), 100.f, 300.f);
}

void OnInitSwapchain(reshade::api::swapchain* swapchain) {
last_is_hdr = renodx::utils::swapchain::IsHDRColorSpace(swapchain);
if (!last_is_hdr) {
settings[1]->default_value = 80.f;
settings[2]->default_value = 80.f;
settings[3]->default_value = 80.f;
settings[4]->default_value = 0.f;
return;
}

auto peak = renodx::utils::swapchain::GetPeakNits(swapchain);
if (peak.has_value()) {
settings[1]->default_value = roundf(peak.value());
} else {
settings[1]->default_value = 1000.f;
}

settings[2]->default_value = ComputeReferenceWhite(settings[1]->default_value);

auto white_level = renodx::utils::swapchain::GetSDRWhiteNits(swapchain);
if (white_level.has_value()) {
settings[3]->default_value = roundf(white_level.value());
} else {
settings[3]->default_value = 203.f;
}

settings[4]->default_value = 1.f;
}
} // namespace

extern "C" __declspec(dllexport) constexpr const char* NAME = "RenoDX";
Expand All @@ -223,8 +295,10 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
.old_format = reshade::api::format::r8g8b8a8_typeless,
.new_format = reshade::api::format::r16g16b16a16_float,
});
reshade::register_event<reshade::addon_event::init_swapchain>(OnInitSwapchain);
break;
case DLL_PROCESS_DETACH:
reshade::unregister_event<reshade::addon_event::init_swapchain>(OnInitSwapchain);
reshade::unregister_addon(h_module);
break;
}
Expand Down
13 changes: 10 additions & 3 deletions src/games/seaofstars/lutbuilder_new_0x77850945.ps_4_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void main(float4 v0: SV_POSITION0, float2 v1: TEXCOORD0, out float4 o0: SV_Targe
r0.xyz = renodx::tonemap::unity::BT709(r0.xyz);

if (useSDRLut) {
r0.xyz = lerp(r0.xyz, renodx::lut::Sample(t8, lut_config, r0.xyz), lut_config.strength);
r0.xyz = lerp(r0.xyz, renodx::lut::Sample(t8, lut_config, saturate(r0.xyz)), lut_config.strength);
}
} else {
float vanillaMidGray = renodx::tonemap::unity::BT709(0.18f);
Expand All @@ -297,15 +297,22 @@ void main(float4 v0: SV_POSITION0, float2 v1: TEXCOORD0, out float4 o0: SV_Targe
config.type = injectedData.toneMapType;
config.peak_nits = injectedData.toneMapPeakNits;
config.game_nits = injectedData.toneMapGameNits;
config.gamma_correction = injectedData.toneMapGammaCorrection - 1;
config.gamma_correction = injectedData.toneMapGammaCorrection;
config.exposure = injectedData.colorGradeExposure;
config.highlights = injectedData.colorGradeHighlights;
config.shadows = injectedData.colorGradeShadows;
config.contrast = injectedData.colorGradeContrast;
config.saturation = injectedData.colorGradeSaturation;
config.mid_gray_value = vanillaMidGray;
config.mid_gray_nits = vanillaMidGray * 100.f;
config.reno_drt_dechroma = 0;
config.reno_drt_dechroma = injectedData.colorGradeBlowout;
config.reno_drt_flare = injectedData.colorGradeFlare;

config.hue_correction_type = renodx::tonemap::config::hue_correction_type::CUSTOM;
config.hue_correction_color = lerp(
untonemapped,
saturate(renodx::tonemap::unity::BT709(untonemapped)),
injectedData.toneMapHueCorrection);

r0.xyz = renodx::tonemap::config::Apply(r0.xyz, config, lut_config, t8);
}
Expand Down
3 changes: 3 additions & 0 deletions src/games/seaofstars/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ struct ShaderInjectData {
float toneMapGameNits;
float toneMapUINits;
float toneMapGammaCorrection;
float toneMapHueCorrection;
float colorGradeExposure;
float colorGradeHighlights;
float colorGradeShadows;
float colorGradeContrast;
float colorGradeSaturation;
float colorGradeBlowout;
float colorGradeFlare;
float colorGradeLUTStrength;
float colorGradeLUTScaling;
float fxBloom;
Expand Down
10 changes: 4 additions & 6 deletions src/games/seaofstars/tonemapper_new_0xB646820B.ps_4_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ void main(float4 v0: SV_POSITION0, float2 v1: TEXCOORD0, out float4 o0: SV_Targe
r1.xyz = float3(8, 8, 8) * r2.xyz;
}
r1.xyz = cb0[192].xxx * r1.xyz;
r0.xyz = r1.xyz * cb0[192].yzw + r0.xyz;

float3 scaledBloom = r0.xyz;
// r0.xyz = r1.xyz * cb0[192].yzw + r0.xyz;

if (injectedData.fxBloom) {
r0.rgb = inputColor.rgb + scaledBloom * pow(injectedData.fxBloom, injectedData.fxBloom);
}
r0.rgb = r1.xyz * cb0[192].yzw * injectedData.fxBloom + r0.xyz;

// possibly vignette
r0.w = cmp(0 < cb0[200].z);
Expand Down Expand Up @@ -84,7 +81,6 @@ void main(float4 v0: SV_POSITION0, float2 v1: TEXCOORD0, out float4 o0: SV_Targe
r1.xyz = r0.www * r1.xyz + r3.xyz;
}


// SDR LUT which seems like dead code
r0.w = cmp(cb0[205].y == 0.000000);
if (r0.w != 0) {
Expand Down Expand Up @@ -146,5 +142,7 @@ void main(float4 v0: SV_POSITION0, float2 v1: TEXCOORD0, out float4 o0: SV_Targe
o0.xyz = r1.xyz;
o0.w = 1;

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

return;
}

0 comments on commit 44febdf

Please sign in to comment.