From b55a9671e5ec167e61225a2a0e1f4b09c53801f7 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 9 Nov 2018 06:21:25 +0100 Subject: [PATCH] - use the cheaper any hit test when possible --- src/level/doomdata.h | 1 + src/level/level_light.cpp | 5 +++++ src/lightmap/lightmap.cpp | 4 +--- src/lightmap/lightsurface.cpp | 4 +--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/level/doomdata.h b/src/level/doomdata.h index 2c776a0..c548edb 100644 --- a/src/level/doomdata.h +++ b/src/level/doomdata.h @@ -374,6 +374,7 @@ struct FLevel void CreateLights(); LevelTraceHit Trace(const kexVec3 &startVec, const kexVec3 &endVec); + bool TraceAnyHit(const kexVec3 &startVec, const kexVec3 &endVec); const kexVec3 &GetSunColor() const; const kexVec3 &GetSunDirection() const; diff --git a/src/level/level_light.cpp b/src/level/level_light.cpp index 0168601..e17f3c1 100644 --- a/src/level/level_light.cpp +++ b/src/level/level_light.cpp @@ -379,3 +379,8 @@ LevelTraceHit FLevel::Trace(const kexVec3 &startVec, const kexVec3 &endVec) } return trace; } + +bool FLevel::TraceAnyHit(const kexVec3 &startVec, const kexVec3 &endVec) +{ + return TriangleMeshShape::find_any_hit(CollisionMesh.get(), startVec, endVec); +} diff --git a/src/lightmap/lightmap.cpp b/src/lightmap/lightmap.cpp index ac79d7b..25182a2 100644 --- a/src/lightmap/lightmap.cpp +++ b/src/lightmap/lightmap.cpp @@ -265,9 +265,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *s } } - LevelTraceHit trace = map->Trace(lightOrigin, origin); - - if (trace.fraction != 1) + if (map->TraceAnyHit(lightOrigin, origin)) { // this light is occluded by something continue; diff --git a/src/lightmap/lightsurface.cpp b/src/lightmap/lightsurface.cpp index 2952925..356ffcd 100644 --- a/src/lightmap/lightsurface.cpp +++ b/src/lightmap/lightsurface.cpp @@ -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 // case the start/end points are directly on or inside the surface - LevelTraceHit trace = map->Trace(lightPos + lightSurfaceNormal, fragmentPos + fragmentNormal); - - if (trace.fraction < 1.0f) + if (map->TraceAnyHit(lightPos + lightSurfaceNormal, fragmentPos + fragmentNormal)) continue; // something is obstructing it if (d < closestDistance)