Skip to content

Commit 287a6f3

Browse files
feat(lights): add PointLightIntensity configuration setting (#358)
1 parent ea368a2 commit 287a6f3

7 files changed

Lines changed: 30 additions & 10 deletions

File tree

‎resource/dist/ModelExtras.ini‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CoronaDistanceMul = 0.1 # Scales coronas at distance
5050
CoronaNearClip = 0.45 # Minimum camera clipping distance for coronas
5151
LightShadowDistance = 120.0 # Maximum draw distance for vehicle ground light shadows
5252
HighBeamPointLightMul = 2.0 # Multiplier for high beam point light reach (1.0 matches low beam, up to 4.0)
53+
PointLightIntensity = 0.8 # Brightness multiplier for dynamic point lights (0.0 to 1.0)
5354
LightHeightLimit = 1.4 # Light height limit (0.0 to disable)
5455
MaterialAmbientMul = 1.0 # Multiplier for illuminated light material ambient brightness
5556
LightCoronaSize = 0.3 # Standard base of coronas size for turn and other lights

‎src/ModelExtrasAPI.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,5 +427,10 @@ int ME_GetPedVariationCount(int modelIndex) {
427427
return 0;
428428
}
429429

430+
// Visual & Render Configuration
431+
float ME_GetPointLightIntensity() {
432+
return LightsConfig::Get().fPointLightIntensity;
433+
}
434+
430435
} // extern "C"
431436

‎src/ModelExtrasAPI.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ extern "C"
214214
// Ped Colors
215215
ME_WRAPPER int ME_GetPedVariationCount(int modelIndex);
216216

217+
// Visual & Render Configuration
218+
ME_WRAPPER float ME_GetPointLightIntensity();
219+
217220
#ifdef __cplusplus
218221
}
219222
#endif

‎src/features/lights/data.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct LightsConfig {
5151
bool bFoglightTiedToHeadlight = false;
5252
bool bPlayerIdleBrakeLights = false;
5353
float fHighBeamPointLightMul = 2.0f;
54+
float fPointLightIntensity = 0.8f;
5455

5556
void InitConfig() {
5657
gbGlobalIndicatorLights = gConfig.ReadBoolean("LIGHTS", "StandardLights_GlobalIndicatorLights", gConfig.ReadBoolean("FEATURES", "StandardLights_GlobalIndicatorLights", false));
@@ -84,6 +85,9 @@ struct LightsConfig {
8485

8586
float rawMul = gConfig.ReadFloat("LIGHTS", "HighBeamPointLightMul", gConfig.ReadFloat("TWEAKS", "HighBeamPointLightMul", 2.0f));
8687
fHighBeamPointLightMul = (rawMul < 1.0f) ? 1.0f : ((rawMul > 4.0f) ? 4.0f : rawMul);
88+
89+
float rawIntensity = gConfig.ReadFloat("LIGHTS", "PointLightIntensity", gConfig.ReadFloat("TWEAKS", "PointLightIntensity", 0.8f));
90+
fPointLightIntensity = std::clamp(rawIntensity, 0.0f, 1.0f);
8791
}
8892

8993
private:

‎src/features/sirens.cpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,10 @@ void Sirens::ProcessPointLights(CVehicle *pVeh)
12941294
}
12951295
sirenRadius = std::clamp(sirenRadius, 5.0f, 15.0f);
12961296

1297-
float r = std::clamp(activeColor.r / 255.0f, 0.0f, 1.0f);
1298-
float g = std::clamp(activeColor.g / 255.0f, 0.0f, 1.0f);
1299-
float b = std::clamp(activeColor.b / 255.0f, 0.0f, 1.0f);
1297+
float intensity = LightsConfig::Get().fPointLightIntensity;
1298+
float r = std::clamp((activeColor.r / 255.0f) * intensity, 0.0f, 1.0f);
1299+
float g = std::clamp((activeColor.g / 255.0f) * intensity, 0.0f, 1.0f);
1300+
float b = std::clamp((activeColor.b / 255.0f) * intensity, 0.0f, 1.0f);
13001301

13011302
for (auto &e : data.Dummies[mat.first])
13021303
{
@@ -1369,21 +1370,22 @@ void Sirens::ProcessPointLights(CVehicle *pVeh)
13691370
{
13701371
uint32_t step = (CTimer::m_snTimeInMilliseconds / 120) % 4;
13711372
CMatrix vehMat = pVeh->GetMatrix();
1373+
float intensity = LightsConfig::Get().fPointLightIntensity;
13721374
if (step == 0 || step == 1)
13731375
{
13741376
CVector localLeft(-0.35f, 0.70f, 0.45f);
13751377
CVector plightPos = pVeh->TransformFromObjectSpace(localLeft);
13761378
CVector worldDir = vehMat.up - vehMat.at * 0.25f;
13771379
worldDir.Normalize();
1378-
CPointLights::AddLight(PLTYPE_SPOTLIGHT, plightPos, worldDir, 8.5f, 1.0f, 0.1f, 0.1f, 0, false, nullptr);
1380+
CPointLights::AddLight(PLTYPE_SPOTLIGHT, plightPos, worldDir, 8.5f, 1.0f * intensity, 0.1f * intensity, 0.1f * intensity, 0, false, nullptr);
13791381
}
13801382
else if (step == 2 || step == 3)
13811383
{
13821384
CVector localRight(0.35f, 0.70f, 0.45f);
13831385
CVector plightPos = pVeh->TransformFromObjectSpace(localRight);
13841386
CVector worldDir = vehMat.up - vehMat.at * 0.25f;
13851387
worldDir.Normalize();
1386-
CPointLights::AddLight(PLTYPE_SPOTLIGHT, plightPos, worldDir, 8.5f, 0.1f, 0.1f, 1.0f, 0, false, nullptr);
1388+
CPointLights::AddLight(PLTYPE_SPOTLIGHT, plightPos, worldDir, 8.5f, 0.1f * intensity, 0.1f * intensity, 1.0f * intensity, 0, false, nullptr);
13871389
}
13881390
}
13891391
}

‎src/features/spotlights.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "utils/audiomgr.h"
1313
#include "utils/util.h"
1414
#include "utils/meevents.h"
15+
#include "features/lights/data.h"
1516

1617
using namespace plugin;
1718

@@ -216,12 +217,13 @@ void SpotLights::ProcessPointLights(CVehicle *pVeh)
216217

217218
// 1. 3D Point Light: Placed forward along cone (3.5m) with 18m reach
218219
CVector plightPos = lightPos + lightDir * 3.5f;
220+
float intensity = LightsConfig::Get().fPointLightIntensity;
219221
CPointLights::AddLight(
220222
PLTYPE_SPOTLIGHT,
221223
plightPos,
222224
lightDir,
223225
18.0f,
224-
1.2f, 1.2f, 1.2f,
226+
1.2f * intensity, 1.2f * intensity, 1.2f * intensity,
225227
0,
226228
false,
227229
nullptr

‎src/utils/render.cpp‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "utils/texmgr.h"
1010
#include "defines.h"
1111
#include "features/core/dummy.h"
12+
#include "features/lights/data.h"
1213
#include <CPointLights.h>
1314

1415
inline CVector2D GetPerpRight(const CVector2D &vec)
@@ -198,8 +199,9 @@ void RenderUtil::RegisterHeadlightPointLight(const DummyConfig *pConfig, float r
198199
lightDir.Normalize();
199200

200201
CRGBA col = pConfig->corona.color;
202+
float intensity = LightsConfig::Get().fPointLightIntensity;
201203
CPointLights::AddLight(PLTYPE_SPOTLIGHT, lightPos, lightDir, HEADLIGHT_PLIGHT_RANGE * rangeMul,
202-
col.r / 255.0f, col.g / 255.0f, col.b / 255.0f, 0, 0, 0);
204+
(col.r / 255.0f) * intensity, (col.g / 255.0f) * intensity, (col.b / 255.0f) * intensity, 0, 0, 0);
203205
}
204206

205207
void RenderUtil::RegisterPointLight(const DummyConfig *pConfig, CRGBA col, float radius, bool isSpotlight)
@@ -379,9 +381,10 @@ void RenderUtil::RegisterPointLight(const DummyConfig *pConfig, CRGBA col, float
379381
CVector plightPos = lightPos + lightDir * pushDist;
380382

381383
constexpr float INV_255 = 1.0f / 255.0f;
382-
float r = std::clamp(col.r * INV_255, 0.0f, 1.0f);
383-
float g = std::clamp(col.g * INV_255, 0.0f, 1.0f);
384-
float b = std::clamp(col.b * INV_255, 0.0f, 1.0f);
384+
float intensity = LightsConfig::Get().fPointLightIntensity;
385+
float r = std::clamp((col.r * INV_255) * intensity, 0.0f, 1.0f);
386+
float g = std::clamp((col.g * INV_255) * intensity, 0.0f, 1.0f);
387+
float b = std::clamp((col.b * INV_255) * intensity, 0.0f, 1.0f);
385388

386389
unsigned char lightType = isSpotlight ? PLTYPE_SPOTLIGHT : PLTYPE_POINTLIGHT;
387390
CPointLights::AddLight(lightType, plightPos, lightDir, radius, r, g, b, 0, false, nullptr);

0 commit comments

Comments
 (0)