Round sampledist to power of 2

This commit is contained in:
RaveYard 2023-09-04 12:35:36 +02:00 committed by Christoph Oelckers
parent 18a873923f
commit fd4496f360
2 changed files with 12 additions and 2 deletions

View file

@ -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 };

View file

@ -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++)