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>
155 lines
5.7 KiB
C#
155 lines
5.7 KiB
C#
using System.Numerics;
|
|
using AcDream.Core.World;
|
|
|
|
namespace AcDream.App.Rendering;
|
|
|
|
/// <summary>
|
|
/// Ports retail's teleport projection transition. <c>gmSmartBoxUI::UseTime</c>
|
|
/// (<c>0x004D6E30</c>) eases SmartBox's view-plane distance between the
|
|
/// active game's value and <c>TRANSITION_VIEW_PLANE_DISTANCE = 0.001</c>.
|
|
/// <c>Render::set_vdst</c> (<c>0x0054B240</c>) converts that distance back to
|
|
/// FOV and adjusts the near plane. At the exit edge retail swaps directly
|
|
/// from portal space to the destination world at the transition projection;
|
|
/// there is no black-alpha compositor between them.
|
|
/// </summary>
|
|
public sealed class TeleportViewPlaneController
|
|
{
|
|
public const float TransitionViewPlaneDistance = 0.001f;
|
|
|
|
private float _gameViewPlaneDistance = 1f;
|
|
private readonly ProjectionOverrideCamera _projectionCamera = new();
|
|
|
|
public bool Enabled { get; private set; }
|
|
public float CurrentViewPlaneDistance { get; private set; } = 1f;
|
|
|
|
/// <summary>
|
|
/// Retail <c>BeginTeleportAnimation</c> captures
|
|
/// <c>SmartBox::GetOverrideFovDistance</c> once when starting from Off.
|
|
/// For a standard perspective matrix, M22 is exactly
|
|
/// <c>cot(verticalFov / 2)</c>, retail's view-plane-distance value.
|
|
/// </summary>
|
|
public void Begin(Matrix4x4 gameProjection)
|
|
{
|
|
float distance = gameProjection.M22;
|
|
if (!float.IsFinite(distance) || distance <= 0f)
|
|
distance = 1f;
|
|
|
|
_gameViewPlaneDistance = distance;
|
|
CurrentViewPlaneDistance = distance;
|
|
Enabled = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Apply retail's view-plane state machine. Here "fade" is retail's state
|
|
/// name for a projection transition: normal to 0.001 on fade-out, and
|
|
/// 0.001 back to normal on fade-in. A logout transition retains the
|
|
/// captured override during stable Tunnel; <c>EndTeleportAnimation</c>
|
|
/// (<c>0x004D65D5</c>) releases it when entering TunnelContinue.
|
|
/// </summary>
|
|
public void Update(TeleportAnimSnapshot snapshot)
|
|
{
|
|
switch (snapshot.State)
|
|
{
|
|
case TeleportAnimState.WorldFadeOut:
|
|
case TeleportAnimState.TunnelFadeIn:
|
|
case TeleportAnimState.TunnelFadeOut:
|
|
case TeleportAnimState.WorldFadeIn:
|
|
Enabled = true;
|
|
CurrentViewPlaneDistance = Lerp(
|
|
_gameViewPlaneDistance,
|
|
TransitionViewPlaneDistance,
|
|
snapshot.ViewPlaneBlend);
|
|
break;
|
|
|
|
case TeleportAnimState.Tunnel:
|
|
// Retail preserves the captured FOV override through the
|
|
// logout path's stable tunnel. A normal portal begins in
|
|
// Tunnel with no override, so its disabled state is retained.
|
|
if (Enabled)
|
|
CurrentViewPlaneDistance = _gameViewPlaneDistance;
|
|
break;
|
|
|
|
case TeleportAnimState.TunnelContinue:
|
|
case TeleportAnimState.Off:
|
|
default:
|
|
Enabled = false;
|
|
CurrentViewPlaneDistance = _gameViewPlaneDistance;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Enabled = false;
|
|
CurrentViewPlaneDistance = _gameViewPlaneDistance;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rebuild a perspective projection with retail's active view-plane
|
|
/// distance while preserving the source projection's aspect and far
|
|
/// plane. <c>Render::set_vdst</c> uses
|
|
/// <c>FOV = 2 * atan(1 / distance)</c> and
|
|
/// <c>znear = max(0.1, distance * 0.25)</c>.
|
|
/// </summary>
|
|
public Matrix4x4 Apply(Matrix4x4 baseProjection)
|
|
{
|
|
if (!Enabled)
|
|
return baseProjection;
|
|
|
|
float aspect = baseProjection.M11 != 0f
|
|
? baseProjection.M22 / baseProjection.M11
|
|
: 1f;
|
|
float far = baseProjection.M33 != -1f
|
|
? baseProjection.M43 / (baseProjection.M33 + 1f)
|
|
: 5000f;
|
|
|
|
if (!float.IsFinite(aspect) || aspect <= 0f)
|
|
aspect = 1f;
|
|
if (!float.IsFinite(far) || far <= 0.1f)
|
|
far = 5000f;
|
|
|
|
float distance = MathF.Max(CurrentViewPlaneDistance, TransitionViewPlaneDistance);
|
|
float fov = 2f * MathF.Atan(1f / distance);
|
|
float near = MathF.Max(0.1f, distance * 0.25f);
|
|
if (near >= far)
|
|
near = MathF.Min(0.1f, far * 0.5f);
|
|
|
|
return Matrix4x4.CreatePerspectiveFieldOfView(fov, aspect, near, far);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Decorate the active camera with the same projection returned by
|
|
/// <see cref="Apply(Matrix4x4)"/>. Retail's <c>Render::set_vdst</c> is
|
|
/// global to every 3-D draw; callers must pass this returned camera to
|
|
/// terrain, meshes, particles, sky, weather, and portal-cell rendering so
|
|
/// rasterization and frustum culling cannot use different projections.
|
|
/// </summary>
|
|
public ICamera ApplyTo(ICamera baseCamera)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(baseCamera);
|
|
_projectionCamera.Update(baseCamera, Apply(baseCamera.Projection));
|
|
return _projectionCamera;
|
|
}
|
|
|
|
private static float Lerp(float from, float to, float amount) =>
|
|
from + (to - from) * Math.Clamp(amount, 0f, 1f);
|
|
|
|
private sealed class ProjectionOverrideCamera : ICamera
|
|
{
|
|
private ICamera _source = null!;
|
|
|
|
public Matrix4x4 View => _source.View;
|
|
public Matrix4x4 Projection { get; private set; } = Matrix4x4.Identity;
|
|
public float Aspect
|
|
{
|
|
get => _source.Aspect;
|
|
set => _source.Aspect = value;
|
|
}
|
|
|
|
public void Update(ICamera source, Matrix4x4 projection)
|
|
{
|
|
_source = source;
|
|
Projection = projection;
|
|
}
|
|
}
|
|
}
|