Skip to content

Commit

Permalink
Initial The Evil Within 2
Browse files Browse the repository at this point in the history
Add RenoDX to the main tonemap shader

Still has some bugs, like motion blue clamping the game

No UI shaders yet
  • Loading branch information
marat569 authored Aug 17, 2024
1 parent 595dae6 commit 667b60e
Show file tree
Hide file tree
Showing 4 changed files with 509 additions and 0 deletions.
248 changes: 248 additions & 0 deletions src/games/tew2/addon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/*
* Copyright (C) 2023 Carlos Lopez
* SPDX-License-Identifier: MIT
*/

#define ImTextureID ImU64

#define DEBUG_LEVEL_0

//#define DEBUG_LEVEL_1 //added

#include <embed/0xB13F7764.h> //Tonemapper






#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(0xB13F7764), //Tonemapper


};

ShaderInjectData shader_injection;

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,
.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,
.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 = "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,
.parse = [](float value) { return value * 0.01f; },
},




new renodx::utils::settings::Setting{
.key = "bloom",
.binding = &shader_injection.bloom,
.value_type = renodx::utils::settings::SettingValueType::BOOLEAN,
.default_value = 1,
.can_reset = false,
.label = "Bloom + DoF",
.section = "Effects",
.tooltip = "Enable/Disable Bloom + Depth of Field",

},

new renodx::utils::settings::Setting{
.key = "fxBloom",
.binding = &shader_injection.fxBloom,
.default_value = 50.f,
.label = "Bloom Strength",
.section = "Effects",
.tooltip = "Controls Bloom Strength",
.max = 100.f,
.parse = [](float value) { return value * 0.02f; },
},


new renodx::utils::settings::Setting{
.key = "chromaticAberration",
.binding = &shader_injection.chromaticAberration,
.value_type = renodx::utils::settings::SettingValueType::BOOLEAN,
.default_value = 1,
.can_reset = false,
.label = "Chromatic Aberration",
.section = "Effects",
.tooltip = "Enable/Disable chromaticAberration",

},

};

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("toneMapUINits", 203.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);
renodx::utils::settings::UpdateSetting("colorGradeSaturation", 50.f);
renodx::utils::settings::UpdateSetting("colorGradeBlowout", 50.f);
//Start PostProcess effects on/off
renodx::utils::settings::UpdateSetting("bloom", 1);
renodx::utils::settings::UpdateSetting("fxBloom", 50.f);
renodx::utils::settings::UpdateSetting("chromaticAberration", 1);
}

} // namespace

// NOLINTBEGIN(readability-identifier-naming)

extern "C" __declspec(dllexport) const char* NAME = "RenoDX";
extern "C" __declspec(dllexport) const char* DESCRIPTION = "RenoDX for The Evil Within 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::force_pipeline_cloning = true; //So the mod works with the toolkit

renodx::mods::swapchain::force_borderless = false; //needed for stability
renodx::mods::swapchain::prevent_full_screen = false; //needed for stability




// RGBA8_TYPELESS
renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = reshade::api::format::r8g8b8a8_typeless,
.new_format = reshade::api::format::r16g16b16a16_float,
// .index = 39, //Maybe find the specific render target that uncaps the game one day, but not right now
// .ignore_size = true, //Ignoring size allows you to uncap when the game runs in a sub-native resolution, but tons of artifacts are created
});

// RGBA8_UNORM
renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = reshade::api::format::r8g8b8a8_unorm,
.new_format = reshade::api::format::r16g16b16a16_float,
// .index = 39, //Maybe find the specific render target that uncaps the game one day, but not right now
// .ignore_size = true, //Ignoring size allows you to uncap when the game runs in a sub-native resolution, but tons of artifacts are created
});



break;
case DLL_PROCESS_DETACH:
reshade::unregister_addon(h_module);
break;
}

renodx::utils::settings::Use(fdw_reason, &settings, &OnPresetOff);

renodx::mods::swapchain::Use(fdw_reason);

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

return TRUE;
}
34 changes: 34 additions & 0 deletions src/games/tew2/shared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef SRC_RYZA3_SHARED_H_
#define SRC_RYZA3_SHARED_H_

#ifndef __cplusplus
#include "../../shaders/renodx.hlsl"
#endif

// Must be 32bit aligned
// Should be 4x32
struct ShaderInjectData {
float toneMapType;
float toneMapPeakNits;
float toneMapGameNits;
float toneMapUINits;
float colorGradeExposure;
float colorGradeHighlights;
float colorGradeShadows;
float colorGradeContrast;
float colorGradeSaturation;
float colorGradeBlowout;
float toneMapHueCorrection;
float blend;
float bloom;
float fxBloom;
float chromaticAberration;
};

#ifndef __cplusplus
cbuffer cb13 : register(b13) {
ShaderInjectData injectedData : packoffset(c0); //
}
#endif

#endif // SRC_RYZA3_SHARED_H_
Loading

0 comments on commit 667b60e

Please sign in to comment.