Skip to content

Commit 6a718c7

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 e026911 commit 6a718c7

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
@@ -257,6 +257,16 @@ void CClientVariables::ValidateValues()
257257
ClampValue("voicevolume", 0.0f, 1.0f);
258258
ClampValue("mapalpha", 0, 255);
259259
ClampValue("mapimage", 0, 1);
260+
ClampValue("borderless_gamma_power", 0.5f, 2.0f);
261+
ClampValue("borderless_brightness_scale", 0.5f, 2.0f);
262+
ClampValue("borderless_contrast_scale", 0.5f, 2.0f);
263+
ClampValue("borderless_saturation_scale", 0.5f, 2.0f);
264+
ClampValue("borderless_gamma_enabled", false, true);
265+
ClampValue("borderless_brightness_enabled", false, true);
266+
ClampValue("borderless_contrast_enabled", false, true);
267+
ClampValue("borderless_saturation_enabled", false, true);
268+
ClampValue("borderless_apply_windowed", false, true);
269+
ClampValue("borderless_apply_fullscreen", false, true);
260270
}
261271

262272
void CClientVariables::LoadDefaults()
@@ -338,6 +348,24 @@ void CClientVariables::LoadDefaults()
338348
DEFAULT("display_fullscreen_style", 0); // 0-standard 1-borderless 2-borderless keep res 3-borderless stretch
339349
DEFAULT("display_windowed", 0); // 0-off 1-on
340350
DEFAULT("multimon_fullscreen_minimize", 1); // 0-off 1-on
351+
DEFAULT("borderless_gamma_power", 0.95f); // Gamma exponent applied to windowed gamma ramp (1.0 = unchanged)
352+
DEFAULT("borderless_brightness_scale", 1.03f); // Brightness multiplier for windowed gamma ramp (1.0 = unchanged)
353+
DEFAULT("borderless_contrast_scale", 1.0f); // Contrast multiplier for borderless presentation (1.0 = unchanged)
354+
DEFAULT("borderless_saturation_scale", 1.0f); // Saturation multiplier for borderless presentation (1.0 = unchanged)
355+
DEFAULT("borderless_enable_srgb", false); // Enable sRGB correction when running borderless
356+
DEFAULT("borderless_gamma_enabled", false); // Apply gamma adjustment while borderless tuning active
357+
DEFAULT("borderless_brightness_enabled", false); // Apply brightness adjustment while borderless tuning active
358+
DEFAULT("borderless_contrast_enabled", false); // Apply contrast adjustment while borderless tuning active
359+
DEFAULT("borderless_saturation_enabled", false); // Apply saturation adjustment while borderless tuning active
360+
DEFAULT("borderless_apply_windowed", false); // Apply display adjustments while windowed/borderless
361+
DEFAULT("borderless_apply_fullscreen", false); // Apply display adjustments while in exclusive fullscreen
362+
363+
if (Exists("borderless_enable_srgb"))
364+
{
365+
bool legacyEnable = false;
366+
Get("borderless_enable_srgb", legacyEnable);
367+
Set("borderless_apply_windowed", legacyEnable);
368+
}
341369
DEFAULT("vertical_aim_sensitivity", 0.0015f); // 0.0015f is GTA default setting
342370
DEFAULT("process_priority", 0); // 0-normal 1-above normal 2-high
343371
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)