Fix OpenGL 3.3 Polygon2D UV discard, clear-quad float precision, and Camera2D warning

This commit is contained in:
Meta Vens 2026-12-04 16:48:10 +01:00
commit f41b9249e3
2 changed files with 123 additions and 21 deletions

View file

@ -101,13 +101,75 @@ public partial class Smoke : Node
float gpuBefore = 0f;
if (!isHeadless)
{
if (_main.Terrain.TryGetHeightImageFormat(out var imgFormat))
{
GD.Print($"SMOKE INFO: HeightViewport format={imgFormat}");
}
bool hasGpuBefore = _main.Terrain.TrySampleBakedHeight(-96f, -96f, out gpuBefore);
Check(hasGpuBefore, "Expected GPU HeightViewport readback to succeed before crater");
if (hasGpuBefore)
{
Check(MathF.Abs(gpuBefore - cpuBefore) <= 0.25f,
$"Expected baked GPU height ({gpuBefore:F2}m) to match CPU height ({cpuBefore:F2}m) before crater");
float beforeErr = MathF.Abs(gpuBefore - cpuBefore);
GD.Print($"SMOKE INFO: Crater-site pre-stamp cpu={cpuBefore:F4}m gpu={gpuBefore:F4}m err={beforeErr:F4}m");
Check(beforeErr <= 0.20f,
$"Expected baked GPU height ({gpuBefore:F4}m) to match CPU height ({cpuBefore:F4}m) before crater within 0.20m");
}
// Verify brushed terrain relief (tallest Mesa/DuneRidge center) so a flat-map bug can never pass
TerrainBrush? reliefBrush = null;
float bestHillCpu = 0f;
foreach (var b in _main.Session.State.Terrain.Brushes)
{
if (b.Kind == TerrainBrushKind.Mesa || (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > 0f))
{
float h = _main.Session.State.Terrain.SampleHeight(b.X, b.Z);
if (h > bestHillCpu)
{
bestHillCpu = h;
reliefBrush = b;
}
}
}
Check(reliefBrush.HasValue && bestHillCpu > 10f, "Expected brushed terrain relief > 10m in generated arena");
if (reliefBrush.HasValue)
{
var rb = reliefBrush.Value;
bool hasGpuHill = _main.Terrain.TrySampleBakedHeight(rb.X, rb.Z, out float gpuHill);
Check(hasGpuHill, "Expected GPU HeightViewport readback to succeed on brushed relief hill/mesa");
if (hasGpuHill)
{
float hillErr = MathF.Abs(gpuHill - bestHillCpu);
GD.Print($"SMOKE INFO: Relief {rb.Kind} at ({rb.X:F1},{rb.Z:F1}) cpu={bestHillCpu:F4}m gpu={gpuHill:F4}m err={hillErr:F4}m");
Check(gpuHill > 10f, $"Expected GPU baked hill height > 10m, got {gpuHill:F4}m");
Check(hillErr <= 0.20f,
$"Expected GPU hill height ({gpuHill:F4}m) to match CPU ({bestHillCpu:F4}m) within 0.20m");
}
}
// Verify tile seam continuity across interior tile boundaries (< 0.01m)
float maxSeamErr = 0f;
float[] boundaries = { -192f, 0f, 192f };
float[] offsets = { -280f, -96f, 96f, 280f };
foreach (float bCoord in boundaries)
{
foreach (float ortho in offsets)
{
if (_main.Terrain.TrySampleBakedHeight(bCoord - 0.0001f, ortho, out float hL) &&
_main.Terrain.TrySampleBakedHeight(bCoord + 0.0001f, ortho, out float hR))
{
maxSeamErr = MathF.Max(maxSeamErr, MathF.Abs(hL - hR));
}
if (_main.Terrain.TrySampleBakedHeight(ortho, bCoord - 0.0001f, out float hD) &&
_main.Terrain.TrySampleBakedHeight(ortho, bCoord + 0.0001f, out float hU))
{
maxSeamErr = MathF.Max(maxSeamErr, MathF.Abs(hD - hU));
}
}
}
GD.Print($"SMOKE INFO: Max tile seam error={maxSeamErr:F5}m");
Check(maxSeamErr < 0.01f, $"Expected tile seam error < 0.01m, got {maxSeamErr:F5}m");
}
_main.Session.State.Terrain.StampCrater(-96f, -96f, radius: 5f, depth: 1.4f);
@ -127,10 +189,12 @@ public partial class Smoke : Node
Check(hasGpuAfter, "Expected GPU HeightViewport readback to succeed after crater");
if (hasGpuAfter)
{
Check(MathF.Abs(gpuAfter - cpuAfter) <= 0.25f,
$"Expected baked GPU height ({gpuAfter:F2}m) to match CPU height ({cpuAfter:F2}m) after crater");
float afterErr = MathF.Abs(gpuAfter - cpuAfter);
GD.Print($"SMOKE INFO: Crater-site post-stamp cpu={cpuAfter:F4}m gpu={gpuAfter:F4}m err={afterErr:F4}m");
Check(afterErr <= 0.20f,
$"Expected baked GPU height ({gpuAfter:F4}m) to match CPU height ({cpuAfter:F4}m) after crater within 0.20m");
Check(gpuAfter < gpuBefore - 0.8f,
$"Expected baked GPU height to drop after crater (before {gpuBefore:F2}m, after {gpuAfter:F2}m)");
$"Expected baked GPU height to drop after crater (before {gpuBefore:F4}m, after {gpuAfter:F4}m)");
}
}