diff --git a/include/light/surflight.hh b/include/light/surflight.hh index adfab9dc..eb35e0a2 100644 --- a/include/light/surflight.hh +++ b/include/light/surflight.hh @@ -26,6 +26,11 @@ See file, 'COPYING', for details. typedef struct { vec3_t pos; qvec3f surfnormal; + /** + * disables use of the surfnormal. We set this to true on sky surface lights, + * to avoid black seams on geometry meeting the sky + */ + bool omnidirectional; std::vector points; // Surface light settings... diff --git a/light/ltface.cc b/light/ltface.cc index 55a4ecdc..98d6971a 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1921,19 +1921,29 @@ static qvec3f GetSurfaceLighting(const globalconfig_t &cfg, const surfacelight_t *vpl, const qvec3f &dir, const float dist, const qvec3f &normal) { qvec3f result{0}; - const float dp1 = qv::dot(vpl->surfnormal, dir); - if (dp1 < 0.0f) return result; // sample point behind vpl + float dotProductFactor = 1.0f; + const float dp1 = qv::dot(vpl->surfnormal, dir); const qvec3f sp_vpl = dir * -1.0f; float dp2 = qv::dot(sp_vpl, normal); - if (dp2 < 0.0f) return result; // vpl behind sample face + + if (!vpl->omnidirectional) { + if (dp1 < 0.0f) return {0}; // sample point behind vpl + if (dp2 < 0.0f) return {0}; // vpl behind sample face + + dp2 = 0.5f + dp2 * 0.5f; // Rescale a bit to brighten the faces nearly-perpendicular to the surface light plane... + + dotProductFactor = dp1 * dp2; + } else { + // used for sky face surface lights + dotProductFactor = dp2; + } // Get light contribution result = SurfaceLight_ColorAtDist(cfg, vpl->intensity, vec3_t_to_glm(vpl->color), dist); - dp2 = 0.5f + dp2 * 0.5f; // Rescale a bit to brighten the faces nearly-perpendicular to the surface light plane... - + // Apply angle scale - const qvec3f resultscaled = result * dp1 * dp2; + const qvec3f resultscaled = result * dotProductFactor; Q_assert(!std::isnan(resultscaled[0]) && !std::isnan(resultscaled[1]) && !std::isnan(resultscaled[2])); return resultscaled; diff --git a/light/surflight.cc b/light/surflight.cc index ca5dba6d..47bd4036 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -149,6 +149,7 @@ MakeSurfaceLightsThread(void *arg) // Add surfacelight... surfacelight_t l; l.surfnormal = vec3_t_to_glm(facenormal); + l.omnidirectional = (info->flags & Q2_SURF_SKY) ? true : false; l.points = points; VectorCopy(facemidpoint, l.pos);