Merge pull request #39 from MrRaveYard/pr_minor_refactoring

Support sunlight from sky on the floor + fix warnings
This commit is contained in:
Magnus Norddahl 2022-06-24 18:16:49 +02:00 committed by GitHub
commit bbf4a71c1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 23 deletions

View file

@ -120,6 +120,12 @@ struct MapSector
short tag;
};
enum SecPlaneType
{
PLANE_FLOOR,
PLANE_CEILING,
};
struct IntSector
{
// none of the sector properties are used by the node builder
@ -140,7 +146,14 @@ struct IntSector
bool controlsector;
TArray<IntSector*> x3dfloors;
bool skySector;
union
{
bool skyPlanes[2];
struct { bool skyFloor, skyCeiling; };
};
inline const char* GetTextureName(int plane) const { return plane != PLANE_FLOOR ? data.ceilingpic : data.floorpic; }
TArray<UDMFKey> props;

View file

@ -78,7 +78,7 @@ void FLevel::SetupLights()
{
FString hex = FString("0x") + FString(key.value);
hex.StripChars("\"");
printf("Sun color: %s\n", hex);
printf("Sun color: %s\n", hex.GetChars());
int rgb = hex.ToULong();
lightcolor = (uint32_t)rgb;
}
@ -124,23 +124,21 @@ void FLevel::SetupLights()
void FLevel::CheckSkySectors()
{
char name[65];
for (int i = 0; i < (int)Sectors.Size(); ++i)
for (auto& sector : Sectors)
{
//if (mapDef && mapDef->sunIgnoreTag != 0 && Sectors[i].data.tag == mapDef->sunIgnoreTag)
// continue;
strncpy(name, Sectors[i].data.ceilingpic, 64);
name[64] = 0;
if (!strncmp(name, "F_SKY001", 64) || !strncmp(name, "F_SKY1", 64) || !strncmp(name, "F_SKY", 64))
for (int i = 0; i < 2; ++i)
{
Sectors[i].skySector = true;
}
else
{
Sectors[i].skySector = false;
sector.skyPlanes[i] = false;
//if (mapDef && mapDef->sunIgnoreTag != 0 && sector.data.tag == mapDef->sunIgnoreTag)
// continue;
const auto name = sector.GetTextureName(i);
if (!strncmp(name, "F_SKY001", 64) || !strncmp(name, "F_SKY1", 64) || !strncmp(name, "F_SKY", 64))
{
sector.skyPlanes[i] = true;
}
}
}
}

View file

@ -97,7 +97,7 @@ void GPURaytracer::Raytrace(LevelMesh* level)
size_t maxTasks = (size_t)rayTraceImageSize * rayTraceImageSize;
for (size_t startTask = 0; startTask < tasks.size(); startTask += maxTasks)
{
printf("\r%.1f%%\t%d/%d", double(startTask) / double(tasks.size()) * 100, startTask, tasks.size());
printf("\r%.1f%%\t%llu/%llu", double(startTask) / double(tasks.size()) * 100, startTask, tasks.size());
size_t numTasks = std::min(tasks.size() - startTask, maxTasks);
UploadTasks(tasks.data() + startTask, numTasks);
@ -145,7 +145,7 @@ void GPURaytracer::Raytrace(LevelMesh* level)
EndTracing();
DownloadTasks(tasks.data() + startTask, numTasks);
}
printf("\r%.1f%%\t%d/%d\n", 100.0, tasks.size(), tasks.size());
printf("\r%.1f%%\t%llu/%llu\n", 100.0, tasks.size(), tasks.size());
});
if (device->renderdoc)
@ -405,7 +405,7 @@ void GPURaytracer::CreateVertexAndIndexBuffers()
info.EmissiveColor = vec3(0.0f, 0.0f, 0.0f);
}
info.SamplingDistance = surface->sampleDimension;
info.SamplingDistance = float(surface->sampleDimension);
surfaces.push_back(info);
}

View file

@ -570,7 +570,17 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
// bottom seg
if (v1Bottom < v1BottomBack || v2Bottom < v2BottomBack)
{
if (side->bottomtexture[0] != '-')
bool bSky = false;
if (front->skyFloor && back->skyFloor)
{
if (front->data.floorheight != back->data.floorheight && side->bottomtexture[0] == '-')
{
bSky = true;
}
}
if (side->bottomtexture[0] != '-' || bSky)
{
float texWidth = 128.0f;
float texHeight = 128.0f;
@ -593,6 +603,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->plane.SetDistance(surf->verts[0]);
surf->type = ST_LOWERSIDE;
surf->typeIndex = typeIndex;
surf->bSky = bSky;
surf->controlSector = nullptr;
surf->sampleDimension = (surf->sampleDimension = side->GetSampleDistanceBottom()) ? surf->sampleDimension : defaultSamples;
@ -620,7 +631,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
{
bool bSky = false;
if (front->skySector && back->skySector)
if (front->skyCeiling && back->skyCeiling)
{
if (front->data.ceilingheight != back->data.ceilingheight && side->toptexture[0] == '-')
{
@ -726,6 +737,7 @@ void LevelMesh::CreateFloorSurface(FLevel &doomMap, MapSubsectorEx *sub, IntSect
surf->numVerts = sub->numlines;
surf->verts.resize(surf->numVerts);
surf->uvs.resize(surf->numVerts);
surf->bSky = sector->skyFloor;
if (!is3DFloor)
{
@ -764,7 +776,7 @@ void LevelMesh::CreateCeilingSurface(FLevel &doomMap, MapSubsectorEx *sub, IntSe
surf->numVerts = sub->numlines;
surf->verts.resize(surf->numVerts);
surf->uvs.resize(surf->numVerts);
surf->bSky = sector->skySector;
surf->bSky = sector->skyCeiling;
if (!is3DFloor)
{