Skip to content

Commit

Permalink
feat (Stalker 2) (#80)
Browse files Browse the repository at this point in the history
* Initial stalker 2

* Add more lutbuilders, final shader and tonemapper

* Initial working stalker 2 mod

* Add postprocess shaders, new luts, and correct gamma only in final shader

* feat(stalker2): remove unfinished lutbuilder, convert to srgb for postprocess shaders, bypass output shader adjustments

* feat(stalker2): Move colorgrading to final shader, disable custom code for vanilla

* feat(stalker2): Disable image corrections and use default SDR values instead

* fix(stalker2): Rework LUT sampling logic, restore mid gray value, and enable UI adjustments for all tonemappers

* cleanup(stalker2): Remove CS lutbuilders, adjust paperwhite default value

* regress(stalker2): revert lut sampling type to SRGB
  • Loading branch information
MohannedElfatih authored Dec 5, 2024
1 parent bf3493e commit 94c9a25
Show file tree
Hide file tree
Showing 12 changed files with 12,009 additions and 0 deletions.
276 changes: 276 additions & 0 deletions src/games/stalker2/addon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
/*
* Copyright (C) 2023 Carlos Lopez
* SPDX-License-Identifier: MIT
*/

#define ImTextureID ImU64

#define DEBUG_LEVEL_0

#include <embed/0x04532088.h> // Unknown post process
#include <embed/0x4D3C673E.h> // Output
#include <embed/0x5590F787.h> // Radiation post process
#include <embed/0x6CFBD4C0.h> // LUT Builder
#include <embed/0xA7EFB8C2.h> // Final
#include <embed/0xB6CA5FD9.h> // LUT Builder
#include <embed/0xBAA27141.h> // LUT Builder
#include <embed/0xECD0D71A.h> // Output
#include <embed/0xED411D4E.h> // Unknown post process 2

#include <deps/imgui/imgui.h>
#include <include/reshade.hpp>

#include "../../mods/shader.hpp"
#include "../../mods/swapchain.hpp"
#include "../../utils/settings.hpp"
#include "./shared.h"

namespace {

renodx::mods::shader::CustomShaders custom_shaders = {
CustomShaderEntry(0xB6CA5FD9),
CustomShaderEntry(0xA7EFB8C2),
CustomShaderEntry(0x6CFBD4C0),
CustomShaderEntry(0x5590F787),
CustomShaderEntry(0x04532088),
CustomShaderEntry(0xBAA27141),
CustomShaderEntry(0xECD0D71A),
CustomShaderEntry(0xED411D4E),
CustomShaderEntry(0x4D3C673E),

};

ShaderInjectData shader_injection;
const std::string build_date = __DATE__;
const std::string build_time = __TIME__;

renodx::utils::settings::Settings settings = {
new renodx::utils::settings::Setting{
.key = "toneMapType",
.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",
.labels = {"Vanilla", "None", "ACES", "RenoDRT"},
},
new renodx::utils::settings::Setting{
.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,
.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,
.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,
.max = 500.f,
},
new renodx::utils::settings::Setting{
.key = "radiationOverlayStrength",
.binding = &shader_injection.radiationOverlayStrength,
.default_value = 50.f,
.label = "Radiation Strength",
.section = "Tone Mapping",
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "toneMapGammaCorrection",
.binding = &shader_injection.toneMapGammaCorrection,
.value_type = renodx::utils::settings::SettingValueType::BOOLEAN,
.can_reset = false,
.label = "Gamma Correction",
.section = "Tone Mapping",
.tooltip = "Emulates a 2.2 EOTF (use with HDR or sRGB)",
},
new renodx::utils::settings::Setting{
.key = "colorGradeExposure",
.binding = &shader_injection.colorGradeExposure,
.default_value = 1.f,
.label = "Exposure",
.section = "Color Grading",
.max = 10.f,
.format = "%.2f",
},
new renodx::utils::settings::Setting{
.key = "colorGradeHighlights",
.binding = &shader_injection.colorGradeHighlights,
.default_value = 50.f,
.label = "Highlights",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeShadows",
.binding = &shader_injection.colorGradeShadows,
.default_value = 50.f,
.label = "Shadows",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeContrast",
.binding = &shader_injection.colorGradeContrast,
.default_value = 50.f,
.label = "Contrast",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeSaturation",
.binding = &shader_injection.colorGradeSaturation,
.default_value = 50.f,
.label = "Saturation",
.section = "Color Grading",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeBlowout",
.binding = &shader_injection.colorGradeBlowout,
.default_value = 50.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 = "colorGradeLUTStrength",
.binding = &shader_injection.colorGradeLUTStrength,
.default_value = 100.f,
.label = "LUT Strength",
.section = "Color Grading",
.max = 100.f,
.is_enabled = []() { return shader_injection.toneMapType != 2; },
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::TEXT,
.label = " - Ingame HDR must be turned ON!",
.section = "Instructions",
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::TEXT,
.label = "Special thanks to Shortfuse & the folks at HDR Den for their support! Join the HDR Den discord for help!",
.section = "About",
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::BUTTON,
.label = "HDR Den Discord",
.section = "About",
.group = "button-line-1",
.tint = 0x5865F2,
.on_change = []() {
static const std::string obfuscated_link = std::string("start https://discord.gg/5WZX") + std::string("DpmbpP");
system(obfuscated_link.c_str());
},
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::BUTTON,
.label = "Get more RenoDX mods!",
.section = "About",
.group = "button-line-1",
.tint = 0x5865F2,
.on_change = []() {
system("start https://github.com/clshortfuse/renodx/wiki/Mods");
},
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::BUTTON,
.label = "ShortFuse's Ko-Fi",
.section = "About",
.group = "button-line-1",
.tint = 0xFF5F5F,
.on_change = []() {
system("start https://ko-fi.com/shortfuse");
},
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::BUTTON,
.label = "HDR Den's Ko-Fi",
.section = "About",
.group = "button-line-1",
.tint = 0xFF5F5F,
.on_change = []() {
system("start https://ko-fi.com/hdrden");
},
},
new renodx::utils::settings::Setting{
.value_type = renodx::utils::settings::SettingValueType::TEXT,
.label = "This build was compiled on " + build_date + " at " + build_time + ".",
.section = "About",
},
};

void OnPresetOff() {
renodx::utils::settings::UpdateSetting("toneMapType", 0.f);
renodx::utils::settings::UpdateSetting("toneMapPeakNits", 800.f);
renodx::utils::settings::UpdateSetting("toneMapGameNits", 203.f);
renodx::utils::settings::UpdateSetting("toneMapUINits", 203.f);
renodx::utils::settings::UpdateSetting("radiationOverlayStrength", 50.f);
renodx::utils::settings::UpdateSetting("toneMapGammaCorrection", 0);
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);
renodx::utils::settings::UpdateSetting("colorGradeSaturation", 50.f);
renodx::utils::settings::UpdateSetting("colorGradeLUTStrength", 100.f);
}

} // namespace

// NOLINTBEGIN(readability-identifier-naming)

extern "C" __declspec(dllexport) const char* NAME = "RenoDX Stalker 2";
extern "C" __declspec(dllexport) const char* DESCRIPTION = "RenoDX Stalker 2";

// NOLINTEND(readability-identifier-naming)

BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
switch (fdw_reason) {
case DLL_PROCESS_ATTACH:
if (!reshade::register_addon(h_module)) return FALSE;
renodx::mods::shader::on_init_pipeline_layout = [](reshade::api::device* device, auto, auto) {
return device->get_api() == reshade::api::device_api::d3d12;
};
renodx::mods::shader::expected_constant_buffer_space = 50;
break;
case DLL_PROCESS_DETACH:
reshade::unregister_addon(h_module);
break;
}

renodx::utils::settings::Use(fdw_reason, &settings, &OnPresetOff);
renodx::mods::shader::Use(fdw_reason, custom_shaders, &shader_injection);

return TRUE;
}
Loading

0 comments on commit 94c9a25

Please sign in to comment.