Fix Cut 1 findings: Polygon2D 256px terrain bake, spectator LOS memory leak, steep slope/biped physics, and HUD polish

This commit is contained in:
Meta Vens 2026-12-04 15:41:02 +01:00
commit af6604da80
9 changed files with 458 additions and 69 deletions

View file

@ -12,8 +12,8 @@ namespace RustToDust.Client;
/// </summary>
public partial class TerrainRenderer : Node3D
{
private const int ViewportSize = 128;
private const float InnerTexelSpan = 125.0f; // texel 1 center (1.5) .. texel 126 center (126.5)
private const int ViewportSize = 256;
private const float InnerTexelSpan = 253.0f; // texel 1 center (1.5) .. texel 254 center (254.5)
private const float GutterCenterOffset = 1.5f;
private const float PixelsPerMeter = InnerTexelSpan / TerrainField.TileSize;
private const float HeightSpan = TerrainField.MaxWorldHeight - TerrainField.MinWorldHeight;
@ -21,6 +21,13 @@ public partial class TerrainRenderer : Node3D
private static readonly Color HeightClearColor = new(BaseHeightNorm, 0.88f, 0.0f, 1.0f);
private static readonly Color AlbedoClearColor = new(0.69f, 0.50f, 0.31f, 1.0f);
private static readonly Vector2[] BrushUv =
{
new(0f, 0f),
new(1f, 0f),
new(1f, 1f),
new(0f, 1f)
};
private sealed class TileNode
{
@ -162,8 +169,8 @@ public partial class TerrainRenderer : Node3D
var plane = new PlaneMesh
{
Size = new Vector2(TerrainField.TileSize, TerrainField.TileSize),
SubdivideWidth = 40,
SubdivideDepth = 40
SubdivideWidth = 64,
SubdivideDepth = 64
};
var mat = new ShaderMaterial { Shader = _surfaceShader };
@ -205,6 +212,8 @@ public partial class TerrainRenderer : Node3D
Disable3D = true,
UseHdr2D = useHdr,
TransparentBg = false,
Snap2DTransformsToPixel = false,
Snap2DVerticesToPixel = false,
RenderTargetClearMode = SubViewport.ClearMode.Always,
RenderTargetUpdateMode = SubViewport.UpdateMode.Disabled
};
@ -227,19 +236,9 @@ public partial class TerrainRenderer : Node3D
ClearCanvasChildren(tile.HeightCanvas);
ClearCanvasChildren(tile.AlbedoCanvas);
// Full-tile base clear quads
tile.HeightCanvas.AddChild(new ColorRect
{
Position = Vector2.Zero,
Size = new Vector2(ViewportSize, ViewportSize),
Color = HeightClearColor
});
tile.AlbedoCanvas.AddChild(new ColorRect
{
Position = Vector2.Zero,
Size = new Vector2(ViewportSize, ViewportSize),
Color = AlbedoClearColor
});
// Full-tile base clear quads (Polygon2D avoids GUI pixel snapping)
tile.HeightCanvas.AddChild(CreateClearQuad(HeightClearColor));
tile.AlbedoCanvas.AddChild(CreateClearQuad(AlbedoClearColor));
float tileMinX = -TerrainField.HalfExtent + tx * TerrainField.TileSize;
float tileMinZ = -TerrainField.HalfExtent + tz * TerrainField.TileSize;
@ -282,13 +281,7 @@ public partial class TerrainRenderer : Node3D
}
// 2. Albedo brush pass
var albedoQuad = new ColorRect
{
Position = new Vector2(px - rxPx, py - rzPx),
Size = new Vector2(rxPx * 2f, rzPx * 2f),
PivotOffset = new Vector2(rxPx, rzPx),
Rotation = b.RotationRad
};
var albedoQuad = CreateOrientedQuad(px, py, rxPx, rzPx, b.RotationRad);
var albedoMat = new ShaderMaterial { Shader = _brushAlbedoShader };
albedoMat.SetShaderParameter("brush_kind", kindInt);
albedoMat.SetShaderParameter("brush_albedo", new Vector3(b.AlbedoR, b.AlbedoG, b.AlbedoB));
@ -301,7 +294,42 @@ public partial class TerrainRenderer : Node3D
tile.AlbedoViewport.RenderTargetUpdateMode = SubViewport.UpdateMode.Once;
}
private static ColorRect CreateBrushQuad(
private static Polygon2D CreateClearQuad(Color color)
{
return new Polygon2D
{
Polygon = new[]
{
new Vector2(0f, 0f),
new Vector2(ViewportSize, 0f),
new Vector2(ViewportSize, ViewportSize),
new Vector2(0f, ViewportSize)
},
Color = color
};
}
private static Polygon2D CreateOrientedQuad(
float px, float py,
float rxPx, float rzPx,
float rotationRad)
{
return new Polygon2D
{
Position = new Vector2(px, py),
Rotation = rotationRad,
Polygon = new[]
{
new Vector2(-rxPx, -rzPx),
new Vector2(rxPx, -rzPx),
new Vector2(rxPx, rzPx),
new Vector2(-rxPx, rzPx)
},
Uv = BrushUv
};
}
private static Polygon2D CreateBrushQuad(
float px, float py,
float rxPx, float rzPx,
float rotationRad,
@ -309,13 +337,7 @@ public partial class TerrainRenderer : Node3D
int kindInt,
float heightDelta)
{
var quad = new ColorRect
{
Position = new Vector2(px - rxPx, py - rzPx),
Size = new Vector2(rxPx * 2f, rzPx * 2f),
PivotOffset = new Vector2(rxPx, rzPx),
Rotation = rotationRad
};
var quad = CreateOrientedQuad(px, py, rxPx, rzPx, rotationRad);
var mat = new ShaderMaterial { Shader = shader };
mat.SetShaderParameter("brush_kind", kindInt);
mat.SetShaderParameter("height_delta", heightDelta);