From 18a873923f5b3c7b8758c4a998609ea222fb41ba Mon Sep 17 00:00:00 2001 From: RaveYard <29225776+MrRaveYard@users.noreply.github.com> Date: Mon, 4 Sep 2023 12:28:05 +0200 Subject: [PATCH] Read ZDRay info thing --- .../rendering/hwrenderer/data/hw_levelmesh.h | 1 + src/g_levellocals.h | 1 + src/maploader/maploader.cpp | 8 +++-- src/maploader/udmf.cpp | 33 ++++++++++++++++++- src/namedef_custom.h | 1 + src/rendering/hwrenderer/doom_levelmesh.cpp | 3 +- 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index c537f8ae36..f294bcbbdc 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -178,6 +178,7 @@ public: FVector3 SunDirection = FVector3(0.0f, 0.0f, -1.0f); FVector3 SunColor = FVector3(0.0f, 0.0f, 0.0f); + uint16_t LightmapSampleDistance = 16; bool Trace(const FVector3& start, FVector3 direction, float maxDist) { diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 69f973c32f..aed244d587 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -458,6 +458,7 @@ public: TArray LMSurfaces; FVector3 SunDirection; FVector3 SunColor; + uint16_t LightmapSampleDistance; // Portal information. FDisplacementTable Displacements; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index d23f30839c..4eeefd0268 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -2940,9 +2940,6 @@ void MapLoader::CalcIndices() void MapLoader::InitLevelMesh() { - Level->SunColor = FVector3(1.f, 1.f, 1.f); - Level->SunDirection = FVector3(0.45f, 0.3f, 0.9f); - // Propagate sample distance where it isn't yet set for (auto& line : Level->lines) { @@ -2978,6 +2975,11 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) { const int *oldvertextable = nullptr; + // Reset defaults for lightmapping + Level->SunColor = FVector3(1.f, 1.f, 1.f); + Level->SunDirection = FVector3(0.45f, 0.3f, 0.9f); + Level->LightmapSampleDistance = 16; + // note: most of this ordering is important ForceNodeBuild = gennodes; diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index 2d646bad87..4e1069c012 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -754,9 +754,31 @@ public: break; case NAME_lm_suncolor: + CHECK_N(Zd | Zdt) + if (CheckInt(key) < 0 || CheckInt(key) > 0xFFFFFF) + { + DPrintf(DMSG_WARNING, "Sun Color '%x' is out of range %s\n", CheckInt(key)); + } + else + { + auto n = uint32_t(CheckInt(key)); + Level->SunColor = FVector3(float((n >> 16) & 0xFF) / 0xFF, float((n >> 8) & 0xFF) / 0xFF, float(n & 0xFF) / 0xFF); + } + break; case NAME_lm_sampledistance: CHECK_N(Zd | Zdt) - break; + if (CheckInt(key) >= 0 && CheckInt(key) <= 0xFFFF) + { + Level->LightmapSampleDistance = CheckInt(key); + } + else + { + DPrintf(DMSG_WARNING, "Can't set the global lm_sampledistance to %s\n", key.GetChars()); + } + break; + case NAME_lm_gridsize: + CHECK_N(Zd | Zdt) + break; default: CHECK_N(Zd | Zdt) @@ -805,6 +827,15 @@ public: th->special = 0; memset(th->args, 0, sizeof (th->args)); } + + if (th->EdNum == 9890) // ZDRAY INFO thing + { + FAngle angle = FAngle::fromDeg(float(th->angle)); + FAngle pitch = FAngle::fromDeg(float(th->pitch)); + + auto pc = pitch.Cos(); + Level->SunDirection = -FVector3 { pc * angle.Cos(), pc * angle.Sin(), -pitch.Sin() }; // [RaveYard]: is there a dedicated function for this? + } } //=========================================================================== diff --git a/src/namedef_custom.h b/src/namedef_custom.h index a5604475d4..c70909ff1d 100644 --- a/src/namedef_custom.h +++ b/src/namedef_custom.h @@ -857,5 +857,6 @@ xx(lm_sampledist_floor) xx(lm_sampledist_ceiling) xx(lm_suncolor) xx(lm_sampledistance) +xx(lm_gridsize) xx(Corona) diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 7b844773f0..932a5f08ac 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -27,6 +27,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap) { SunColor = doomMap.SunColor; // TODO keep only one copy? SunDirection = doomMap.SunDirection; + LightmapSampleDistance = doomMap.LightmapSampleDistance; for (unsigned int i = 0; i < doomMap.sides.Size(); i++) { @@ -890,7 +891,7 @@ void DoomLevelMesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMapTex if (surface.sampleDimension <= 0) { - surface.sampleDimension = 16; + surface.sampleDimension = LightmapSampleDistance; } //surface->sampleDimension = Math::RoundPowerOfTwo(surface->sampleDimension);