Browse Source

Hellfire: Fix light fall off not with in it's radious

pull/6036/head
Anders Jenbo 3 years ago
parent
commit
eef0b10e1f
  1. 39
      Source/lighting.cpp

39
Source/lighting.cpp

@ -369,29 +369,26 @@ void MakeLightTable()
LoadFileInMem("gendata\\pause.trn", PauseTable);
// Generate light falloffs ranges
if (IsAnyOf(leveltype, DTYPE_NEST, DTYPE_CRYPT)) {
for (size_t j = 0; j < NumLightRadiuses; j++) {
double fa = (sqrt((double)(16 - j))) / 128;
fa *= fa;
for (int i = 0; i < 128; i++) {
uint8_t color = 15 - static_cast<uint8_t>(fa * (double)((128 - i) * (128 - i)));
if (color > 15)
color = 0;
color -= static_cast<uint8_t>((NumLightRadiuses - j - 1) / 2);
if (color > 15)
color = 0;
LightFalloffs[NumLightRadiuses - j - 1][i] = color;
}
}
} else {
for (size_t j = 0; j < NumLightRadiuses; j++) {
for (size_t i = 0; i < 128; i++) {
if (i > (j + 1) * 8) {
LightFalloffs[j][i] = 15;
const float maxDarkness = 15;
const float maxBrightness = 0;
for (size_t radius = 0; radius < NumLightRadiuses; radius++) {
size_t maxDistance = (radius + 1) * 8;
for (size_t distance = 0; distance < 128; distance++) {
if (distance > maxDistance) {
LightFalloffs[radius][distance] = 15;
} else {
const float factor = static_cast<float>(distance) / maxDistance;
float scaled;
if (IsAnyOf(leveltype, DTYPE_NEST, DTYPE_CRYPT)) {
// quardratic falloff with over exposure
const float brightness = radius * 1.5;
scaled = factor * factor * brightness + (maxDarkness - brightness);
scaled = std::max(maxBrightness, scaled);
} else {
double fs = (double)15 * i / ((double)8 * (j + 1));
LightFalloffs[j][i] = static_cast<uint8_t>(fs + 0.5);
// Leaner falloff
scaled = factor * maxDarkness;
}
LightFalloffs[radius][distance] = static_cast<uint8_t>(scaled + 0.5F); // round up
}
}
}

Loading…
Cancel
Save