Skip to content

Commit

Permalink
Update for lights, basic light effects work , brightness is now actua…
Browse files Browse the repository at this point in the history
…lly used

User's brighness setting controls global light brightness
Configurable light options available in the ini
  • Loading branch information
mmdanggg2 committed Nov 12, 2024
1 parent 0901636 commit dcbe256
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.rc eol=crlf working-tree-encoding=UTF-16LE-BOM
*.props eol=crlf
*.bat eol=crlf
Config/D3D9DrvRTX.int eol=crlf
3 changes: 3 additions & 0 deletions Config/D3D9DrvRTX.int
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion Inc/D3D9RenderDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ class UD3D9RenderDevice : public RENDERDEVICE_SUPER {

UBOOL EnableSkyBoxAnchors;
UBOOL EnableHashTextures;
FLOAT LightMultiplier;
FLOAT LightRadiusDivisor;
FLOAT LightRadiusExponent;

FColor SurfaceSelectionColor;

Expand Down Expand Up @@ -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<AActor*> lightActors);
void renderLights(FSceneNode* frame, std::vector<AActor*> lightActors);
// Renders a magic shape for anchoring stuff to the sky box
void renderSkyZoneAnchor(ASkyZoneInfo* zone, const FVector* location);

Expand Down
2 changes: 1 addition & 1 deletion Src/D3D9Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
58 changes: 17 additions & 41 deletions Src/D3D9RenderDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,41 +264,6 @@ class UniqueValueArray {
std::unordered_set<T> 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<DirectX::XMMATRIX&>(temp);
Expand Down Expand Up @@ -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<UStruct>(NULL, TEXT("Core.Object.Color"), 1));
Expand Down Expand Up @@ -4315,7 +4283,7 @@ std::unordered_set<int> UD3D9RenderDevice::LightSlots::updateActors(const std::v
return unsetSlots;
}

void UD3D9RenderDevice::renderLights(std::vector<AActor*> lightActors) {
void UD3D9RenderDevice::renderLights(FSceneNode* frame, std::vector<AActor*> lightActors) {
guard(UD3D9RenderDevice::renderLights);

EndBuffering();
Expand All @@ -4334,15 +4302,23 @@ void UD3D9RenderDevice::renderLights(std::vector<AActor*> 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);
Expand Down

0 comments on commit dcbe256

Please sign in to comment.