Skip to content

Commit

Permalink
Clamp lightmap UV to the tile if geometry moves
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Jan 17, 2024
1 parent d181774 commit ad1f6a8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/common/rendering/hwrenderer/data/hw_lightmaptile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ad1f6a8

Please sign in to comment.