From 0baa788d7e3805e39510d8e6211f0cf1f693b766 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 2 Jul 2022 16:59:04 -0400 Subject: [PATCH] fix bounced lighting --- light/bounce.cc | 11 +++++++++-- light/ltface.cc | 13 ++++--------- light/surflight.cc | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/light/bounce.cc b/light/bounce.cc index a1e68823..281aeeb4 100644 --- a/light/bounce.cc +++ b/light/bounce.cc @@ -71,6 +71,14 @@ static bool Face_ShouldBounce(const mbsp_t *bsp, const mface_t *face) return false; } + // don't bounce *from* emission surfaces + // FIXME: better way that works for Q1 too + if (bsp->loadversion->game->id == GAME_QUAKE_II) { + if (bsp->texinfo[face->texinfo].flags.native & Q2_SURF_LIGHT) { + return false; + } + } + return true; } @@ -163,7 +171,7 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m return; } - const vec_t sample_scalar = 1.f / area; + const vec_t sample_scalar = 1.f / sqrt(area); qplane3d faceplane = winding.plane(); @@ -183,7 +191,6 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m for (auto &styleColor : sum) { styleColor.second *= sample_scalar; - styleColor.second /= 255.0f; styleColor.second *= cfg.bouncescale.value(); total += styleColor.second; } diff --git a/light/ltface.cc b/light/ltface.cc index 445cb179..a2a6e594 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1841,18 +1841,13 @@ static void LightFace_BounceLightsDebug(const lightsurf_t *lightsurf, lightmapdi // returns color in [0,255] inline qvec3f BounceLight_ColorAtDist( - const settings::worldspawn_keys &cfg, float area, const qvec3f &bounceLightColor, float dist) + const settings::worldspawn_keys &cfg, float area, const qvec3f &color, float dist) { - // clamp away hotspots - if (dist < 128.0f) { - dist = 128.0f; - } - - const float dist2 = (dist * dist); - const float scale = (1.0f / dist2); + const float d = max(dist, 128.f); // Clamp away hotspots, also avoid division by 0.. + const float scale = (1.0f / (d * d)); // get light contribution - return bounceLightColor * area * (255.0f * scale); + return color * area * scale; } // mxd. Surface light falloff. Returns color in [0,255] diff --git a/light/surflight.cc b/light/surflight.cc index 41ee42d2..ae932df1 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -159,7 +159,7 @@ static void MakeSurfaceLightsThread(const mbsp_t *bsp, const settings::worldspaw return; } - MakeSurfaceLight(bsp, cfg, face, std::nullopt, false, (info->flags.native & Q2_SURF_SKY), 0, info->value); + MakeSurfaceLight(bsp, cfg, face, std::nullopt, false/*!(info->flags.native & Q2_SURF_SKY)*/, (info->flags.native & Q2_SURF_SKY), 0, info->value); } // check matching templates