fix(render): Phase A8 — skip line-7200 terrain when cameraInsideBuilding

User report after Step 5 disable + cull-cache fix: "Cant see anything,
flickering colors, sometimes textures sometimes inside, house missing
lots of walls. 10 FPS. GPU 100%."

Root cause: terrain was being drawn TWICE per indoor frame:
1. Line 7283 _terrain.Draw — UNCONDITIONAL pre-A8 pass; writes full-
   screen terrain color + depth at terrain Z.
2. Step 4 inside RenderInsideOutAcdream — stencil-gated terrain at
   portal silhouettes only (matching WB VisibilityManager:143).

Pre-A8 papered over the Z conflict with a depth-clear-if-inside
workaround (cleared depth between terrain and cottage) which we
DELETED as part of Wave 4. Without it, when Step 3 writes the cell
geometry with DepthFunc.Less, the cottage walls at Z=92-94 (where
they meet the ground) Z-FIGHT against the terrain already in the
depth buffer from pass 1. Symptom: flickering walls + missing
sections + GPU saturated drawing terrain twice.

Fix: gate the line-7200 terrain draw on `!cameraInsideBuilding`.
When indoor, Step 4 is the SOLE terrain pass — stencil-gated to
portal silhouettes only. No double-draw, no Z-fighting, no need
for the deleted depth-clear workaround.

Outdoor mode unchanged (pass 1 still fires, Step 4 isn't taken).

Build green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-05-27 16:14:13 +02:00
parent 9ee42d408a
commit f143ece317

View file

@ -7279,8 +7279,21 @@ public sealed class GameWindow : IDisposable
// Phase N.5b: wrap Draw in CPU stopwatch for [TERRAIN-DIAG] rollup
// (gated on ACDREAM_WB_DIAG=1, same env var as [WB-DIAG]). Stopwatch
// is cheap; only the periodic Console.WriteLine is gated.
//
// FIX 2026-05-28: skip this terrain pass when cameraInsideBuilding.
// RenderInsideOutAcdream's Step 4 draws terrain stencil-gated to
// portal silhouettes (matching WB VisibilityManager:143). Drawing
// terrain BOTH here (full-screen) AND in Step 4 (stencil-gated)
// doubles GPU work AND causes Z-fighting at cottage walls — the
// lower wall portion (Z=92-94) overlaps terrain Z=92, terrain's
// depth from this pass is already in the depth buffer when Step
// 3 writes the cell mesh. The pre-A8 code papered over this with
// a depth-clear-if-inside workaround which we deleted in Wave 4.
// The proper fix is to NOT draw terrain here when indoor; Step 4
// is the single, stencil-gated terrain pass.
_terrainCpuStopwatch.Restart();
_terrain?.Draw(camera, frustum, neverCullLandblockId: playerLb);
if (!cameraInsideBuilding)
_terrain?.Draw(camera, frustum, neverCullLandblockId: playerLb);
_terrainCpuStopwatch.Stop();
// Multiply by 100 then divide by 100 in the diag print to keep
// 0.01 µs precision in the long-typed sample buffer. Terrain Draw