Skip to content

Commit

Permalink
Add brightness controls
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Aug 5, 2022
1 parent ed9191c commit 01036c4
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This project implements a vulkan render device for Unreal Tournament (UT99).

The project files were made for Visual Studio 2019. Open VulkanDrv.sln, select the release configuration and press build.

Note: This project can no longer be built without the 469 SDK. It also requires 469c to run.

## Using VulkanDrv as the render device

Copy the VulkanDrv.dll and VulkanDrv.int files to the Unreal Tournament system folder.
Expand All @@ -16,7 +18,6 @@ Add the following section to the file:
[VulkanDrv.VulkanRenderDevice]
UsePrecache=False
UseVSync=True
FPSLimit=200
Multisample=16
DetailTextures=True
DescFlags=0
Expand All @@ -32,6 +33,20 @@ The VkDeviceIndex selects which vulkan device in the system the render device sh

For debugging, VkDebug can be set to true. This enables the vulkan debug layer and will cause the render device to output extra information into the UnrealTournament.log file. 'VkMemStats' can also be typed into the console.

## Brightness controls console commands:

vk_contrast <number> - defaults to 1.0
vk_saturation <number> - defaults to 1.0
vk_brightness <number> - defaults to 0.0
vk_grayformula <number> - defaults to 1, can be 0, 1 or 2

## Debugging console commands:

vstat memory
vstat resources
vstat draw
vkmemstats

## License

Please see LICENSE.md for the details.
27 changes: 23 additions & 4 deletions VulkanDrv/FileResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,13 @@ std::string FileResource::readAllText(const std::string& filename)
layout(push_constant) uniform PresentPushConstants
{
float InvGamma;
float padding1;
float padding2;
float padding3;
float Contrast;
float Saturation;
float Brightness;
int GrayFormula;
int Padding1;
int Padding2;
int Padding3;
};
layout(binding = 0) uniform sampler2D texSampler;
Expand All @@ -188,9 +192,24 @@ std::string FileResource::readAllText(const std::string& filename)
return mix(c * 12.92, 1.055 * pow(c, vec3(1.0/2.4)) - 0.055, step(c, vec3(0.0031308)));
}
vec3 applyGamma(vec3 c)
{
vec3 valgray;
if (GrayFormula == 0)
valgray = vec3(c.r + c.g + c.b) * (1 - Saturation) / 3 + c * Saturation;
else if (GrayFormula == 2) // new formula
valgray = mix(vec3(pow(dot(pow(c, vec3(2.2)), vec3(0.2126, 0.7152, 0.0722)), 1.0/2.2)), c, Saturation);
else
valgray = mix(vec3(dot(c, vec3(0.3,0.56,0.14))), c, Saturation);
vec3 val = valgray * Contrast - (Contrast - 1.0) * 0.5;
val += Brightness * 0.5;
val = pow(max(val, vec3(0.0)), vec3(InvGamma));
return val;
}
void main()
{
outColor = vec4(dither(pow(texture(texSampler, texCoord).rgb, vec3(InvGamma))), 1.0f);
outColor = vec4(dither(applyGamma(texture(texSampler, texCoord).rgb)), 1.0f);
}
)";
}
Expand Down
10 changes: 7 additions & 3 deletions VulkanDrv/ShaderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ struct ScenePushConstants
struct PresentPushConstants
{
float InvGamma;
float padding1;
float padding2;
float padding3;
float Contrast;
float Saturation;
float Brightness;
int GrayFormula;
int32_t padding1;
int32_t padding2;
int32_t padding3;
};

class ShaderManager
Expand Down
42 changes: 42 additions & 0 deletions VulkanDrv/UVulkanRenderDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ void UVulkanRenderDevice::StaticConstructor()
SupportsUpdateTextureRect = 1;
MaxTextureSize = 4096;

VkBrightness = 0.0f;
VkContrast = 1.0f;
VkSaturation = 1.0f;
VkGrayFormula = 1;

new(GetClass(), TEXT("UseLightmapAtlas"), RF_Public) UBoolProperty(CPP_PROPERTY(UseLightmapAtlas), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("UseVSync"), RF_Public) UBoolProperty(CPP_PROPERTY(UseVSync), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("UsePrecache"), RF_Public) UBoolProperty(CPP_PROPERTY(UsePrecache), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("Multisample"), RF_Public) UIntProperty(CPP_PROPERTY(Multisample), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("VkDeviceIndex"), RF_Public) UIntProperty(CPP_PROPERTY(VkDeviceIndex), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("VkDebug"), RF_Public) UBoolProperty(CPP_PROPERTY(VkDebug), TEXT("Display"), CPF_Config);

new(GetClass(), TEXT("VkBrightness"), RF_Public) UFloatProperty(CPP_PROPERTY(VkBrightness), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("VkContrast"), RF_Public) UFloatProperty(CPP_PROPERTY(VkContrast), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("VkSaturation"), RF_Public) UFloatProperty(CPP_PROPERTY(VkSaturation), TEXT("Display"), CPF_Config);
new(GetClass(), TEXT("VkGrayFormula"), RF_Public) UIntProperty(CPP_PROPERTY(VkGrayFormula), TEXT("Display"), CPF_Config);

unguard;
}

Expand Down Expand Up @@ -240,6 +250,34 @@ UBOOL UVulkanRenderDevice::Exec(const TCHAR* Cmd, FOutputDevice& Ar)
{
return 1;
}
else if (ParseCommand(&Cmd, TEXT("vk_contrast")))
{
float value = _wtof(Cmd);
VkContrast = clamp(value, 0.1f, 3.f);
SaveConfig();
return 1;
}
else if (ParseCommand(&Cmd, TEXT("vk_saturation")))
{
float value = _wtof(Cmd);
VkSaturation = clamp(value, -0.8f, 0.8f);
SaveConfig();
return 1;
}
else if (ParseCommand(&Cmd, TEXT("vk_brightness")))
{
float value = _wtof(Cmd);
VkBrightness = clamp(value, -15.0f, 15.f);
SaveConfig();
return 1;
}
else if (ParseCommand(&Cmd, TEXT("vk_grayformula")))
{
int value = _wtoi(Cmd);
VkGrayFormula = clamp(value, 0, 2);
SaveConfig();
return 1;
}
else if (ParseCommand(&Cmd, TEXT("DGL")))
{
if (ParseCommand(&Cmd, TEXT("BUFFERTRIS")))
Expand Down Expand Up @@ -1209,6 +1247,10 @@ void UVulkanRenderDevice::DrawPresentTexture(int x, int y, int width, int height

PresentPushConstants pushconstants;
pushconstants.InvGamma = 1.0f / gamma;
pushconstants.Contrast = clamp(VkContrast, 0.1f, 3.f);
pushconstants.Saturation = clamp(VkSaturation, -0.8f, 0.8f);
pushconstants.Brightness = clamp(VkBrightness, -15.0f, 15.f);
pushconstants.GrayFormula = clamp(VkGrayFormula, 0, 2);

VkViewport viewport = {};
viewport.x = x;
Expand Down
4 changes: 4 additions & 0 deletions VulkanDrv/UVulkanRenderDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class UVulkanRenderDevice : public URenderDeviceOldUnreal469
INT VkDeviceIndex;
BITFIELD VkDebug;
INT Multisample;
FLOAT VkBrightness;
FLOAT VkContrast;
FLOAT VkSaturation;
INT VkGrayFormula;

void DrawPresentTexture(int x, int y, int width, int height);

Expand Down

0 comments on commit 01036c4

Please sign in to comment.