From ad1f6a8b5aacd204f6a608bdeafc0c1b2b8c45fc Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 17 Jan 2024 20:15:15 +0100 Subject: [PATCH] Clamp lightmap UV to the tile if geometry moves --- src/common/rendering/hwrenderer/data/hw_lightmaptile.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_lightmaptile.h b/src/common/rendering/hwrenderer/data/hw_lightmaptile.h index c65f9c038c..0775c99bb9 100644 --- a/src/common/rendering/hwrenderer/data/hw_lightmaptile.h +++ b/src/common/rendering/hwrenderer/data/hw_lightmaptile.h @@ -64,9 +64,12 @@ struct LightmapTile FVector2 ToUV(const FVector3& vert, float textureSize) const { + // Clamp in case the wall moved outside the tile (happens if a lift moves with a static lightmap on it) FVector3 localPos = vert - Transform.TranslateWorldToLocal; - float u = (AtlasLocation.X + (localPos | Transform.ProjLocalToU)) / textureSize; - float v = (AtlasLocation.Y + (localPos | Transform.ProjLocalToV)) / textureSize; + float u = std::max(std::min(localPos | Transform.ProjLocalToU, (float)AtlasLocation.Width), 0.0f); + float v = std::max(std::min(localPos | Transform.ProjLocalToV, (float)AtlasLocation.Height), 0.0f); + u = (AtlasLocation.X + u) / textureSize; + v = (AtlasLocation.Y + v) / textureSize; return FVector2(u, v); }