diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index 73dc1a5bfa..5c668eb7d2 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -24,6 +24,18 @@ class DoomLevelMesh : public hwrenderer::LevelMesh public: DoomLevelMesh(FLevelLocals &doomMap); + 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 = MeshSurfaces[hit.triangle]; + const Surface& surface = Surfaces[surfaceIndex]; + return surface.bSky; + } + TArray Surfaces; private: diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index 84b6d5c3d0..3ff56701f6 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -59,6 +59,11 @@ static bool TraceLightVisbility(FLightNode* node, const FVector3& L, float dist) return level.levelMesh->Trace(FVector3((float)light->Pos.X, (float)light->Pos.Y, (float)light->Pos.Z), FVector3(-L.X, -L.Y, -L.Z), dist); } +static bool TraceSunVisibility(float x, float y, float z) +{ + return level.levelMesh->TraceSky(FVector3(x, y, z), FVector3(0.0f, 0.0, 1.0f), 10000.0f); +} + //========================================================================== // // Sets a single light value from all dynamic lights affecting the specified location @@ -73,6 +78,11 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLig out[0] = out[1] = out[2] = 0.f; + if (TraceSunVisibility(x, y, z)) + { + //out[0] = 1.0f; + } + // Go through both light lists while (node) { @@ -183,6 +193,11 @@ void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata) float radiusSquared = actorradius * actorradius; dl_validcount++; + if (TraceSunVisibility(x, y, z)) + { + //AddSunLightToList(modellightdata); + } + BSPWalkCircle(self->Level, x, y, radiusSquared, [&](subsector_t *subsector) // Iterate through all subsectors potentially touched by actor { auto section = subsector->section;