This reverts ceec3bc4. Two independent reasons, either sufficient.
The rendering regression. The slice deleted TextRenderGlStateScope, which
saved GL_MULTISAMPLE and GL_SAMPLE_ALPHA_TO_COVERAGE on entry, disabled them
for the text pass, and restored them on exit (TextRenderGlStateScope.cs:111-112
and 153-154 at the parent commit). Its replacement bakes that state into the
text pipeline but nothing restores it, and GlGpuPassEncoder.Dispose does not
either. Every world renderer is still raw GL at this point in the campaign, so
from the first UI frame onward the world drew with multisampling disabled.
The offline pixel gate caught it: 1,791 of 563,200 compared pixels differed,
0.318% against a 0.001 threshold. The commit message attributed this to
wall-clock-driven ambient animation shifting phase, and committed through the
failure. That explanation does not survive its own control: capturing twice at
the reverted-to commit differs by 19 pixels and twice at the slice's own commit
by 8, while base-versus-head differs by 1,791 - a 224x gap that no shared-noise
source explains. An amplified difference image settles it visually: the changed
pixels are the silhouette edges of every tree, building and rock, with terrain
interiors, water and the entire UI untouched. That is the signature of losing
edge antialiasing, not of animated sprites.
This is the exact failure mode two existing memory notes already warn about -
a mid-frame renderer must set every GL state it uses rather than inherit it,
and issue #52's lesson that a rendering migration must audit per-pass GL state
before declaring itself done.
The scope. The brief was three small leaf renderers plus additive frame-
lifecycle wiring, roughly ten files. The commit changed 334 files with 3,665
insertions and 3,845 deletions, including 323 public-to-internal visibility
conversions across the App assembly, 55 test files, two retired conformance
tests, and a self-described temporary escape hatch for bridging raw-GL viewport
textures. Even without the regression, that is not separable into the part
worth keeping and the part worth dropping.
Reverting rather than patching because the good work here - the RHI frame
lifecycle wiring and a genuine render-state-cache staleness fix - is small
enough to redo cleanly against a tightened spec, while untangling it from 300+
files of unrelated churn is not.
Post-revert: Release build clean, App suite back to 3,843 passed / 3 skipped,
offline pixel gate passing at 19 differing pixels.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
143 lines
4.5 KiB
C#
143 lines
4.5 KiB
C#
// Ported from references/WorldBuilder/Chorizite.OpenGLSDLBackend/Frustum.cs
|
|
// Phase A8 extraction (2026-05-28). Verbatim algorithm; adaptations:
|
|
// - Namespace: AcDream.App.Rendering.Wb
|
|
// - Class renamed Frustum -> WbFrustum
|
|
// - BoundingBox -> WbBoundingBox (inlined below; no new project dep)
|
|
// - FrustumTestResult kept as-is (inlined below)
|
|
// - WbPlane inlined (was an inner type of Frustum.cs in WB)
|
|
|
|
using System.Numerics;
|
|
|
|
namespace AcDream.App.Rendering.Wb;
|
|
|
|
public struct WbBoundingBox
|
|
{
|
|
public Vector3 Min;
|
|
public Vector3 Max;
|
|
|
|
public WbBoundingBox(Vector3 min, Vector3 max)
|
|
{
|
|
Min = min;
|
|
Max = max;
|
|
}
|
|
|
|
public static WbBoundingBox Union(WbBoundingBox a, WbBoundingBox b) =>
|
|
new WbBoundingBox(
|
|
Vector3.Min(a.Min, b.Min),
|
|
Vector3.Max(a.Max, b.Max));
|
|
}
|
|
|
|
public enum FrustumTestResult
|
|
{
|
|
Outside,
|
|
Inside,
|
|
Intersecting
|
|
}
|
|
|
|
/// <summary>
|
|
/// View-frustum helper extracted from WorldBuilder's Frustum class.
|
|
/// Source: references/WorldBuilder/Chorizite.OpenGLSDLBackend/Frustum.cs
|
|
/// Phase A8 extraction (2026-05-28).
|
|
/// </summary>
|
|
public sealed class WbFrustum
|
|
{
|
|
private struct Plane
|
|
{
|
|
public Vector3 Normal;
|
|
public float D;
|
|
|
|
public Plane(float a, float b, float c, float d)
|
|
{
|
|
Normal = new Vector3(a, b, c);
|
|
float length = Normal.Length();
|
|
Normal /= length;
|
|
D = d / length;
|
|
}
|
|
|
|
public float Dot(Vector3 point) => Vector3.Dot(Normal, point) + D;
|
|
}
|
|
|
|
private readonly Plane[] _planes = new Plane[6];
|
|
private readonly object _lock = new();
|
|
|
|
public void Update(Matrix4x4 matrix)
|
|
{
|
|
lock (_lock)
|
|
{
|
|
// Left plane
|
|
_planes[0] = new Plane(matrix.M14 + matrix.M11, matrix.M24 + matrix.M21, matrix.M34 + matrix.M31, matrix.M44 + matrix.M41);
|
|
// Right plane
|
|
_planes[1] = new Plane(matrix.M14 - matrix.M11, matrix.M24 - matrix.M21, matrix.M34 - matrix.M31, matrix.M44 - matrix.M41);
|
|
// Bottom plane
|
|
_planes[2] = new Plane(matrix.M14 + matrix.M12, matrix.M24 + matrix.M22, matrix.M34 + matrix.M32, matrix.M44 + matrix.M42);
|
|
// Top plane
|
|
_planes[3] = new Plane(matrix.M14 - matrix.M12, matrix.M24 - matrix.M22, matrix.M34 - matrix.M32, matrix.M44 - matrix.M42);
|
|
// Near plane
|
|
_planes[4] = new Plane(matrix.M14 + matrix.M13, matrix.M24 + matrix.M23, matrix.M34 + matrix.M33, matrix.M44 + matrix.M43);
|
|
// Far plane
|
|
_planes[5] = new Plane(matrix.M14 - matrix.M13, matrix.M24 - matrix.M23, matrix.M34 - matrix.M33, matrix.M44 - matrix.M43);
|
|
}
|
|
}
|
|
|
|
public bool Intersects(WbBoundingBox box, bool ignoreNearPlane = false)
|
|
{
|
|
lock (_lock)
|
|
{
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
if (ignoreNearPlane && i == 4) continue;
|
|
|
|
Vector3 positive = box.Min;
|
|
if (_planes[i].Normal.X >= 0) positive.X = box.Max.X;
|
|
if (_planes[i].Normal.Y >= 0) positive.Y = box.Max.Y;
|
|
if (_planes[i].Normal.Z >= 0) positive.Z = box.Max.Z;
|
|
|
|
if (_planes[i].Dot(positive) < 0)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public FrustumTestResult TestBox(WbBoundingBox box, bool ignoreNearPlane = false)
|
|
{
|
|
var result = FrustumTestResult.Inside;
|
|
lock (_lock)
|
|
{
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
if (ignoreNearPlane && i == 4) continue;
|
|
|
|
Vector3 positive = box.Min;
|
|
Vector3 negative = box.Max;
|
|
if (_planes[i].Normal.X >= 0)
|
|
{
|
|
positive.X = box.Max.X;
|
|
negative.X = box.Min.X;
|
|
}
|
|
if (_planes[i].Normal.Y >= 0)
|
|
{
|
|
positive.Y = box.Max.Y;
|
|
negative.Y = box.Min.Y;
|
|
}
|
|
if (_planes[i].Normal.Z >= 0)
|
|
{
|
|
positive.Z = box.Max.Z;
|
|
negative.Z = box.Min.Z;
|
|
}
|
|
|
|
if (_planes[i].Dot(positive) < 0)
|
|
{
|
|
return FrustumTestResult.Outside;
|
|
}
|
|
if (_planes[i].Dot(negative) < 0)
|
|
{
|
|
result = FrustumTestResult.Intersecting;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|