diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index c537f8ae3..f294bcbbd 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 ab05e2b9f..ab76f6600 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 6fce19c05..932ec36c8 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -2945,9 +2945,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) { @@ -2983,6 +2980,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 979f8f649..260d68de4 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -754,10 +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) + 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; + break; default: CHECK_N(Zd | Zdt) @@ -806,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/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 7b844773f..932a5f08a 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);