Skip to content

Commit 17f8c9e

Browse files
mqhajiclshortfuse
authored andcommitted
ori2: pull from refactor2
1 parent 17c5105 commit 17f8c9e

File tree

53 files changed

+6882
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+6882
-0
lines changed

src/games/ori2/addon.cpp

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/*
2+
* Copyright (C) 2024 Musa Haji
3+
* Copyright (C) 2024 Carlos Lopez
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#define ImTextureID ImU64
8+
9+
#define DEBUG_LEVEL_0
10+
#define DEBUG_SLIDERS_OFF
11+
12+
#include <deps/imgui/imgui.h>
13+
14+
#include <embed/0x24182048.h> // Color Grading - main menu & prologue
15+
#include <embed/0x73E7A34D.h> // Color Grading - main menu & prologue - sharpening low
16+
#include <embed/0xD7BC63A1.h> // Color Grading - level 1: Inkwater Marsh
17+
18+
// additional color grading shaders done in batch
19+
#include <embed/0x063548F6.h>
20+
#include <embed/0x0BE6093C.h>
21+
#include <embed/0x0E0EE842.h>
22+
#include <embed/0x1A46FADC.h>
23+
#include <embed/0x1E8FDB7D.h>
24+
#include <embed/0x211F3245.h>
25+
#include <embed/0x28B10677.h>
26+
#include <embed/0x2CEC407A.h>
27+
#include <embed/0x34F7E01C.h>
28+
#include <embed/0x350163E1.h>
29+
#include <embed/0x37E6CB72.h>
30+
#include <embed/0x3F118009.h>
31+
#include <embed/0x3FDCF7AA.h>
32+
#include <embed/0x48CDE62E.h>
33+
#include <embed/0x4A3D4181.h>
34+
#include <embed/0x596B9BD3.h>
35+
#include <embed/0x5B0965E4.h>
36+
#include <embed/0x5CDE4A30.h>
37+
#include <embed/0x613B5403.h>
38+
#include <embed/0x62C79AA3.h>
39+
#include <embed/0x649A0B90.h>
40+
#include <embed/0x7C14BB2C.h>
41+
#include <embed/0x841FAF0A.h>
42+
#include <embed/0x84C7D93E.h>
43+
#include <embed/0x8A303253.h>
44+
#include <embed/0x8B1DE268.h>
45+
#include <embed/0x8D6097D1.h>
46+
#include <embed/0x8D6C34A5.h>
47+
#include <embed/0x8EC5798A.h>
48+
#include <embed/0x9AC0DEEF.h>
49+
#include <embed/0x9B5CC768.h>
50+
#include <embed/0x9DA86DCE.h>
51+
#include <embed/0xA6488EB2.h>
52+
#include <embed/0xABD8D6B7.h>
53+
#include <embed/0xB24C1A54.h>
54+
#include <embed/0xB270CA5B.h>
55+
#include <embed/0xC4128983.h>
56+
#include <embed/0xD9B57ECB.h>
57+
#include <embed/0xDB90C883.h>
58+
#include <embed/0xDE975B11.h>
59+
#include <embed/0xE3F6E54F.h>
60+
#include <embed/0xF017475F.h>
61+
#include <embed/0xF3917C63.h>
62+
#include <embed/0xF7933F3F.h>
63+
#include <embed/0xFCF0717A.h>
64+
65+
#include <embed/0x9D323EA3.h> // Inverse tonemap, garbage default hdr implementation
66+
#include <embed/0xF9C2BDE1.h> // DICE, final bt2020 conversion, paper white, and pq encode
67+
68+
#include <include/reshade.hpp>
69+
#include "../../mods/shader.hpp"
70+
#include "../../utils/settings.hpp"
71+
#include "./shared.h"
72+
73+
namespace {
74+
75+
renodx::mods::shader::CustomShaders custom_shaders = {
76+
CustomShaderEntry(0x24182048), // Color Grading - main menu & prologue
77+
CustomShaderEntry(0x73E7A34D), // Color Grading - main menu & prologue - sharpening low
78+
CustomShaderEntry(0xD7BC63A1), // Color Grading - level 1
79+
80+
// additional color grading shaders done in batch
81+
CustomShaderEntry(0x063548F6),
82+
CustomShaderEntry(0x0BE6093C),
83+
CustomShaderEntry(0x0E0EE842),
84+
CustomShaderEntry(0x1A46FADC),
85+
CustomShaderEntry(0x1E8FDB7D),
86+
CustomShaderEntry(0x211F3245),
87+
CustomShaderEntry(0x28B10677),
88+
CustomShaderEntry(0x2CEC407A),
89+
CustomShaderEntry(0x34F7E01C),
90+
CustomShaderEntry(0x350163E1),
91+
CustomShaderEntry(0x37E6CB72),
92+
CustomShaderEntry(0x3F118009),
93+
CustomShaderEntry(0x3FDCF7AA),
94+
CustomShaderEntry(0x48CDE62E),
95+
CustomShaderEntry(0x4A3D4181),
96+
CustomShaderEntry(0x596B9BD3),
97+
CustomShaderEntry(0x5B0965E4),
98+
CustomShaderEntry(0x5CDE4A30),
99+
CustomShaderEntry(0x613B5403),
100+
CustomShaderEntry(0x62C79AA3),
101+
CustomShaderEntry(0x649A0B90),
102+
CustomShaderEntry(0x7C14BB2C),
103+
CustomShaderEntry(0x841FAF0A),
104+
CustomShaderEntry(0x84C7D93E),
105+
CustomShaderEntry(0x8A303253),
106+
CustomShaderEntry(0x8B1DE268),
107+
CustomShaderEntry(0x8D6097D1),
108+
CustomShaderEntry(0x8D6C34A5),
109+
CustomShaderEntry(0x8EC5798A),
110+
CustomShaderEntry(0x9AC0DEEF),
111+
CustomShaderEntry(0x9B5CC768),
112+
CustomShaderEntry(0x9DA86DCE),
113+
CustomShaderEntry(0xA6488EB2),
114+
CustomShaderEntry(0xABD8D6B7),
115+
CustomShaderEntry(0xB24C1A54),
116+
CustomShaderEntry(0xB270CA5B),
117+
CustomShaderEntry(0xC4128983),
118+
CustomShaderEntry(0xD9B57ECB),
119+
CustomShaderEntry(0xDB90C883),
120+
CustomShaderEntry(0xDE975B11),
121+
CustomShaderEntry(0xE3F6E54F),
122+
CustomShaderEntry(0xF017475F),
123+
CustomShaderEntry(0xF3917C63),
124+
CustomShaderEntry(0xF7933F3F),
125+
CustomShaderEntry(0xFCF0717A),
126+
127+
CustomShaderEntry(0x9D323EA3), // Inverse tonemap, garbage default hdr implementation
128+
CustomShaderEntry(0xF9C2BDE1), // DICE, final bt2020 conversion, paper white, and pq encode
129+
};
130+
131+
ShaderInjectData shader_injection;
132+
133+
renodx::utils::settings::Settings settings = {
134+
new renodx::utils::settings::Setting{
135+
.key = "toneMapType",
136+
.binding = &shader_injection.toneMapType,
137+
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
138+
.default_value = 2.f,
139+
.can_reset = false,
140+
.label = "Tone Mapper",
141+
.section = "Tone Mapping",
142+
.tooltip = "Sets the tone mapper type",
143+
.labels = {"Vanilla (Fake HDR)", "None", "DICE"},
144+
},
145+
new renodx::utils::settings::Setting{
146+
.key = "toneMapPeakNits",
147+
.binding = &shader_injection.toneMapPeakNits,
148+
.default_value = 1000.f,
149+
.can_reset = false,
150+
.label = "Peak Brightness",
151+
.section = "Tone Mapping",
152+
.tooltip = "Sets the value of peak white in nits",
153+
.min = 48.f,
154+
.max = 4000.f,
155+
},
156+
new renodx::utils::settings::Setting{
157+
.key = "toneMapGameNits",
158+
.binding = &shader_injection.toneMapGameNits,
159+
.default_value = 203.f,
160+
.can_reset = false,
161+
.label = "Game Brightness",
162+
.section = "Tone Mapping",
163+
.tooltip = "Sets the value of 100%% white in nits",
164+
.min = 48.f,
165+
.max = 500.f,
166+
},
167+
new renodx::utils::settings::Setting{
168+
.key = "toneMapHueCorrection",
169+
.binding = &shader_injection.toneMapHueCorrection,
170+
.default_value = 50.f,
171+
.can_reset = false,
172+
.label = "Hue Correction",
173+
.section = "Tone Mapping",
174+
.tooltip = "Emulates hue shifting from the vanilla tonemapper",
175+
.max = 100.f,
176+
.is_enabled = []() { return shader_injection.toneMapType != 0; },
177+
.parse = [](float value) { return value * 0.01f; },
178+
},
179+
new renodx::utils::settings::Setting{
180+
.key = "colorGradeStrength",
181+
.binding = &shader_injection.colorGradeStrength,
182+
.default_value = 100.f,
183+
.label = "Color Grade Strength",
184+
.section = "Color Grading",
185+
.max = 100.f,
186+
.parse = [](float value) { return value * 0.01f; },
187+
},
188+
};
189+
190+
void OnPresetOff() {
191+
renodx::utils::settings::UpdateSetting("toneMapType", 0);
192+
renodx::utils::settings::UpdateSetting("toneMapPeakNits", 1000.f);
193+
renodx::utils::settings::UpdateSetting("toneMapGameNits", 203.f);
194+
renodx::utils::settings::UpdateSetting("toneMapGammaCorrection", 1.f);
195+
renodx::utils::settings::UpdateSetting("colorGradeExposure", 1.f);
196+
renodx::utils::settings::UpdateSetting("colorGradeHighlights", 50.f);
197+
renodx::utils::settings::UpdateSetting("colorGradeShadows", 50.f);
198+
renodx::utils::settings::UpdateSetting("colorGradeContrast", 50.f);
199+
renodx::utils::settings::UpdateSetting("colorGradeSaturation", 50.f);
200+
renodx::utils::settings::UpdateSetting("colorGradeStrength", 100.f);
201+
}
202+
203+
} // namespace
204+
205+
// NOLINTBEGIN(readability-identifier-naming)
206+
207+
extern "C" __declspec(dllexport) const char* NAME = "RenoDX";
208+
extern "C" __declspec(dllexport) const char* DESCRIPTION = "RenoDX for Ori and the Will of the Wisps";
209+
210+
// NOLINTEND(readability-identifier-naming)
211+
212+
BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
213+
switch (fdw_reason) {
214+
case DLL_PROCESS_ATTACH:
215+
renodx::mods::shader::force_pipeline_cloning = true;
216+
renodx::mods::shader::expected_constant_buffer_index = 11;
217+
218+
if (!reshade::register_addon(h_module)) return FALSE;
219+
220+
break;
221+
case DLL_PROCESS_DETACH:
222+
reshade::unregister_addon(h_module);
223+
break;
224+
}
225+
226+
renodx::utils::settings::Use(fdw_reason, &settings, &OnPresetOff);
227+
228+
renodx::mods::shader::Use(fdw_reason, custom_shaders, &shader_injection);
229+
230+
return TRUE;
231+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#include "./shared.h"
2+
3+
// ---- Created with 3Dmigoto v1.3.16 on Thu Aug 15 21:12:45 2024
4+
Texture2D<float4> t4 : register(t4);
5+
6+
Texture2D<float4> t3 : register(t3);
7+
8+
Texture2D<float4> t2 : register(t2);
9+
10+
Texture2D<float4> t1 : register(t1);
11+
12+
Texture2D<float4> t0 : register(t0);
13+
14+
SamplerState s3_s : register(s3);
15+
16+
SamplerState s2_s : register(s2);
17+
18+
SamplerState s1_s : register(s1);
19+
20+
SamplerState s0_s : register(s0);
21+
22+
cbuffer cb0 : register(b0)
23+
{
24+
float4 cb0[22];
25+
}
26+
27+
28+
29+
30+
// 3Dmigoto declarations
31+
#define cmp -
32+
33+
34+
void main(
35+
float4 v0 : SV_POSITION0,
36+
linear noperspective float2 v1 : TEXCOORD0,
37+
linear noperspective float2 w1 : TEXCOORD1,
38+
linear noperspective float2 v2 : TEXCOORD2,
39+
out float4 o0 : SV_Target0)
40+
{
41+
float4 r0,r1,r2,r3,r4,r5,r6,r7,r8;
42+
uint4 bitmask, uiDest;
43+
float4 fDest;
44+
45+
r0.xy = t0.Sample(s2_s, v2.xy).xy;
46+
r0.xy = float2(-0.498039216,-0.498039216) + r0.xy;
47+
r0.xy = float2(0.100000001,0.100000001) * r0.xy;
48+
r0.zw = r0.xy * cb0[5].xy + v1.xy;
49+
r0.xy = r0.xy * cb0[5].xy + v2.xy;
50+
r0.xy = min(cb0[6].zw, r0.xy);
51+
r1.xyzw = t2.Sample(s1_s, r0.xy).xyzw; // blur?
52+
r1.xyzw = saturate(-r1.xyzw * cb0[21].xxxx + float4(1,1,1,1));
53+
r2.xyzw = min(cb0[6].xyxy, r0.zwzw);
54+
r0.xy = r0.zw / cb0[5].xy;
55+
r3.xyzw = cb0[3].xyxy * float4(-1.5,-1.5,1.5,-1.5) + r2.zwzw;
56+
r4.xyz = t1.Sample(s0_s, r3.xy).xyz;
57+
r3.xyz = t1.Sample(s0_s, r3.zw).xyz;
58+
r3.xyz = r4.xyz + r3.xyz;
59+
r4.xyzw = cb0[3].xyxy * float4(-1.5,1.5,1.5,1.5) + r2.xyzw;
60+
r2.xyzw = t1.Sample(s0_s, r2.zw).xyzw; // render
61+
62+
r5.xyz = t1.Sample(s0_s, r4.xy).xyz;
63+
r4.xyz = t1.Sample(s0_s, r4.zw).xyz;
64+
r3.xyz = r5.xyz + r3.xyz;
65+
r3.xyz = r3.xyz + r4.xyz;
66+
r3.xyz = -r3.xyz * float3(0.25,0.25,0.25) + r2.xyz;
67+
r3.xyz = r3.xyz * cb0[8].yyy + r2.xyz;
68+
r0.zw = min(cb0[13].zw, r0.xy);
69+
r4.xyz = t4.Sample(s3_s, r0.xy).xyz; // ori glow
70+
r0.xyz = t3.Sample(s3_s, r0.zw).xyz; // sun glow
71+
r5.xyz = cb0[13].xxx * r0.xyz;
72+
r0.xyz = cb0[13].yyy + r0.xyz;
73+
r0.xyz = r5.xyz / r0.xyz;
74+
r0.xyz = r3.xyz + r0.xyz;
75+
r0.w = max(r4.y, r4.z);
76+
r0.w = max(r4.x, r0.w);
77+
r3.x = cmp(cb0[12].z < r0.w);
78+
r0.w = cb0[12].z / r0.w;
79+
r0.w = r3.x ? r0.w : 1;
80+
r2.xyz = r4.xyz * r0.www + r0.xyz;
81+
r0.xy = w1.xy * float2(2,2) + float2(-1,-1);
82+
r0.x = dot(r0.xy, r0.xy);
83+
r0.x = min(1, r0.x);
84+
r0.x = cb0[8].x * r0.x;
85+
r0.x = r0.x * 7 + 1;
86+
r0.xyzw = r2.xyzw * r0.xxxx;
87+
88+
r2.xyz = cb0[17].xyz * r0.xyz; // r2.xyz = saturate(cb0[17].xyz * r0.xyz);
89+
float3 hdrColor = r2.xyz;
90+
r2.xyz = saturate(r2.xyz);
91+
92+
r3.xyz = r2.xyz * r2.xyz;
93+
r4.xyz = r3.xyz * r2.xyz;
94+
r5.w = r4.x;
95+
r6.xyz = float3(1,1,1) + -r2.xyz;
96+
r7.xyz = r6.xyz * r6.xyz;
97+
r8.xyz = r7.yxz * r6.yxz;
98+
r3.xyz = r6.xyz * r3.xyz;
99+
r2.xyz = r7.xzy * r2.xzy;
100+
r5.x = r8.y;
101+
r5.y = r2.x;
102+
r5.z = r3.x;
103+
r5.x = dot(r5.xyzw, cb0[14].xyzw);
104+
r2.x = r8.z;
105+
r8.y = r2.z;
106+
r8.z = r3.y;
107+
r2.z = r3.z;
108+
r8.w = r4.y;
109+
r2.w = r4.z;
110+
r5.z = dot(r2.xyzw, cb0[16].xyzw);
111+
r5.y = dot(r8.xyzw, cb0[15].xyzw);
112+
r0.xyz = r5.xyz * cb0[9].xxx + cb0[9].yyy;
113+
r2.x = saturate(dot(r0.xyz, float3(0.219999999,0.707000017,0.0710000023))); // BOURGIN D65 Y
114+
r2.xyzw = r2.xxxx + -r0.xyzw;
115+
r0.xyzw = cb0[10].xxxx * r2.xyzw + r0.xyzw;
116+
r0.xyzw = float4(1,1,1,1) + -r0.xyzw;
117+
r2.xyzw = -r1.xyzw * r0.xyzw + float4(1,1,1,1);
118+
r0.xyz = -r1.xyz * r0.xyz + float3(0.5,0.5,0.5);
119+
r1.xy = float2(-0.5,-0.5) + w1.xy;
120+
r0.w = dot(r1.xy, r1.xy);
121+
r0.w = sqrt(r0.w);
122+
r0.w = r0.w * 0.720000029 + -0.800000012;
123+
r0.w = saturate(-1.83715463 * r0.w);
124+
r1.x = r0.w * -2 + 3;
125+
r0.w = r0.w * r0.w;
126+
r1.y = r1.x * r0.w + -1;
127+
r0.w = r1.x * r0.w;
128+
r1.x = -r1.y * 0.200000003 + 1;
129+
r1.x = max(1, r1.x);
130+
r0.xyz = r0.xyz * r1.xxx + float3(0.5,0.5,0.5);
131+
r0.xyz = r0.xyz * r0.www + -r2.xyz;
132+
r0.w = 0;
133+
134+
135+
o0.xyzw = cb0[12].yyyy * r0.xyzw + r2.xyzw; // vignette + render
136+
if (injectedData.toneMapType != 0) {
137+
// preserve SDR color grading
138+
o0.xyz = renodx::tonemap::UpgradeToneMap(hdrColor, saturate(hdrColor), o0.xyz, injectedData.colorGradeStrength);
139+
}
140+
return;
141+
}

0 commit comments

Comments
 (0)