render: unified MultiMeshPartPool with MechPaint, PomDecalPool, and per-weapon VFX

This commit is contained in:
Meta Vens 2026-12-04 23:56:30 +01:00
commit 2529ba62d2
9 changed files with 2593 additions and 871 deletions

View file

@ -314,14 +314,6 @@ public partial class Smoke : Node
Check(mappedHp is { Id: "hp.weapon.main" },
$"Expected GetHardpointAt(1,1) to return hp.weapon.main, got {mappedHp?.Id ?? "null"}");
// Toggle thermal mode off -> on -> off
_main.Hud.SetThermalMode(true, instant: true);
Check(_main.Hud.ThermalMode && MathF.Abs(schematic.ThermalBlend - 1f) < 0.01f,
"Expected ThermalMode to activate immediately");
_main.Hud.SetThermalMode(false, instant: true);
Check(!_main.Hud.ThermalMode && MathF.Abs(schematic.ThermalBlend) < 0.01f,
"Expected ThermalMode to deactivate immediately");
// Regression check (Finding 3): same-dimension SwapChassis updates _hardpointLookup and clears hover state
schematic._GuiInput(new InputEventMouseMotion { Position = probePos });
Check(schematic.HoveredCell == new Vector2I(1, 1) && schematic.HoveredHardpoint is { Id: "hp.weapon.main" },
@ -383,7 +375,7 @@ public partial class Smoke : Node
return;
}
// GPU verification on OpenGL 3.3: render isolated InventoryGridControl (tactical + thermal) & panel_chrome.gdshader
// GPU verification on OpenGL 3.3: render isolated InventoryGridControl (ambient vs live bilinear heat) & panel_chrome.gdshader
var gridVp = new SubViewport
{
Size = new Vector2I(240, 240),
@ -398,36 +390,42 @@ public partial class Smoke : Node
gridVp.AddChild(vpGrid);
AddChild(gridVp);
var coolGrid = new ChassisGrid(Catalog.Ironclad);
coolGrid.TryMount(Catalog.Recoilless, "hp.weapon.main");
coolGrid.TryMount(Catalog.Mg762, "hp.weapon.coax");
coolGrid.TryMount(Catalog.TurboCore, "hp.engine.rear");
coolGrid.TryMount(Catalog.CopperRad, "hp.radiator.l");
coolGrid.TryMount(Catalog.WeldedPlate, "hp.armor.front");
coolGrid.Armor[0, 0] = 0f;
vpGrid.SetGrid(coolGrid);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
var coolImg = gridVp.GetTexture().GetImage();
int coolOpaque = CountNonZeroAlphaPixels(coolImg, 0.08f);
GD.Print($"SMOKE INFO: InventoryGrid GPU cool opaque pixels={coolOpaque}");
Check(coolOpaque > 4000, $"Expected > 4000 rendered pixels from InventoryGrid shader, got {coolOpaque}");
vpGrid.SetGrid(testGrid);
vpGrid.TriggerHitPulse(1, 1, 1f);
vpGrid.SetThermalInstant(false);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
var tacticalImg = gridVp.GetTexture().GetImage();
int tacticalOpaque = CountNonZeroAlphaPixels(tacticalImg, 0.08f);
GD.Print($"SMOKE INFO: InventoryGrid GPU tactical opaque pixels={tacticalOpaque}");
Check(tacticalOpaque > 4000, $"Expected > 4000 rendered pixels from InventoryGrid tactical shader, got {tacticalOpaque}");
var hotImg = gridVp.GetTexture().GetImage();
int hotOpaque = CountNonZeroAlphaPixels(hotImg, 0.08f);
int heatDiff = CountDifferentPixels(coolImg, hotImg, 0.05f);
GD.Print($"SMOKE INFO: InventoryGrid GPU hot opaque={hotOpaque}, diff vs cool={heatDiff}");
Check(hotOpaque > 4000, $"Expected > 4000 rendered pixels from heated InventoryGrid shader, got {hotOpaque}");
Check(heatDiff > 400, $"Expected always-active temp_tex + hit pulse to visibly change > 400 pixels, got {heatDiff}");
vpGrid.SetThermalInstant(true);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
var thermalImg = gridVp.GetTexture().GetImage();
int thermalOpaque = CountNonZeroAlphaPixels(thermalImg, 0.08f);
int modeDiff = CountDifferentPixels(tacticalImg, thermalImg, 0.05f);
GD.Print($"SMOKE INFO: InventoryGrid GPU thermal opaque={thermalOpaque}, diff vs tactical={modeDiff}");
Check(thermalOpaque > 4000, $"Expected > 4000 rendered pixels from InventoryGrid thermal shader, got {thermalOpaque}");
Check(modeDiff > 500, $"Expected thermal conduit toggle to visibly change > 500 pixels, got {modeDiff}");
// Finding 2 GPU check: overheated (350C+, thermal_mode = 1.0f) must obey blend_premul_alpha (out_rgb <= out_a)
// Finding 2 GPU check: overheated (350C..550C+) must obey blend_premul_alpha (out_rgb <= out_a)
testGrid.InjectHardpointHeat("hp.engine.rear", 45000f);
testGrid.InjectHardpointHeat("hp.weapon.main", 25000f);
testGrid.StepHeat(0.05f);
float hotTemp = testGrid.Temperature[1, 3];
Check(hotTemp >= 350f, $"Expected overheated cell >= 350C for premul test, got {hotTemp:F1}C");
vpGrid.SetGrid(testGrid);
vpGrid.SetThermalInstant(true);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
@ -436,7 +434,7 @@ public partial class Smoke : Node
GD.Print($"SMOKE INFO: InventoryGrid GPU overheat ({hotTemp:F1}C) premul violations={premulViolations}");
Check(premulViolations == 0, $"Expected 0 blend_premul_alpha violations (max(RGB) > A + 0.01) on overheated grid, got {premulViolations}");
// Finding 1 GPU check: asymmetric Raptor chassis with thermal_mode = 1.0f must leave 0 lit pixels in inactive cell holes
// Finding 1 GPU check: asymmetric heated Raptor chassis must leave 0 lit pixels in inactive cell holes
var raptorGrid = new ChassisGrid(Catalog.Raptor);
Check(raptorGrid.TryMount(Catalog.CopperRad, "hp.radiator.sh_l"), "Expected CopperRad on Raptor hp.radiator.sh_l");
Check(raptorGrid.TryMount(Catalog.CopperRad, "hp.radiator.sh_r"), "Expected CopperRad on Raptor hp.radiator.sh_r");
@ -447,7 +445,6 @@ public partial class Smoke : Node
raptorGrid.StepHeat(0.25f);
vpGrid.SetGrid(raptorGrid);
vpGrid.SetThermalInstant(true);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
@ -480,7 +477,6 @@ public partial class Smoke : Node
raptorGrid.Cargo.Clear();
Check(raptorGrid.TryAddCargo(Catalog.Autocannon), "Expected Autocannon in Raptor Cargo[0]");
vpGrid.SetGrid(raptorGrid, selectedCargoIndex: 0);
vpGrid.SetThermalInstant(false);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
@ -650,6 +646,8 @@ public partial class Smoke : Node
if (pkg is null) continue;
var vis = VehicleVisualInstance.Create(cache, spec.Id, VehicleVisualRole.Player);
Check(CountMeshInstances(vis.Root) == 0,
$"Expected zero MeshInstance3D children on MultiMesh rig '{spec.Id}', got {CountMeshInstances(vis.Root)}");
Check(vis.BoundHardpointCount == spec.Hardpoints.Length,
$"Expected {spec.Hardpoints.Length} bound hardpoints on '{spec.Id}', got {vis.BoundHardpointCount}");
Check(vis.Joints.Count == pkg.Joints.Count,
@ -663,7 +661,7 @@ public partial class Smoke : Node
foreach (var m in grid.Mounted)
{
var gNode = vis.GetMountedGearNode(m.HardpointId);
if (gNode is not null && CountMeshInstances(gNode) > 0)
if (gNode is not null)
{
mountedMeshes++;
if (m.Spec.Kind == HardpointKind.Weapon)
@ -675,18 +673,18 @@ public partial class Smoke : Node
"recoilless" => ("sight_tube", "breech_band"),
_ => ("condenser_ring_2", "ivory_cowl")
};
Vector3? frontC = ComputeSubtreeVertexCentroidInAncestor(gNode, vis.ModelRoot, frontPart);
Vector3? rearC = ComputeSubtreeVertexCentroidInAncestor(gNode, vis.ModelRoot, rearPart);
Check(frontC.HasValue && rearC.HasValue,
bool hasCentroids = vis.TryGetMountedWeaponCentroidsInModel(
m.HardpointId, frontPart, rearPart, out Vector3 frontC, out Vector3 rearC);
Check(hasCentroids,
$"Missing weapon submeshes '{frontPart}'/'{rearPart}' on '{spec.Id}.{m.HardpointId}' ({m.Spec.Id})");
if (frontC.HasValue && rearC.HasValue)
if (hasCentroids)
{
Vector3 muzzleDir = (frontC.Value - rearC.Value).Normalized();
Vector3 muzzleDir = (frontC - rearC).Normalized();
if (m.Spec.Id == "recoilless")
{
GD.Print($"SMOKE INFO: recoilless {spec.Id}.{m.HardpointId} sight_tube={frontC.Value} breech={rearC.Value} dir={muzzleDir}");
Check(frontC.Value.Z > rearC.Value.Z + 0.20f,
$"Expected recoilless sight_tube (+Z) ahead of breech_band on '{spec.Id}.{m.HardpointId}', got sight={frontC.Value}, breech={rearC.Value}");
GD.Print($"SMOKE INFO: recoilless {spec.Id}.{m.HardpointId} sight_tube={frontC} breech={rearC} dir={muzzleDir}");
Check(frontC.Z > rearC.Z + 0.20f,
$"Expected recoilless sight_tube (+Z) ahead of breech_band on '{spec.Id}.{m.HardpointId}', got sight={frontC}, breech={rearC}");
}
Check(muzzleDir.Z > 0.75f,
$"Expected weapon '{m.Spec.Id}' on '{spec.Id}.{m.HardpointId}' mesh geometry to point forward (+Z), got dir={muzzleDir}");
@ -800,15 +798,15 @@ public partial class Smoke : Node
Check(anvilVis.GetMountedGearNode("hp.weapon.siege_l") is null,
"Expected hp.weapon.siege_l gear to shear off when hardpoint becomes non-operational");
if (debris.GetChildCount() > 0 && debris.GetChild(0) is Node3D firstPiece)
if (debris.TryGetPiecePosition(0, out Vector3 p0))
{
Vector3 p0 = firstPiece.Position;
for (int s = 0; s < 25; s++)
{
debris.Step(1f / 60f, _main.Session.State.Terrain);
}
float moved = firstPiece.Position.DistanceTo(p0);
Check(moved > 0.1f && !HasNaN(firstPiece.Transform),
debris.TryGetPiecePosition(0, out Vector3 p1);
float moved = p1.DistanceTo(p0);
Check(moved > 0.1f && p1.IsFinite(),
$"Expected debris piece to travel/fall > 0.1m under blast + gravity, got {moved:F3}m");
}
@ -848,12 +846,11 @@ public partial class Smoke : Node
debris.QueueFree();
}
// 5. All 15 ChassisDrop salvage wrecks ground within 0.05m of terrain & PickedUp frees drop nodes cleanly
// 5. All 15 ChassisDrop salvage wrecks ground within 0.05m of terrain & PickedUp frees drops cleanly
{
var drops = _main.Session.State.GroundDrops;
int baseCount = drops.Count;
_main.Arena.Sync(_main.Session, 1.0f, 1f / 60f);
int dropNodesBefore = _main.Arena.DropGroupChildCount;
int trackedBefore = _main.Arena.ActiveDropVisualCount;
int nextId = 90000;
@ -876,37 +873,30 @@ public partial class Smoke : Node
for (int i = 0; i < added.Count; i++)
{
var d = added[i];
Node3D? dropNode = _main.Arena.GetNodeOrNull<Node3D>($"GroundDrops/Drop_{d.Id}");
Check(dropNode is not null, $"Missing Drop_{d.Id} node for ChassisDrop '{d.Chassis!.Id}'");
if (dropNode is not null)
bool hasDrop = _main.Arena.TryGetChassisDropVisual(d.Id, out var dropVis, out _);
Check(hasDrop && dropVis is not null, $"Missing ChassisDrop visual for Drop_{d.Id} ('{d.Chassis!.Id}')");
if (hasDrop && dropVis is not null)
{
Node3D? actorNode = dropNode.GetNodeOrNull<Node3D>($"Actor_{d.Chassis!.Id}");
Check(actorNode is not null, $"Missing Actor_{d.Chassis!.Id} under Drop_{d.Id}");
if (actorNode is not null)
{
float minWorldY = ComputeSubtreeMinWorldY(actorNode, dropNode.Position.Y);
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
float err = MathF.Abs(minWorldY - terrainY);
if (err > maxGroundErr) maxGroundErr = err;
Check(err <= 0.05f,
$"ChassisDrop '{d.Chassis!.Id}' buried/floating: minWorldY={minWorldY:F4}m terrainY={terrainY:F4}m err={err:F4}m");
}
dropVis.SetLodState(useStaticLod: false, castShadows: false);
float minWorldY = dropVis.ComputeMinVertexY();
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
float err = MathF.Abs(minWorldY - terrainY);
if (err > maxGroundErr) maxGroundErr = err;
Check(err <= 0.05f,
$"ChassisDrop '{d.Chassis!.Id}' buried/floating: minWorldY={minWorldY:F4}m terrainY={terrainY:F4}m err={err:F4}m");
}
}
GD.Print($"SMOKE INFO: ChassisDrop max ground err={maxGroundErr:F4}m across {added.Count} chassis");
// Also verify far LOD (BakedLodFarMesh) ChassisDrop grounding stays <= 0.05m across all 15 chassis
// Also verify far LOD (SingleSurfaceLodFarMesh) ChassisDrop grounding stays <= 0.05m across all 15 chassis
float maxFarGroundErr = 0f;
for (int i = 0; i < added.Count; i++)
{
var d = added[i];
Node3D? dropNode = _main.Arena.GetNodeOrNull<Node3D>($"GroundDrops/Drop_{d.Id}");
Node3D? actorNode = dropNode?.GetNodeOrNull<Node3D>($"Actor_{d.Chassis!.Id}");
MeshInstance3D? dropMesh = actorNode?.GetNodeOrNull<MeshInstance3D>($"Model_{d.Chassis!.Id}");
if (dropNode is not null && actorNode is not null && dropMesh is not null)
if (_main.Arena.TryGetChassisDropVisual(d.Id, out var dropVis, out _) && dropVis is not null)
{
dropMesh.Mesh = cache.GetOrLoadVehicle(d.Chassis!.Id).BakedLodFarMesh;
float minFarWorldY = ComputeSubtreeMinWorldY(actorNode, dropNode.Position.Y);
dropVis.SetLodState(useStaticLod: true, castShadows: false);
float minFarWorldY = dropVis.ComputeMinVertexY();
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
float err = MathF.Abs(minFarWorldY - terrainY);
if (err > maxFarGroundErr) maxFarGroundErr = err;
@ -924,8 +914,6 @@ public partial class Smoke : Node
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
Check(_main.Arena.ActiveDropVisualCount == trackedBefore,
$"Expected picked-up drops removed from _dropVisuals ({trackedBefore}), got {_main.Arena.ActiveDropVisualCount}");
Check(_main.Arena.DropGroupChildCount == dropNodesBefore,
$"Expected picked-up drop nodes freed from GroundDrops ({dropNodesBefore}), got {_main.Arena.DropGroupChildCount}");
drops.RemoveRange(baseCount, added.Count);
}
@ -946,7 +934,7 @@ public partial class Smoke : Node
foreach (var (wId, footNodeName, pelvisNodeName, checkSagittal) in walkerChecks)
{
var vis = VehicleVisualInstance.Create(cache, wId, VehicleVisualRole.Player);
float restMinY = ComputeSubtreeMinWorldY(vis.ModelRoot, 0f, relativeToModelRoot: true);
float restMinY = vis.ComputeMinVertexY(relativeToModelRoot: true);
float worstRelMinY = float.PositiveInfinity;
float minFootZ = float.PositiveInfinity, maxFootZ = float.NegativeInfinity;
float minFootX = float.PositiveInfinity, maxFootX = float.NegativeInfinity;
@ -959,7 +947,7 @@ public partial class Smoke : Node
for (int step = 0; step < 48; step++)
{
VehicleRigAnimator.Update(vis, in walkInp, Basis.Identity);
float curMinY = ComputeSubtreeMinWorldY(vis.ModelRoot, 0f, relativeToModelRoot: true);
float curMinY = vis.ComputeMinVertexY(relativeToModelRoot: true);
float relMinY = curMinY - restMinY;
if (relMinY < worstRelMinY) worstRelMinY = relMinY;
Check(!float.IsNaN(curMinY), $"NaN vertex Y on walker '{wId}' step {step}");
@ -1099,6 +1087,21 @@ public partial class Smoke : Node
debris.QueueFree();
}
// 10. MultiMeshPartPool & PomDecalPool sanity: live arena submits into MultiMeshPartPool and PomDecalPool stamps impacts cleanly
{
_main.Arena.PomDecals.StampTestDecal(
new Vector3(_main.Session.State.Player.X + 2f, _main.Session.State.Terrain.SampleHeight(_main.Session.State.Player.X + 2f, _main.Session.State.Player.Z) + 0.03f, _main.Session.State.Player.Z),
Vector3.Up, 1.2f, tileIndex: 14);
_main.Arena.Sync(_main.Session, 1.6f, 1f / 60f);
Check(_main.Arena.PartPool.TotalSubmittedInstances > 0,
$"Expected MultiMeshPartPool to submit active instances, got {_main.Arena.PartPool.TotalSubmittedInstances}");
Check(_main.Arena.PomDecals.ActiveCount >= 1,
$"Expected PomDecalPool to hold >= 1 active decal, got {_main.Arena.PomDecals.ActiveCount}");
_main.Hud.PushTestHitArc(_main.Session.State.Player.X + 20f, _main.Session.State.Player.Z + 10f, WeaponVisualClass.Explosive);
Check(_main.Hud.ActiveHitArcCount >= 1, "Expected CrosshairOverlay to accept incoming hit arc");
}
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
}