Skip to content

Commit 5bcc5c4

Browse files
committed
Fix overlay overlapping with buildings and vehicles
1 parent 536dbad commit 5bcc5c4

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/TSMapEditor/Rendering/ObjectRenderers/BuildingRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected override float GetDepthFromPosition(Structure gameObject, int bottomDr
126126
height = southernmostCell.Level;
127127
}
128128

129-
return ((CellMath.CellTopLeftPointFromCellCoords(southernmostCell.CoordsToPoint(), Map).Y + Constants.CellSizeY) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
129+
return ((CellMath.CellTopLeftPointFromCellCoords(southernmostCell.CoordsToPoint(), Map).Y + Constants.CellSizeY * 2) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
130130
(height * Constants.DepthRenderStep);
131131
}
132132

src/TSMapEditor/Rendering/ObjectRenderers/ObjectRenderer.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,21 @@ public virtual void DrawShadow(T gameObject)
293293

294294
protected virtual float GetDepthFromPosition(T gameObject, int bottomDrawPoint)
295295
{
296-
// In this generic implementation, we only use the cell to fetch its height.
297-
// Otherwise, position-related depth is calculated from the bottom draw point of the object.
296+
// Calculate position-related depth from the bottom draw point of the object.
297+
// Snap the texture height to the southernmost pixel coordinate of the southernmost
298+
// cell that this object's texture overlaps.
298299
var cell = Map.GetTile(gameObject.Position);
300+
int cellY = CellMath.CellTopLeftPointFromCellCoords(gameObject.Position, Map).Y;
301+
int dy = bottomDrawPoint - cellY;
302+
int extraHeightForSnap = dy % Constants.CellHeight;
299303

300304
int height = 0;
301305
if (cell != null)
302306
{
303307
height = cell.Level;
304308
}
305309

306-
return ((bottomDrawPoint + (height * Constants.CellHeight) + Constants.CellSizeY) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
310+
return ((bottomDrawPoint + (height * Constants.CellHeight) + extraHeightForSnap) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
307311
(height * Constants.DepthRenderStep);
308312
}
309313

@@ -485,7 +489,7 @@ private void RenderFrame(T gameObject, PositionedTexture frame, PositionedTextur
485489
depthAddition = 1.0f;
486490

487491
// Add extra depth so objects show above terrain despite float imprecision
488-
depthAddition += Constants.DepthEpsilon;
492+
// depthAddition += Constants.DepthEpsilon;
489493

490494
// There can be a gap between the end of the texture and the bottom-most cell for objects,
491495
// with more "circular" graphics. This can reduce depth when it's calculated in the shader.

src/TSMapEditor/Rendering/ObjectRenderers/UnitRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected override float GetDepthFromPosition(Unit gameObject, int bottomDrawPoi
4444
height = cell.Level;
4545
}
4646

47-
return ((CellMath.CellTopLeftPointFromCellCoords(cell.CoordsToPoint(), Map).Y + Constants.CellSizeY) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
47+
return ((CellMath.CellTopLeftPointFromCellCoords(cell.CoordsToPoint(), Map).Y + (Constants.CellSizeY * 2)) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
4848
(height * Constants.DepthRenderStep);
4949
}
5050

0 commit comments

Comments
 (0)