From a79ea9414b824886b0ce1e1db2377648d0b38aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 6 Oct 2024 20:27:21 -0300 Subject: [PATCH] inverse square lights for sprites had to add a minimum distance to make sure smaller lights don't completely blow out actors nearby --- .../hwrenderer/scene/hw_spritelight.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index 031262daf..866024653 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -112,6 +112,15 @@ public: // //========================================================================== + +float inverseSquareAttenuation(FVector3 lightpos, float dist, float radius) +{ + float strength = 1500.0; + float a = dist / radius; + float b = clamp(1.0 - a * a * a * a, 0.0, 1.0); + return (b * b) / (dist * dist + 1.0) * strength; +} + void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLightNode *node, int portalgroup, float *out) { FDynamicLight *light; @@ -167,7 +176,14 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLig if (staticLight.TraceLightVisbility(node, L, dist)) { - frac = 1.0f - (dist / radius); + if(level.info->lightattenuationmode == ELightAttenuationMode::INVERSE_SQUARE) + { + frac = (inverseSquareAttenuation(L, std::max(dist, sqrt(radius) * 2), radius)); + } + else + { + frac = 1.0f - (dist / radius); + } if (light->IsSpot()) {