Isoline render smoke: crowded tile, per-family look and dash filter checks (kill M10, M19, M17)

Soul's X1 and X4 probes and a dash-edge check, ported against the shipped extractor.
Readings on ab17b688b: crowded tile worst |h-cpu| 1.1e-5 px against M10 9.5; ray raw D 1.0e-6 off truth against M19 0.21; dash spread 0.0047 against M17 0.455.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-30 00:14:44 +01:00
commit 094a436745

View file

@ -267,6 +267,9 @@ namespace Aetheria.EditorTools
Guarded("composite moves the way raw dir says", CompositeFlow);
Guarded("count guard", CountGuard);
Guarded("pool guard", PoolGuard);
Guarded("crowded tile", CrowdedTile);
Guarded("per-family look", PerFamilyLook);
Guarded("dash filter", DashFilter);
EditorSceneManager.OpenScene("Assets/Scenes/ARPG.unity", OpenSceneMode.Single);
var settings = AssetDatabase.LoadAssetAtPath<GameSettings>("Assets/Resources/Settings.asset")
@ -295,6 +298,179 @@ namespace Aetheria.EditorTools
EditorApplication.Exit(_ok ? 0 : 1);
}
// ---- shader mutants the first smoke missed (verdict cut-isoline-renderer.s1, finding smoke-misses-three-shader-mutants) -----
// Bounds by the margin rule. CrowdBound: shipped worst |h - cpu| 1.1e-5 px (X1 on ab17b688b), M10 (the chunk loop reads
// min(63, left) entries, dropping the 64th) reads h 9.5 at the dropped segment: sqrt(1.1e-5 x 9.5), separation 929.
// FamilyBound: shipped raw D of a SigmaD 6 ray 1.0e-6 off its kernel truth, M19 (the ray reads the contour's sigmaD 3)
// 0.2102 off: sqrt(1.0e-6 x 0.2102) = 4.6e-4, separation 456. DashSpreadBound: relative spread of the composite along
// a dash at a 0.4 px period, shipped 0.0047, M17 (filter width 1e-4) emulated 0.455: sqrt = 0.0462, separation 9.8.
// CrowdDensityBound is a gross gate, not a margin bound: relative |D - cpu| (shipped 0.0143 absolute at the worst
// pixel) has no claimed mutant; M10's D reading was never measured.
const float CrowdBound = 0.0102f;
const float CrowdDensityBound = 0.01f;
const float FamilyBound = 4.6e-4f;
const float DashSpreadBound = 0.0462f;
// Erf in double, Numerical Recipes erfc Chebyshev, 1.2e-7 relative.
static double Erf64(double x)
{
var z = Math.Abs(x);
var t = 1.0 / (1.0 + 0.5 * z);
var r = t * Math.Exp(-z * z - 1.26551223 + t * (1.00002368 + t * (0.37409196 + t * (0.09678418 + t * (-0.18628806 + t * (0.27886807 + t * (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * 0.17087277)))))))));
return x >= 0 ? 1 - r : r - 1;
}
// n short segments in one 8 x 8 tile (n = 64..400, so the cooperative load runs several chunks): raw h and D at every pixel
// around them against a CPU brute force; then one unique-nearest segment placed at list index 0, 63, 64, 127, 128 and n - 1
// must be the one the pixel on it reads. Kills M10, which drops the 64th entry of each chunk.
static void CrowdedTile()
{
var view = Unit256();
try
{
var look = PlainLook();
var rng = new System.Random(3);
float worstH = 0f, worstD = 0f, worstUnique = 0f;
var sigma = look.Contour.SigmaD;
foreach (var n in new[] { 64, 65, 128, 129, 200, 400 })
{
var list = new List<Seg>();
for (var i = 0; i < n; i++)
{
var c = new Vector2(80f + (float)rng.NextDouble() * 8f, 80f + (float)rng.NextDouble() * 8f);
var angle = (float)rng.NextDouble() * Mathf.PI;
var half = 1.5f + (float)rng.NextDouble() * 1.5f;
var dir = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * half;
list.Add(Contour(c - dir, c + dir));
}
var frame = Draw(view, list.ToArray(), look, true);
var pixels = list.Select(s => { Project(view, s.a, s.b, out var pa, out var pb, out _, out _); return (pa, pb); }).ToArray();
for (var y = 64; y < 104; y++)
for (var x = 64; x < 104; x++)
{
var p = new Vector2(x + .5f, y + .5f);
var nearest = pixels.Min(q => DistanceToSegment(p, q.pa, q.pb));
if (nearest <= look.Dilation) worstH = Mathf.Max(worstH, Mathf.Abs(frame.At(x, y).y - nearest));
if (nearest > 2f) continue;
double density = 0;
foreach (var q in pixels)
{
var e = q.pb - q.pa;
var length = e.magnitude;
var unit = e / length;
var along = Vector2.Dot(p - q.pa, unit);
var across = unit.x * (p.y - q.pa.y) - unit.y * (p.x - q.pa.x);
density += Math.Exp(-across * across / (2 * sigma * sigma)) * .5 * (Erf64((length - along) / (sigma * Math.Sqrt(2))) - Erf64(-along / (sigma * Math.Sqrt(2))));
}
worstD = Mathf.Max(worstD, Mathf.Abs(frame.At(x, y).x - (float)density) / Mathf.Max((float)density, 1f));
}
if (frame.Stats[0] != frame.Stats[1] || frame.Stats[2] != 0)
Fail("crowded tile", $"n {n}: tile entries requested {frame.Stats[0]} written {frame.Stats[1]} truncated {frame.Stats[2]}");
}
foreach (var n in new[] { 64, 65, 128, 129, 200 })
foreach (var unique in new[] { 0, 63, 64, 127, 128, n - 1 })
{
if (unique >= n) continue;
var list = new List<Seg>();
for (var i = 0; i < n; i++)
{
if (i == unique) list.Add(Contour(new Vector2(80f, 80.5f), new Vector2(80.6f, 80.5f)));
else { var c = new Vector2(86f + (float)rng.NextDouble() * 2f, 88f + (float)rng.NextDouble() * 1.5f); list.Add(Contour(c, c + new Vector2(1f, 0f))); }
}
// pixel (80, 80) has its centre on the unique segment: its distance is 0
worstUnique = Mathf.Max(worstUnique, Draw(view, list.ToArray(), look, true).At(80, 80).y);
}
Info($"crowded tile: worst |h - cpu| {worstH:G3} px, worst relative |D - cpu| {worstD:G3}, unique-nearest h {worstUnique:G3} px (M10 reads 9.5)");
if (worstH > CrowdBound) Fail("crowded tile", $"worst |h - cpu| {worstH:G4} > {CrowdBound:G4}");
if (worstUnique > CrowdBound) Fail("crowded tile", $"the unique nearest segment reads h {worstUnique:G4} > {CrowdBound:G4}: it was dropped from a tile list");
if (worstD > CrowdDensityBound) Fail("crowded tile", $"worst relative |D - cpu| {worstD:G4} > {CrowdDensityBound:G4}");
}
finally { view.Dispose(); }
}
// The ray family carries its own SigmaD: a ray of SigmaD 6 beside a contour SigmaD 3 reads the SigmaD 6 kernel in raw D.
// Kills M19, whose ray reads the contour's sigmaD and so the 3 kernel.
static void PerFamilyLook()
{
var view = Unit256();
try
{
var look = PlainLook();
look.Ray.SigmaD = 6f; look.Contour.SigmaD = 3f; look.Ray.W = 6f; look.Contour.W = 1f; look.Ray.Period = 0f; look.Ray.Base = Color.white;
var ray = new[] { Segment(new Vector2(10f, 128f), new Vector2(246f, 128f), 0f, 236f, .1f, .1f, true) };
var d = Draw(view, ray, look, true, 1).At(128, 125).x;
var truth = Mathf.Exp(-2.5f * 2.5f / (2f * 36f));
var mutant = Mathf.Exp(-2.5f * 2.5f / (2f * 9f));
var wide = Draw(view, ray, look, false).At(128, 125).w;
var thin = look; thin.Ray.W = 1.5f;
var narrow = Draw(view, ray, thin, false).At(128, 125).w;
Info($"per-family look: ray raw D {d:F4} (kernel truth {truth:F4}, mutant reads {mutant:F4}, |error| {Mathf.Abs(d - truth):G3} against mutant {Mathf.Abs(mutant - truth):G3}); composite alpha 2.5 px off the line W 6 {wide:F3}, W 1.5 {narrow:F3}");
if (Mathf.Abs(d - truth) > FamilyBound) Fail("per-family look", $"ray raw D {d:G4} is not the SigmaD 6 kernel {truth:G4} (bound {FamilyBound:G4})");
if (wide < .6f || narrow > .4f) Fail("per-family look", $"the ray's width does not follow its family's W: {wide:G3} / {narrow:G3}");
}
finally { view.Dispose(); }
}
// The dash is box-filtered over the pixel footprint (w = |ds/dp| / Period). A straight ray with s = arclength:
// (a) Period 0.4 px, the footprint 2.5 periods: the composite along the line is flat at the duty (the sampling phase
// is set so the two alternating pixel phases see the same ink; M17 samples the unfiltered square wave and alternates
// between ink and none); (b) Period 40 px: every dash edge has a pixel strictly between its levels (the box filter's
// edge pixel), where M17 steps. M17 is emulated from two renders of the same ray, solid and duty 0.
static void DashFilter()
{
var view = Unit256();
try
{
var look = PlainLook();
look.Ray.W = 6f; look.Ray.Base = Color.white; look.Ray.Speed = 0f;
float Alpha(Frame f, int x) => f.At(x, 128).w;
Frame Ray(float period, float duty, float x0)
{
var l = look;
l.Ray.Period = period;
l.Ray.Duty = duty;
return Draw(view, new[] { Segment(new Vector2(x0, 128f), new Vector2(246f, 128f), 0f, 246f - x0, .1f, .1f, true) }, l, false);
}
float RelativeSpread(Func<int, float> value)
{
var values = Enumerable.Range(12, 232).Select(value).ToList();
var mean = values.Average();
return Mathf.Sqrt(values.Select(v => (v - mean) * (v - mean)).Average()) / mean;
}
// (a) pixel x has s = x + .5 - x0 = (.02 + 2.5 (x - 10)) periods of .4: phase .02 at x = 10, then .52, .02, ...
var x0a = 10.5f - .008f;
var dashed = Ray(.4f, .5f, x0a);
var solid = Ray(0f, 1f, x0a);
var none = Ray(.4f, 0f, x0a);
var shipped = RelativeSpread(x => Alpha(dashed, x));
var mutant = RelativeSpread(x =>
{
var phase = ((x + .5f - x0a) / .4f) % 1f;
return phase < .5f ? Alpha(solid, x) : Alpha(none, x);
});
Info($"dash filter: relative spread of the composite along a 0.4 px period {shipped:G3} (M17 emulated {mutant:G3}, ratio {mutant / Mathf.Max(shipped, 1e-9f):G3}), bound {DashSpreadBound:G3}");
if (shipped > DashSpreadBound) Fail("dash filter", $"spread {shipped:G4} > {DashSpreadBound:G4} at the sub-pixel period");
// (b) edges at s = 20 + 20 k for a 40 px period at duty .5, landing .37 px into a pixel
var wide = Ray(40f, .5f, 10.37f);
var peak = Enumerable.Range(12, 232).Max(x => Alpha(wide, x));
var trough = Enumerable.Range(12, 232).Min(x => Alpha(wide, x));
int between = 0, steps = 0;
for (var x = 12; x < 243; x++)
{
var f = (Alpha(wide, x) - trough) / (peak - trough);
var g = (Alpha(wide, x + 1) - trough) / (peak - trough);
if (f > .1f && f < .9f) between++;
if ((f >= .9f && g <= .1f) || (f <= .1f && g >= .9f)) steps++;
}
Info($"dash filter: 40 px period, {between} edge pixels between 0.1 and 0.9 of the dash, {steps} hard steps (an unfiltered square wave has no edge pixels: M17 steps at every edge)");
if (steps > 0 || between < 10) Fail("dash filter", $"edges are not antialiased: {between} pixels between the levels, {steps} hard steps");
}
finally { view.Dispose(); }
}
static void Guarded(string name, Action check)
{
try { check(); }