Add some of the sunlight trace code

This commit is contained in:
Magnus Norddahl 2023-04-06 01:04:03 +02:00 committed by Christoph Oelckers
parent 1b81e40842
commit 2bcab0e34d
2 changed files with 27 additions and 0 deletions

View file

@ -24,6 +24,18 @@ class DoomLevelMesh : public hwrenderer::LevelMesh
public: public:
DoomLevelMesh(FLevelLocals &doomMap); 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<Surface> Surfaces; TArray<Surface> Surfaces;
private: private:

View file

@ -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); 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 // 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; out[0] = out[1] = out[2] = 0.f;
if (TraceSunVisibility(x, y, z))
{
//out[0] = 1.0f;
}
// Go through both light lists // Go through both light lists
while (node) while (node)
{ {
@ -183,6 +193,11 @@ void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata)
float radiusSquared = actorradius * actorradius; float radiusSquared = actorradius * actorradius;
dl_validcount++; 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 BSPWalkCircle(self->Level, x, y, radiusSquared, [&](subsector_t *subsector) // Iterate through all subsectors potentially touched by actor
{ {
auto section = subsector->section; auto section = subsector->section;