- use the cheaper any hit test when possible

This commit is contained in:
Magnus Norddahl 2018-11-09 06:21:25 +01:00
parent 63715b855d
commit b55a9671e5
4 changed files with 8 additions and 6 deletions

View file

@ -374,6 +374,7 @@ struct FLevel
void CreateLights(); void CreateLights();
LevelTraceHit Trace(const kexVec3 &startVec, const kexVec3 &endVec); LevelTraceHit Trace(const kexVec3 &startVec, const kexVec3 &endVec);
bool TraceAnyHit(const kexVec3 &startVec, const kexVec3 &endVec);
const kexVec3 &GetSunColor() const; const kexVec3 &GetSunColor() const;
const kexVec3 &GetSunDirection() const; const kexVec3 &GetSunDirection() const;

View file

@ -379,3 +379,8 @@ LevelTraceHit FLevel::Trace(const kexVec3 &startVec, const kexVec3 &endVec)
} }
return trace; return trace;
} }
bool FLevel::TraceAnyHit(const kexVec3 &startVec, const kexVec3 &endVec)
{
return TriangleMeshShape::find_any_hit(CollisionMesh.get(), startVec, endVec);
}

View file

@ -265,9 +265,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *s
} }
} }
LevelTraceHit trace = map->Trace(lightOrigin, origin); if (map->TraceAnyHit(lightOrigin, origin))
if (trace.fraction != 1)
{ {
// this light is occluded by something // this light is occluded by something
continue; continue;

View file

@ -286,9 +286,7 @@ float kexLightSurface::TraceSurface(FLevel *map, const surface_t *fragmentSurfac
// trace the origin to the center of the light surface. nudge by the normals in // trace the origin to the center of the light surface. nudge by the normals in
// case the start/end points are directly on or inside the surface // case the start/end points are directly on or inside the surface
LevelTraceHit trace = map->Trace(lightPos + lightSurfaceNormal, fragmentPos + fragmentNormal); if (map->TraceAnyHit(lightPos + lightSurfaceNormal, fragmentPos + fragmentNormal))
if (trace.fraction < 1.0f)
continue; // something is obstructing it continue; // something is obstructing it
if (d < closestDistance) if (d < closestDistance)