diff --git a/README.md b/README.md index 578b834..1eaeebe 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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 - defaults to 1.0 + vk_saturation - defaults to 1.0 + vk_brightness - defaults to 0.0 + vk_grayformula - 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. diff --git a/VulkanDrv/FileResource.cpp b/VulkanDrv/FileResource.cpp index 9fde5a4..da04511 100644 --- a/VulkanDrv/FileResource.cpp +++ b/VulkanDrv/FileResource.cpp @@ -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; @@ -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); } )"; } diff --git a/VulkanDrv/ShaderManager.h b/VulkanDrv/ShaderManager.h index b1a6f00..c440fd3 100644 --- a/VulkanDrv/ShaderManager.h +++ b/VulkanDrv/ShaderManager.h @@ -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 diff --git a/VulkanDrv/UVulkanRenderDevice.cpp b/VulkanDrv/UVulkanRenderDevice.cpp index 571f2b6..81ba1b4 100644 --- a/VulkanDrv/UVulkanRenderDevice.cpp +++ b/VulkanDrv/UVulkanRenderDevice.cpp @@ -35,6 +35,11 @@ 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); @@ -42,6 +47,11 @@ void UVulkanRenderDevice::StaticConstructor() 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; } @@ -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"))) @@ -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; diff --git a/VulkanDrv/UVulkanRenderDevice.h b/VulkanDrv/UVulkanRenderDevice.h index 2d512ae..564f62e 100644 --- a/VulkanDrv/UVulkanRenderDevice.h +++ b/VulkanDrv/UVulkanRenderDevice.h @@ -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);