From 7c2db1638779cfe2e1f63e5e56727341bc4c7b15 Mon Sep 17 00:00:00 2001 From: Pierre Etchemaite Date: Sun, 8 Mar 2026 03:00:44 +0100 Subject: [PATCH] Fix stacked trees at zone boundaries TerrainSampler.HeightmapDimension returns a number of vertices, so (fence post problem) the height map dimension is heightmapScale.x * (HeightmapDimension - 1), not heightmapScale.x * HeightmapDimension. By using the latter, nature billboards are placed too far apart from one another, and the last billboard of a zone can land very close to the first billboard of the next zone. Say tDim = 128 and hDim = 129 (default values), scale = terrainData.heightmapScale.x * (float)hDim / (float)tDim = 6.4500003 largest x value is x = tDim - 1 = 127 x * scale = 819.14996 when zone is terrainData.heightmapScale.x * (float)(hDim - 1) = 819.2 --- Assets/Scripts/Terrain/TerrainNature.cs | 2 +- Assets/Scripts/Terrain/TerrainSampler.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Terrain/TerrainNature.cs b/Assets/Scripts/Terrain/TerrainNature.cs index 9da89b907d..5570cf2b15 100644 --- a/Assets/Scripts/Terrain/TerrainNature.cs +++ b/Assets/Scripts/Terrain/TerrainNature.cs @@ -105,7 +105,7 @@ public virtual void LayoutNature(DaggerfallTerrain dfTerrain, DaggerfallBillboar Vector2 tilePos = Vector2.zero; int tDim = MapsFile.WorldMapTileDim; int hDim = DaggerfallUnity.Instance.TerrainSampler.HeightmapDimension; - float scale = terrainData.heightmapScale.x * (float)hDim / (float)tDim; + float scale = terrainData.heightmapScale.x * (float)(hDim - 1) / (float)tDim; float maxTerrainHeight = DaggerfallUnity.Instance.TerrainSampler.MaxTerrainHeight; float beachLine = DaggerfallUnity.Instance.TerrainSampler.BeachElevation; diff --git a/Assets/Scripts/Terrain/TerrainSampler.cs b/Assets/Scripts/Terrain/TerrainSampler.cs index 3301ebc1f6..06b305c87a 100644 --- a/Assets/Scripts/Terrain/TerrainSampler.cs +++ b/Assets/Scripts/Terrain/TerrainSampler.cs @@ -29,7 +29,7 @@ public interface ITerrainSampler int Version { get; } // Terrain heightmap dimension (+1 extra point for end vertex) - // Example settings are 129, 257, 513, 1023, etc. + // Example settings are 129, 257, 513, 1025, etc. // Do not set to a value less than MapsFile.WorldMapTileDim int HeightmapDimension { get; set; }