diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index f294bcbbd..885c33f29 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -59,7 +59,7 @@ struct LevelMeshSurface int sectorGroup = 0; BBox bounds; - int sampleDimension = 0; + uint16_t sampleDimension = 0; // Lightmap world coordinates for the texture FVector3 worldOrigin = { 0.f, 0.f, 0.f }; diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 932a5f08a..f089e5c18 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -893,7 +893,17 @@ void DoomLevelMesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMapTex { surface.sampleDimension = LightmapSampleDistance; } - //surface->sampleDimension = Math::RoundPowerOfTwo(surface->sampleDimension); + + { + // Round to nearest power of two + uint32_t n = uint16_t(surface.sampleDimension); + n |= n >> 1; + n |= n >> 2; + n |= n >> 4; + n |= n >> 8; + ++n; + surface.sampleDimension = uint16_t(n) ? uint16_t(n) : uint16_t(0xFFFF); + } // round off dimensions for (int i = 0; i < 3; i++)