From dcbe256699642449882073d8f5731276e6a45cad Mon Sep 17 00:00:00 2001 From: James Horsley Date: Tue, 12 Nov 2024 01:32:11 +0000 Subject: [PATCH] Update for lights, basic light effects work , brightness is now actually used User's brighness setting controls global light brightness Configurable light options available in the ini --- .gitattributes | 1 + Config/D3D9DrvRTX.int | 3 +++ Inc/D3D9RenderDevice.h | 5 +++- Src/D3D9Render.cpp | 2 +- Src/D3D9RenderDevice.cpp | 58 ++++++++++++---------------------------- 5 files changed, 26 insertions(+), 43 deletions(-) diff --git a/.gitattributes b/.gitattributes index 774d8dc..e19b931 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,3 +3,4 @@ *.rc eol=crlf working-tree-encoding=UTF-16LE-BOM *.props eol=crlf *.bat eol=crlf +Config/D3D9DrvRTX.int eol=crlf diff --git a/Config/D3D9DrvRTX.int b/Config/D3D9DrvRTX.int index fdb9cc8..77067a7 100644 --- a/Config/D3D9DrvRTX.int +++ b/Config/D3D9DrvRTX.int @@ -4,6 +4,9 @@ Preferences=(Caption="Rendering",Parent="Advanced Options") Preferences=(Caption="Direct3D 9 RTX Optimised",Parent="Rendering",Class=D3D9DrvRTX.D3D9RenderDevice,Immediate=True) Property=(Config,Class=D3D9DrvRTX.D3D9RenderDevice,Name=EnableSkyBoxAnchors,Title="Enable Skybox Anchors",Description="Enables the special mesh generated for anchoring the skybox in remix.") Property=(Config,Class=D3D9DrvRTX.D3D9RenderDevice,Name=EnableHashTextures,Title="Enable Hash Textures",Description="Enables specially generated textures with a stable hash in place of procedurally generated ones.") +Property=(Config,Class=D3D9DrvRTX.D3D9RenderDevice,Name=LightMultiplier,Title="Light Multiplier",Description="Global light brightness multiplier.") +Property=(Config,Class=D3D9DrvRTX.D3D9RenderDevice,Name=LightRadiusDivisor,Title="Light Radius Divisor",Description="The LightRadius is divided by this value before being exponentiated.") +Property=(Config,Class=D3D9DrvRTX.D3D9RenderDevice,Name=LightRadiusExponent,Title="Light Radius Exponent",Description="LightRadius is raised to the power of this value before being multiplied with the brightness.") [D3D9RenderDevice] ClassCaption="Direct3D 9 RTX Optimised" diff --git a/Inc/D3D9RenderDevice.h b/Inc/D3D9RenderDevice.h index f33aca1..280a10f 100644 --- a/Inc/D3D9RenderDevice.h +++ b/Inc/D3D9RenderDevice.h @@ -502,6 +502,9 @@ class UD3D9RenderDevice : public RENDERDEVICE_SUPER { UBOOL EnableSkyBoxAnchors; UBOOL EnableHashTextures; + FLOAT LightMultiplier; + FLOAT LightRadiusDivisor; + FLOAT LightRadiusExponent; FColor SurfaceSelectionColor; @@ -1217,7 +1220,7 @@ class UD3D9RenderDevice : public RENDERDEVICE_SUPER { // Renders a mover brush void renderMover(FSceneNode* frame, ABrush* mover); // Updates and sends the given lights to dx - void renderLights(std::vector lightActors); + void renderLights(FSceneNode* frame, std::vector lightActors); // Renders a magic shape for anchoring stuff to the sky box void renderSkyZoneAnchor(ASkyZoneInfo* zone, const FVector* location); diff --git a/Src/D3D9Render.cpp b/Src/D3D9Render.cpp index a3e3f42..2f1d74d 100644 --- a/Src/D3D9Render.cpp +++ b/Src/D3D9Render.cpp @@ -329,7 +329,7 @@ void UD3D9Render::DrawWorld(FSceneNode* frame) { d3d9Dev->renderSkyZoneAnchor(zone, &frame->Coords.Origin); } - d3d9Dev->renderLights(lightActors); + d3d9Dev->renderLights(frame, lightActors); d3d9Dev->endWorldDraw(frame); diff --git a/Src/D3D9RenderDevice.cpp b/Src/D3D9RenderDevice.cpp index 05e5f33..502702f 100644 --- a/Src/D3D9RenderDevice.cpp +++ b/Src/D3D9RenderDevice.cpp @@ -264,41 +264,6 @@ class UniqueValueArray { std::unordered_set unique_values; }; -static D3DCOLORVALUE hsvToRgb(unsigned char h, unsigned char s, unsigned char v) { - float H = h / 255.0f; - float S = s / 255.0f; - float V = v / 255.0f; - - float C = V * S; - float X = C * (1 - std::abs(fmod(H * 6, 2) - 1)); - float m = V - C; - - D3DCOLORVALUE rgbColor; - - if (0 <= H && H < 1 / 6.0) { - rgbColor.r = C; rgbColor.g = X; rgbColor.b = 0; - } else if (1 / 6.0 <= H && H < 2 / 6.0) { - rgbColor.r = X; rgbColor.g = C; rgbColor.b = 0; - } else if (2 / 6.0 <= H && H < 3 / 6.0) { - rgbColor.r = 0; rgbColor.g = C; rgbColor.b = X; - } else if (3 / 6.0 <= H && H < 4 / 6.0) { - rgbColor.r = 0; rgbColor.g = X; rgbColor.b = C; - } else if (4 / 6.0 <= H && H < 5 / 6.0) { - rgbColor.r = X; rgbColor.g = 0; rgbColor.b = C; - } else { - rgbColor.r = C; rgbColor.g = 0; rgbColor.b = X; - } - - rgbColor.r += m; - rgbColor.g += m; - rgbColor.b += m; - - // Set alpha value to maximum - rgbColor.a = 1.0f; - - return rgbColor; -} - static inline DirectX::XMMATRIX ToXMMATRIX(const D3DMATRIX& d3dMatrix) { D3DMATRIX temp = d3dMatrix; return reinterpret_cast(temp); @@ -441,6 +406,9 @@ void UD3D9RenderDevice::StaticConstructor() { SC_AddBoolConfigParam(2, TEXT("SmoothMaskedTextures"), CPP_PROPERTY_LOCAL(SmoothMaskedTextures), 0); SC_AddBoolConfigParam(1, TEXT("EnableSkyBoxAnchors"), CPP_PROPERTY_LOCAL(EnableSkyBoxAnchors), 1); SC_AddBoolConfigParam(0, TEXT("EnableHashTextures"), CPP_PROPERTY_LOCAL(EnableHashTextures), 1); + SC_AddFloatConfigParam(TEXT("LightMultiplier"), CPP_PROPERTY_LOCAL(LightMultiplier), 4000.0f); + SC_AddFloatConfigParam(TEXT("LightRadiusDivisor"), CPP_PROPERTY_LOCAL(LightRadiusDivisor), 70.0f); + SC_AddFloatConfigParam(TEXT("LightRadiusExponent"), CPP_PROPERTY_LOCAL(LightRadiusExponent), 0.55f); SurfaceSelectionColor = FColor(0, 0, 31, 31); //new(GetClass(), TEXT("SurfaceSelectionColor"), RF_Public)UStructProperty(CPP_PROPERTY(SurfaceSelectionColor), TEXT("Options"), CPF_Config, FindObjectChecked(NULL, TEXT("Core.Object.Color"), 1)); @@ -4315,7 +4283,7 @@ std::unordered_set UD3D9RenderDevice::LightSlots::updateActors(const std::v return unsetSlots; } -void UD3D9RenderDevice::renderLights(std::vector lightActors) { +void UD3D9RenderDevice::renderLights(FSceneNode* frame, std::vector lightActors) { guard(UD3D9RenderDevice::renderLights); EndBuffering(); @@ -4334,15 +4302,23 @@ void UD3D9RenderDevice::renderLights(std::vector lightActors) { assert(res == D3D_OK); } - for (auto pair : lightSlots->slotMap()) { - AActor* actor = pair.first; - int slot = pair.second; + for (auto& pair : lightSlots->slotMap()) { + AActor* const& actor = pair.first; + const int& slot = pair.second; + FLOAT brightness = actor->LightBrightness / 255.0f; + FPlane colour; + GRender->GlobalLighting(true, actor, brightness, colour); D3DLIGHT9 lightInfo = D3DLIGHT9(); lightInfo.Type = D3DLIGHT_POINT; lightInfo.Position = D3DVECTOR{ actor->Location.X, actor->Location.Y, actor->Location.Z }; - lightInfo.Diffuse = hsvToRgb(actor->LightHue, 0xFFu - actor->LightSaturation, actor->LightBrightness); + lightInfo.Diffuse.r = colour.X; + lightInfo.Diffuse.g = colour.Y; + lightInfo.Diffuse.b = colour.Z; + lightInfo.Diffuse.a = 1.0f; lightInfo.Specular = lightInfo.Diffuse; - lightInfo.Range = 1000; + float brightnessSetting = frame->Viewport->GetOuterUClient()->Brightness * 2.0f; // 0.5 is "normal" + // Some math bollocks that looks ok + lightInfo.Range = brightness * pow((actor->LightRadius / LightRadiusDivisor), LightRadiusExponent) * LightMultiplier * brightnessSetting; HRESULT res = m_d3dDevice->SetLight(slot, &lightInfo); assert(res == D3D_OK); res = m_d3dDevice->LightEnable(slot, true);