Skip to content

Commit 4159496

Browse files
committed
"Borderless colors fix" concept > new "PostFX" settings tab (Supports also fullscreen) to let the user decide and customize. Disabled by default.
Also switch up technique for the boosts to tonemap, DWM kept ignoring our values and just applied max all the time, which is a limitation.
1 parent 9ed5455 commit 4159496

File tree

8 files changed

+1175
-93
lines changed

8 files changed

+1175
-93
lines changed

Client/core/CClientVariables.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ void CClientVariables::ValidateValues()
265265
ClampValue("voicevolume", 0.0f, 1.0f);
266266
ClampValue("mapalpha", 0, 255);
267267
ClampValue("mapimage", 0, 1);
268+
ClampValue("borderless_gamma_power", 0.5f, 2.0f);
269+
ClampValue("borderless_brightness_scale", 0.5f, 2.0f);
270+
ClampValue("borderless_contrast_scale", 0.5f, 2.0f);
271+
ClampValue("borderless_saturation_scale", 0.5f, 2.0f);
272+
ClampValue("borderless_gamma_enabled", false, true);
273+
ClampValue("borderless_brightness_enabled", false, true);
274+
ClampValue("borderless_contrast_enabled", false, true);
275+
ClampValue("borderless_saturation_enabled", false, true);
276+
ClampValue("borderless_apply_windowed", false, true);
277+
ClampValue("borderless_apply_fullscreen", false, true);
268278
}
269279

270280
void CClientVariables::LoadDefaults()
@@ -348,6 +358,24 @@ void CClientVariables::LoadDefaults()
348358
DEFAULT("display_fullscreen_style", 0); // 0-standard 1-borderless 2-borderless keep res 3-borderless stretch
349359
DEFAULT("display_windowed", 0); // 0-off 1-on
350360
DEFAULT("multimon_fullscreen_minimize", 1); // 0-off 1-on
361+
DEFAULT("borderless_gamma_power", 0.95f); // Gamma exponent applied to windowed gamma ramp (1.0 = unchanged)
362+
DEFAULT("borderless_brightness_scale", 1.03f); // Brightness multiplier for windowed gamma ramp (1.0 = unchanged)
363+
DEFAULT("borderless_contrast_scale", 1.0f); // Contrast multiplier for borderless presentation (1.0 = unchanged)
364+
DEFAULT("borderless_saturation_scale", 1.0f); // Saturation multiplier for borderless presentation (1.0 = unchanged)
365+
DEFAULT("borderless_enable_srgb", false); // Enable sRGB correction when running borderless
366+
DEFAULT("borderless_gamma_enabled", false); // Apply gamma adjustment while borderless tuning active
367+
DEFAULT("borderless_brightness_enabled", false); // Apply brightness adjustment while borderless tuning active
368+
DEFAULT("borderless_contrast_enabled", false); // Apply contrast adjustment while borderless tuning active
369+
DEFAULT("borderless_saturation_enabled", false); // Apply saturation adjustment while borderless tuning active
370+
DEFAULT("borderless_apply_windowed", false); // Apply display adjustments while windowed/borderless
371+
DEFAULT("borderless_apply_fullscreen", false); // Apply display adjustments while in exclusive fullscreen
372+
373+
if (Exists("borderless_enable_srgb"))
374+
{
375+
bool legacyEnable = false;
376+
Get("borderless_enable_srgb", legacyEnable);
377+
Set("borderless_apply_windowed", legacyEnable);
378+
}
351379
DEFAULT("vertical_aim_sensitivity", 0.0015f); // 0.0015f is GTA default setting
352380
DEFAULT("process_priority", 0); // 0-normal 1-above normal 2-high
353381
DEFAULT("process_dpi_aware", false); // Enable DPI awareness in core initialization

Client/core/CScreenShot.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include "DXHook/CProxyDirect3DDevice9.h"
14+
#include <math.h>
1315
#include <libpng/png.h>
1416

1517
extern CCore* g_pCore;
@@ -38,6 +40,86 @@ static uint ms_uiHeight = 0;
3840
// whether we want to actually save photo in documents folder
3941
static bool savePhotoInDocuments = false;
4042

43+
namespace
44+
{
45+
float Clamp(float value, float minValue, float maxValue)
46+
{
47+
if (value < minValue)
48+
return minValue;
49+
if (value > maxValue)
50+
return maxValue;
51+
return value;
52+
}
53+
54+
void ApplyBorderlessAdjustmentsToBuffer(void* rawData, uint width, uint height)
55+
{
56+
if (!rawData || width == 0 || height == 0)
57+
return;
58+
59+
bool isBorderless = false;
60+
if (CVideoModeManagerInterface* videoModeManager = GetVideoModeManager())
61+
isBorderless = videoModeManager->IsDisplayModeWindowed() || videoModeManager->IsDisplayModeFullScreenWindow();
62+
63+
if (!isBorderless && ::g_pDeviceState)
64+
isBorderless = (::g_pDeviceState->CreationState.PresentationParameters.Windowed != 0);
65+
66+
float gammaPower = 1.0f;
67+
float brightnessScale = 1.0f;
68+
float contrastScale = 1.0f;
69+
float saturationScale = 1.0f;
70+
bool applyWindowed = true;
71+
bool applyFullscreen = false;
72+
::BorderlessGamma::FetchSettings(gammaPower, brightnessScale, contrastScale, saturationScale, applyWindowed, applyFullscreen);
73+
74+
const bool adjustmentsEnabled = isBorderless ? applyWindowed : applyFullscreen;
75+
if (!adjustmentsEnabled)
76+
return;
77+
78+
if (!::BorderlessGamma::ShouldApplyAdjustments(gammaPower, brightnessScale, contrastScale, saturationScale))
79+
return;
80+
81+
BYTE* data = static_cast<BYTE*>(rawData);
82+
const size_t pixelCount = static_cast<size_t>(width) * static_cast<size_t>(height);
83+
const float inv255 = 1.0f / 255.0f;
84+
const float contrastPivot = 0.5f;
85+
86+
for (size_t i = 0; i < pixelCount; ++i)
87+
{
88+
float r = Clamp(data[0] * inv255, 0.0f, 1.0f);
89+
float g = Clamp(data[1] * inv255, 0.0f, 1.0f);
90+
float b = Clamp(data[2] * inv255, 0.0f, 1.0f);
91+
92+
r = powf(r, gammaPower);
93+
g = powf(g, gammaPower);
94+
b = powf(b, gammaPower);
95+
96+
r *= brightnessScale;
97+
g *= brightnessScale;
98+
b *= brightnessScale;
99+
100+
r = (r - contrastPivot) * contrastScale + contrastPivot;
101+
g = (g - contrastPivot) * contrastScale + contrastPivot;
102+
b = (b - contrastPivot) * contrastScale + contrastPivot;
103+
104+
float luminance = Clamp(0.299f * r + 0.587f * g + 0.114f * b, 0.0f, 1.0f);
105+
106+
r = luminance + (r - luminance) * saturationScale;
107+
g = luminance + (g - luminance) * saturationScale;
108+
b = luminance + (b - luminance) * saturationScale;
109+
110+
r = Clamp(r, 0.0f, 1.0f);
111+
g = Clamp(g, 0.0f, 1.0f);
112+
b = Clamp(b, 0.0f, 1.0f);
113+
114+
data[0] = static_cast<BYTE>(r * 255.0f + 0.5f);
115+
data[1] = static_cast<BYTE>(g * 255.0f + 0.5f);
116+
data[2] = static_cast<BYTE>(b * 255.0f + 0.5f);
117+
118+
data += 4;
119+
}
120+
}
121+
} // namespace
122+
41123
void CScreenShot::InitiateScreenShot(bool bIsCameraShot)
42124
{
43125
if (ms_bScreenShot || ms_bIsSaving || IsRateLimited(bIsCameraShot))
@@ -109,6 +191,7 @@ void CScreenShot::CheckForScreenShot(bool bBeforeGUI)
109191

110192
if (uiDataSize == uiReqDataSize)
111193
{
194+
ApplyBorderlessAdjustmentsToBuffer(ms_ScreenShotBuffer.GetData(), ms_uiWidth, ms_uiHeight);
112195
// Start the save thread
113196
StartSaveThread();
114197
}

0 commit comments

Comments
 (0)