From 4e9e94e7bdafe57639aeef86df49920967dd7663 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 25 Jun 2020 00:03:38 -0600 Subject: [PATCH] ltface: GetLightContrib: handle light right on top of sample point --- light/ltface.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/light/ltface.cc b/light/ltface.cc index f7966dba..5ce4f001 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1025,7 +1025,13 @@ void GetLightContrib(const globalconfig_t &cfg, const light_t *entity, const vec3_t surfnorm, const vec3_t surfpoint, bool twosided, vec3_t color_out, vec3_t surfpointToLightDir_out, vec3_t normalmap_addition_out, float *dist_out) { - const float dist = GetDir(surfpoint, *entity->origin.vec3Value(), surfpointToLightDir_out); + float dist = GetDir(surfpoint, *entity->origin.vec3Value(), surfpointToLightDir_out); + if (dist < 0.1) { + // Catch 0 distance between sample point and light (produces infinite brightness / nan's) and causes + // problems later + dist = 0.1; + VectorSet(surfpointToLightDir_out, 0, 0, 1); + } const float add = GetLightValueWithAngle(cfg, entity, surfnorm, surfpointToLightDir_out, dist, twosided); /* write out the final color */