diff --git a/light/ltface.c b/light/ltface.c index 0bc3aef7..b3d977a0 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -635,20 +635,25 @@ CalcPoints(const modelinfo_t *modelinfo, const vec3_t offset, const texorg_t *te VectorCopy(surf->plane.normal, norm); } - vec3_t tracevec, tracedir; - VectorSubtract(point, surf->midpoint, tracevec); - VectorCopy(tracevec, tracedir); - VectorNormalize(tracedir); - - // trace 1 unit further than we need to go to ensure 1 unit clearance - const vec_t dist = VectorLength(tracevec) + 1; - - vec_t hitdist = 0; - vec3_t hitnormal = {0}; - if (CalcPointsTrace_embree(surf->midpoint, tracedir, dist, &hitdist, hitnormal, surf->modelinfo)) { - // we hit a solid. pull back 1 unit from the hitpoint and hope that's in empty space. - hitdist = qmax(0.0f, hitdist - 1.0f); - VectorMA(surf->midpoint, hitdist, tracedir, point); + for (int tries=0; tries<5; tries++) { + vec3_t tracevec, tracedir; + VectorSubtract(point, surf->midpoint, tracevec); + VectorCopy(tracevec, tracedir); + VectorNormalize(tracedir); + + // trace 1 unit further than we need to go to ensure 1 unit clearance + const vec_t dist = VectorLength(tracevec) + 1; + + vec_t hitdist = 0; + vec3_t hitnormal = {0}; + if (CalcPointsTrace_embree(surf->midpoint, tracedir, dist, &hitdist, hitnormal, surf->modelinfo)) { + // we hit a solid. pull back 1 unit in the direction of the hit normal + vec3_t hitpoint; + VectorMA(surf->midpoint, hitdist, tracedir, hitpoint); + VectorMA(hitpoint, 1, hitnormal, point); + } else { + break; + } } } } diff --git a/light/trace_embree.cc b/light/trace_embree.cc index 8b1a4525..9c765670 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -329,8 +329,10 @@ CalcPointsTrace_embree(const vec3_t start, const vec3_t dir, vec_t dist, vec_t * if (hitdist) *hitdist = ray.tfar; - if (normal) + if (normal) { VectorCopy(ray.Ng, normal); + VectorNormalize(normal); + } return ray.geomID != RTC_INVALID_GEOMETRY_ID; }