mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-17 01:31:25 +00:00
CPU tracelight portal fix
This commit is contained in:
parent
98403698cd
commit
eb7e3faf06
3 changed files with 46 additions and 10 deletions
|
@ -199,10 +199,50 @@ public:
|
|||
FVector3 SunColor = FVector3(0.0f, 0.0f, 0.0f);
|
||||
uint16_t LightmapSampleDistance = 16;
|
||||
|
||||
bool Trace(const FVector3& start, FVector3 direction, float maxDist)
|
||||
LevelMeshSurface* Trace(const FVector3& start, FVector3 direction, float maxDist)
|
||||
{
|
||||
FVector3 end = start + direction * std::max(maxDist - 10.0f, 0.0f);
|
||||
return !TriangleMeshShape::find_any_hit(Collision.get(), start, end);
|
||||
maxDist = std::max(maxDist - 10.0f, 0.0f);
|
||||
|
||||
FVector3 origin = start;
|
||||
FVector3 end;
|
||||
|
||||
auto collision = Collision.get();
|
||||
|
||||
LevelMeshSurface* hitSurface = nullptr;
|
||||
|
||||
while (true)
|
||||
{
|
||||
end = origin + direction * maxDist;
|
||||
|
||||
auto hit = TriangleMeshShape::find_first_hit(collision, origin, end);
|
||||
|
||||
if (hit.triangle < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hitSurface = GetSurface(MeshSurfaceIndexes[hit.triangle]);
|
||||
auto portal = hitSurface->portalIndex;
|
||||
|
||||
if (!portal)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
auto& transformation = Portals[portal];
|
||||
|
||||
auto travelDist = hit.fraction * maxDist + 2.0f;
|
||||
if (travelDist >= maxDist)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
origin = transformation.TransformPosition(origin + direction * travelDist);
|
||||
direction = transformation.TransformRotation(direction);
|
||||
maxDist -= travelDist;
|
||||
}
|
||||
|
||||
return hitSurface; // I hit something
|
||||
}
|
||||
|
||||
void BuildSmoothingGroups()
|
||||
|
|
|
@ -31,12 +31,8 @@ public:
|
|||
bool TraceSky(const FVector3& start, FVector3 direction, float dist)
|
||||
{
|
||||
FVector3 end = start + direction * dist;
|
||||
TraceHit hit = TriangleMeshShape::find_first_hit(Collision.get(), start, end);
|
||||
if (hit.fraction == 1.0f)
|
||||
return true;
|
||||
|
||||
int surfaceIndex = MeshSurfaceIndexes[hit.triangle];
|
||||
return Surfaces[surfaceIndex].bSky;
|
||||
auto surface = Trace(start, direction, dist);
|
||||
return surface && surface->bSky;
|
||||
}
|
||||
|
||||
void UpdateLightLists() override;
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
bool traceResult = level.levelMesh->Trace(FVector3((float)light->Pos.X, (float)light->Pos.Y, (float)light->Pos.Z), FVector3(-L.X, -L.Y, -L.Z), dist);
|
||||
bool traceResult = !level.levelMesh->Trace(FVector3((float)light->Pos.X, (float)light->Pos.Y, (float)light->Pos.Z), FVector3(-L.X, -L.Y, -L.Z), dist);
|
||||
Actor->StaticLightsTraceCache.Bits |= ((uint64_t)traceResult) << CurrentBit;
|
||||
CurrentBit++;
|
||||
return traceResult;
|
||||
|
|
Loading…
Reference in a new issue