From 53d4183ac349021b0eb3cd96639bc2bdc6aab90c Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 29 Mar 2024 02:23:36 +1100 Subject: [PATCH] Add a default brightness limit --- source/base/StarCellularLighting.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/base/StarCellularLighting.cpp b/source/base/StarCellularLighting.cpp index 3e5cf9a..cefd751 100644 --- a/source/base/StarCellularLighting.cpp +++ b/source/base/StarCellularLighting.cpp @@ -154,16 +154,23 @@ void CellularLightingCalculator::calculate(Lightmap& output) { output = Lightmap(arrayMax[0] - arrayMin[0], arrayMax[1] - arrayMin[1]); + float brightnessLimit = m_config.getFloat("brightnessLimit", 1.5f); + if (m_monochrome) { for (size_t x = arrayMin[0]; x < arrayMax[0]; ++x) { for (size_t y = arrayMin[1]; y < arrayMax[1]; ++y) { - output.set(x - arrayMin[0], y - arrayMin[1], m_lightArray.right().getLight(x, y)); + auto light = min(m_lightArray.right().getLight(x, y), brightnessLimit); + output.set(x - arrayMin[0], y - arrayMin[1], light); } } } else { for (size_t x = arrayMin[0]; x < arrayMax[0]; ++x) { for (size_t y = arrayMin[1]; y < arrayMax[1]; ++y) { - output.set(x - arrayMin[0], y - arrayMin[1], m_lightArray.left().getLight(x, y)); + auto light = m_lightArray.left().getLight(x, y); + float intensity = ColoredLightTraits::maxIntensity(light); + if (intensity > brightnessLimit) + light *= brightnessLimit / intensity; + output.set(x - arrayMin[0], y - arrayMin[1], light); } } }