feat(render): indoor render WORKS — terminating portal flood + every-cell seal + look-in FPS

Checkpoint of the unified retail-faithful indoor render. The two-week HANG/grey is fixed and the
interior seals (live-verified by the user). Commits the session render-rewrite foundation together
with the fixes that made it functional.

- HANG fix: PortalVisibilityBuilder.Build portal flood did not terminate (the faithful ProjectToClip
  near-side clip drifts per round, defeating the CellView dedup; the BFS had no bound after U.2a removed
  MaxReprocessPerCell). Fix = drift-tolerant snapped/canonical CellView.Add dedup (PortalView.cs) plus
  restored MaxReprocessPerCell=16 bounded re-enqueue (PortalVisibilityBuilder.cs). Re-enqueue is kept
  (load-bearing for late-slice propagation, Build_ViewGrowthAfterDoneCell_PropagatesNewSlicesToExit);
  only its count is capped. CellViewDedupTests added.
- Seal (DrawCells Task 2): RetailPViewRenderer.DrawEnvCellShells draws EVERY visible cell via
  IndoorDrawPlan.ShellPass (was gated on the ClipFrameAssembler slot filter, leaving slot-less cells grey).
- Look-in FPS: GameWindow exterior look-in candidates limited to the player landblock +-1 (was all ~81
  loaded LBs iterated every outdoor frame). No behaviour change (far cells were >48m, already culled).

Remaining dominant issue = the FLAP at transitions: viewer-cell metastability (render roots at the
camera-eye cell, which oscillates outdoor-indoor as the 3rd-person boom drifts across the doorway,
confirmed in render-sig). SEPARATE fix, NOT the DrawCells port. Full handoff + flap fix plan + tracked
follow-ups (#78 terrain, look-in-from-inside, look-in FPS, L-spotlight):
docs/research/2026-06-07-indoor-render-session-handoff.md.

Baselines: build 0 err; App.Tests 210/210; Core.Tests 1331 pass / 4 fail (pre-existing) / 1 skip.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-07 10:14:43 +02:00
parent bff1955066
commit 1405dd8e90
27 changed files with 3635 additions and 814 deletions

View file

@ -98,6 +98,61 @@ public class PortalVisibilityBuilderTests
"a degenerate portal the eye is NOT standing in must stay culled (no over-inclusion / #95 blowup)");
}
[Fact]
public void Build_CollapsedInteriorPortalNearEyeBeyondHalfMeter_FloodsNeighbour()
{
// Live cellar capture (2026-06-06): 0174->0175 was traversable, but the portal projected to
// zero vertices while the chase camera was about 1.4 m from the opening plane. The flood must
// still reach the stair connector; otherwise the main-floor shell/floor disappears.
var cam = Cell(0x0001, new CellPortalInfo(0x0002, 0, 0, 0));
cam.PortalPolygons.Add(Quad(0f, 0f, 0.35f, 0.35f, 1.4f)); // behind eye: ProjectToNdc collapses
var stairs = Cell(0x0002);
var all = new Dictionary<uint, LoadedCell> { [0x0001] = cam, [0x0002] = stairs };
var vp = ViewProj();
Assert.True(PortalProjection.ProjectToNdc(cam.PortalPolygons[0], Matrix4x4.Identity, vp).Length < 3);
var frame = PortalVisibilityBuilder.Build(
cam, Vector3.Zero, id => all.TryGetValue(id, out var c) ? c : null, vp);
Assert.Contains(0x0002u, frame.OrderedVisibleCells);
}
[Fact]
public void Build_ViewGrowthAfterDoneCell_PropagatesNewSlicesToExit()
{
// Retail PView tracks update_count vs view_count. If B is processed through a LEFT slice, then
// a later path reaches B through a RIGHT slice, B must propagate that new RIGHT slice to its
// exit portal. Enqueue-once builders flap here: OutsideView stays empty until the camera moves
// enough to discover B in the other order.
const uint A = 0x0001, B = 0x0002, D = 0x0003;
var a = Cell(A,
new CellPortalInfo((ushort)B, PolygonId: 0, Flags: 0, OtherPortalId: 0),
new CellPortalInfo((ushort)D, PolygonId: 1, Flags: 0, OtherPortalId: 0));
a.PortalPolygons.Add(QuadX(-0.9f, -0.3f, -2f)); // nearer LEFT path to B
a.PortalPolygons.Add(QuadX(0.3f, 0.9f, -5f)); // farther RIGHT path to D
var b = Cell(B,
new CellPortalInfo((ushort)A, PolygonId: 0, Flags: 0, OtherPortalId: 0),
new CellPortalInfo(0xFFFF, PolygonId: 1, Flags: 0, OtherPortalId: 0),
new CellPortalInfo((ushort)D, PolygonId: 2, Flags: 0, OtherPortalId: 0));
b.PortalPolygons.Add(QuadX(-0.9f, -0.3f, -2f)); // reciprocal LEFT back to A
b.PortalPolygons.Add(QuadX(0.3f, 0.9f, -3f)); // RIGHT exit, invisible from LEFT slice
b.PortalPolygons.Add(QuadX(0.3f, 0.9f, -5f)); // reciprocal RIGHT back to D
var d = Cell(D, new CellPortalInfo((ushort)B, PolygonId: 0, Flags: 0, OtherPortalId: 2));
d.PortalPolygons.Add(QuadX(0.3f, 0.9f, -5f)); // later RIGHT path into B
var all = new Dictionary<uint, LoadedCell> { [A] = a, [B] = b, [D] = d };
var frame = Build(a, all);
Assert.Contains(B, frame.OrderedVisibleCells);
Assert.Contains(D, frame.OrderedVisibleCells);
Assert.False(frame.OutsideView.IsEmpty);
}
[Fact]
public void Builder_SealedCellar_NoExitPortal_OutsideViewEmpty()
{
@ -454,6 +509,117 @@ public class PortalVisibilityBuilderTests
"No exit portal in any reachable cell must leave OutsideView empty");
}
[Fact]
public void BuildFromExterior_SeedsInteriorCellThroughOutsidePortal()
{
var room = Cell(0x0001, new CellPortalInfo(0xFFFF, 0, 0, 0));
room.PortalPolygons.Add(Quad(0f, 0f, 0.5f, 0.5f, -4f));
room.ClipPlanes.Add(new PortalClipPlane
{
Normal = new Vector3(0f, 0f, 1f),
D = 3f,
InsideSide = 1,
});
var frame = PortalVisibilityBuilder.BuildFromExterior(
new[] { room },
Vector3.Zero,
id => id == room.CellId ? room : null,
ViewProj());
Assert.Contains(room.CellId, frame.OrderedVisibleCells);
Assert.True(frame.CellViews.TryGetValue(room.CellId, out var view));
Assert.False(view!.IsEmpty);
Assert.True(view.MaxX - view.MinX < 1.0f,
"exterior seed should be clipped to the door opening, not full-screen");
}
[Fact]
public void BuildFromExterior_DoesNotSeedWhenCameraIsOnInteriorSide()
{
var room = Cell(0x0001, new CellPortalInfo(0xFFFF, 0, 0, 0));
room.PortalPolygons.Add(Quad(0f, 0f, 0.5f, 0.5f, -4f));
room.ClipPlanes.Add(new PortalClipPlane
{
Normal = new Vector3(0f, 0f, 1f),
D = -1f,
InsideSide = 1,
});
var frame = PortalVisibilityBuilder.BuildFromExterior(
new[] { room },
Vector3.Zero,
id => id == room.CellId ? room : null,
ViewProj());
Assert.Empty(frame.OrderedVisibleCells);
Assert.Empty(frame.CellViews);
}
[Fact]
public void BuildFromExterior_TraversesDeeperInteriorPortals()
{
var entry = Cell(0x0001,
new CellPortalInfo(0xFFFF, 0, 0, 0),
new CellPortalInfo(0x0002, 1, 0, 0));
entry.PortalPolygons.Add(Quad(0f, 0f, 0.6f, 0.6f, -3f));
entry.PortalPolygons.Add(Quad(0f, 0f, 0.35f, 0.35f, -5f));
entry.ClipPlanes.Add(new PortalClipPlane
{
Normal = new Vector3(0f, 0f, 1f),
D = 2f,
InsideSide = 1,
});
var backRoom = Cell(0x0002);
var all = new Dictionary<uint, LoadedCell>
{
[entry.CellId] = entry,
[backRoom.CellId] = backRoom,
};
var frame = PortalVisibilityBuilder.BuildFromExterior(
new[] { entry },
Vector3.Zero,
id => all.TryGetValue(id, out var c) ? c : null,
ViewProj());
Assert.Equal(new uint[] { 0x0001, 0x0002 }, frame.OrderedVisibleCells.ToArray());
Assert.True(frame.CellViews.ContainsKey(0x0002));
}
[Fact]
public void BuildFromExterior_MaxSeedDistanceSkipsDistantExitPortal()
{
var nearby = Cell(0x0001, new CellPortalInfo(0xFFFF, 0, 0, 0));
nearby.PortalPolygons.Add(Quad(0f, 0f, 0.5f, 0.5f, -4f));
nearby.ClipPlanes.Add(new PortalClipPlane
{
Normal = new Vector3(0f, 0f, 1f),
D = 3f,
InsideSide = 1,
});
var distant = Cell(0x0002, new CellPortalInfo(0xFFFF, 0, 0, 0));
distant.PortalPolygons.Add(Quad(0f, 0f, 0.5f, 0.5f, -200f));
distant.ClipPlanes.Add(new PortalClipPlane
{
Normal = new Vector3(0f, 0f, 1f),
D = 199f,
InsideSide = 1,
});
var frame = PortalVisibilityBuilder.BuildFromExterior(
new[] { nearby, distant },
Vector3.Zero,
id => id == nearby.CellId ? nearby : id == distant.CellId ? distant : null,
ViewProj(),
maxSeedDistance: 48f);
Assert.Contains(nearby.CellId, frame.OrderedVisibleCells);
Assert.DoesNotContain(distant.CellId, frame.OrderedVisibleCells);
}
[Fact]
public void Build_RootCellAlwaysFirstInOrderedVisibleCells()
{