Inventory grid parity: the shader's keyword variants report no error and draw what the plain variant draws

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-29 23:26:21 +01:00
commit 88b3f7afda

View file

@ -60,6 +60,7 @@ public static class InventoryGridParityCapture
var hullOnly = Array.IndexOf(args, "-hullOnly") >= 0;
if (!hullOnly) Atlas();
if (!hullOnly) Thermal(Array.IndexOf(args, "-fitThermal") >= 0);
if (!hullOnly) Variants();
if (Array.IndexOf(args, "-noHull") < 0) Hull();
Log($"SUMMARY atlasWorst={_atlasWorst} hullWorst={_hullWorst} thermalWorstRms={_thermalWorst:F4} bounds atlas={AtlasBound} thermal={ThermalBound}");
@ -328,6 +329,38 @@ public static class InventoryGridParityCapture
for (var i = rig.Page.childCount - 1; i >= 0; i--) UnityEngine.Object.DestroyImmediate(rig.Page.GetChild(i).gameObject);
}
// The shader's keyword variants: with and without UNITY_UI_CLIP_RECT and UNITY_UI_ALPHACLIP it reports no shader error and draws what the
// plain variant draws (the clip rect is opened wide, so clipping changes nothing).
private static void Variants()
{
var shader = GridShader();
var errors = UnityEditor.ShaderUtil.GetShaderMessages(shader).Where(m => m.severity == UnityEditor.Rendering.ShaderCompilerMessageSeverity.Error).ToArray();
Log($"shader messages: {UnityEditor.ShaderUtil.GetShaderMessageCount(shader)} total, {errors.Length} errors");
foreach (var error in errors) Breaches.Add($"shader error: {error.message} ({error.file}:{error.line})");
using var rig = new Rig(1920);
Color32[] Draw(string[] keywords)
{
ClearPage(rig);
var grid = NewObject("Variant", rig.Page, 16, 16, 32).AddComponent<InventoryGrid>();
Look(grid, 1f);
grid.Resize(1, 1, 32, new RectOffset(), GridOrientation.LowerLeft);
grid.SetCell(new int2(0, 0), new CellRecord { Mask = 0b10011001, Present = true, Item = true, Icon = new Color(.9f, .5f, .2f), Background = new Color(0, 0, 0, .9f) });
grid.Flush();
foreach (var keyword in keywords) grid.material.EnableKeyword(keyword);
grid.material.SetVector("_ClipRect", new Vector4(-1e5f, -1e5f, 1e5f, 1e5f));
return rig.Render();
}
var plain = Draw(new string[0]);
foreach (var keywords in new[] { new[] { "UNITY_UI_CLIP_RECT" }, new[] { "UNITY_UI_ALPHACLIP" }, new[] { "UNITY_UI_CLIP_RECT", "UNITY_UI_ALPHACLIP" } })
{
var drawn = Draw(keywords);
var worst = 0;
for (var i = 0; i < plain.Length; i++) worst = Mathf.Max(worst, MaxDifference(plain[i], drawn[i]));
Log($"variant {string.Join("+", keywords)} max8bitDiff against the plain variant = {worst}");
if (worst > 0) Breaches.Add($"variant {string.Join("+", keywords)} differs from the plain variant by {worst}");
}
}
// Thermal pipes: the 16 pipe sprites against the grid's blob and capsules, icon layer only. With -fitThermal the four look
// parameters are first fitted to the sprites by least squares (Nelder-Mead on the squared difference of both sizes) and printed.
private static void Thermal(bool fit)