fix(core): AC2D render split formula + triangle-aware Z sampling
Two fundamental terrain fixes based on the AC2D + holtburger deep dive: 1. Terrain split formula: replaced WorldBuilder's physics-path formula (214614067/1813693831) with AC2D's render-path formula (0x0CCAC033, 0x421BE3BD, 0x6C1AC587, 0x519B8F25). The two produce different splits for some cells. Since the render mesh uses this formula, the physics Z sampler must match it to avoid misalignment on slopes. 2. Triangle-aware Z: replaced bilinear interpolation in TerrainSurface with per-triangle barycentric interpolation. Each cell is split into two triangles (using the same AC2D formula). SampleZ determines which triangle the query point falls in, then interpolates within that triangle. This produces Z values that exactly match the visual terrain mesh — no more slope clipping. Removes the multi-point Z sampling hack from PlayerMovementController (no longer needed with exact triangle Z). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5cd776914a
commit
c5de445e5c
4 changed files with 116 additions and 72 deletions
|
|
@ -44,21 +44,26 @@ public static class TerrainBlending
|
|||
/// is designed so that both the visible mesh and the server's collision
|
||||
/// triangulation agree on the same split — diverging from it causes
|
||||
/// visual/physics disagreement at cell boundaries.
|
||||
/// Ported verbatim from WorldBuilder TerrainUtils.CalculateSplitDirection;
|
||||
/// the magic constants must stay exact or AC cells won't split correctly.
|
||||
///
|
||||
/// Uses the RENDER-PATH formula from AC2D and ACViewer's
|
||||
/// LandblockMesh.cs (constants 0x0CCAC033, 0x421BE3BD, 0x6C1AC587,
|
||||
/// 0x519B8F25), NOT the physics-path formula from WorldBuilder
|
||||
/// (214614067 / 1813693831). The two produce different splits for
|
||||
/// some cells, and the render formula is what the real AC client
|
||||
/// uses for the visible terrain mesh. See
|
||||
/// docs/research/2026-04-12-movement-deep-dive.md Part 3.
|
||||
/// </summary>
|
||||
public static CellSplitDirection CalculateSplitDirection(
|
||||
uint landblockX, uint cellX, uint landblockY, uint cellY)
|
||||
{
|
||||
uint seedA = (landblockX * 8 + cellX) * 214614067u;
|
||||
uint seedB = (landblockY * 8 + cellY) * 1109124029u;
|
||||
uint magicA = seedA + 1813693831u;
|
||||
uint magicB = seedB;
|
||||
// uint wraparound is intentional — matches WorldBuilder and AC.
|
||||
float splitDir = magicA - magicB - 1369149221u;
|
||||
return splitDir * 2.3283064e-10f >= 0.5f
|
||||
? CellSplitDirection.SEtoNW
|
||||
: CellSplitDirection.SWtoNE;
|
||||
uint x = landblockX * 8 + cellX;
|
||||
uint y = landblockY * 8 + cellY;
|
||||
uint dw = unchecked(x * y * 0x0CCAC033u - x * 0x421BE3BDu + y * 0x6C1AC587u - 0x519B8F25u);
|
||||
// Bit 31 set = NE/SW diagonal (SWtoNE in our enum)
|
||||
// Bit 31 clear = NW/SE diagonal (SEtoNW in our enum)
|
||||
return (dw & 0x80000000u) != 0
|
||||
? CellSplitDirection.SWtoNE
|
||||
: CellSplitDirection.SEtoNW;
|
||||
}
|
||||
|
||||
// --- Phase 3c.3 algorithms (surface recipe + vertex data packing) ---
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue