Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Civ-like region borders: A2 is the default, Legacy and the other variants stay selectable (refs #196) (#1794)

Eyal Golan7fa502efd38b
diff --git a/changelog.d/196-civ-borders-prototype.md b/changelog.d/196-civ-borders-prototype.md
new file mode 100644
index 000000000..5dff686e8
--- /dev/null
+++ b/changelog.d/196-civ-borders-prototype.md
@@ -0,0 +1,7 @@
+### Changed
+- Region borders are stronger and more Civ-like (refs #196; owner ruling 27 Oct 2026, "A2: stronger bands
+ (Recommended)"): the bands keep their weight when the camera pulls out (floors of 6 px colour, 1 px light, 12 px
+ wash), both sides wash alike at 0.45 to a quarter of the hex, a light territory tint grows from 0.12 up close to
+ 0.25 at the overview, and the neutral dashes stay at least 8 px. The earlier look stays selectable with
+ `bordervariant=legacy` in the WebGL URL (or `-bordervariant legacy` on desktop), and the prototype's other variants
+ with `a`, `b`, `c`, `b2` or `c2`: B adds a dark outer rim, C an Okabe-Ito blue, and A is the lighter tier of A2.
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index f571d380c..676339ff5 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -1009,6 +1009,19 @@ row and column profiles across the lines):
Each band lies inside its region, as Civ draws territory, so two outlined regions meet as a double band (blue+white next
to red+cream: promo 03 near Tel Aviv). The bands are world-space: they widen towards the camera.
+**The default look: A2 (owner ruling, 27 Oct 2026, refs #196).** The owner picked "A2: stronger bands (Recommended)"
+from the Civ-like prototype's sheet (`captures/pr-1794`, `civ-borders/sheet.png`), so the map draws A2 unless told
+otherwise. Next to main's look, A2's bands keep their weight when the camera pulls out (no far fade); the colour stripe
+is never under 6 px, the light stripe 1 px and the wash 12 px, measured across the edge so they hold under the tilt.
+Both sides wash alike at 0.45, falling as 1 - x squared, so the wash holds well into the hex and reaches a quarter of
+its inradius (about 1,080 m); a light tint of the region's colour covers the territory, 0.12 up close and rising to
+0.25 at the overview. Band plus wash never pass half the inradius, so a far hex is not filled by its outline. The
+neutral grey keeps its 0.14 wash and its dashes, never shorter than 8 px. The other variants stay selectable for
+comparison: `?bordervariant=legacy` in the WebGL URL (or `-bordervariant legacy` on desktop and in the editor) draws
+main's earlier look exactly, and `a`, `b`, `c`, `b2` and `c2` draw the prototype's other variants; anything else draws A2
+(`MapBorders.VariantRequested`). The paragraphs below describe the drawing every variant shares; their widths, wash
+strengths and the 2 px floor are Legacy's.
+
**What is drawn.** `MapBorders` (C#) bakes one texel per hex (`RegionHexes`, RGBA8 linear, point-sampled, 47 x 58: r + 256 g
the region id, b the style; since issue #195, a's low six bits say which edges border another region) and sets the
globals; `StatecraftBorders.hlsl`'s `ScBorderApply`, called last in the terrain
diff --git a/unity/Assets/Editor/MapCapture.cs b/unity/Assets/Editor/MapCapture.cs
index e0ddcfbe9..17b2aa289 100644
--- a/unity/Assets/Editor/MapCapture.cs
+++ b/unity/Assets/Editor/MapCapture.cs
@@ -207,6 +207,64 @@ public static class MapCapture
finally { QualitySettings.SetQualityLevel(saved, true); }
}
+ /// <summary>The Civ-like border prototype's evidence (#196): the map as a new game starts (the side-coloured control
+ /// layer of 15 May 1948, as GameRoot.Begin draws it; kits and trees on, the water's clock pinned), on the WebGL tier,
+ /// at 1920x1080, from three views: gameplay03, a close view (20 km over the Israeli/Arab boundary hex nearest
+ /// gameplay03) and the overview (diorama02); then the synthetic proof at gameplay03. One set for the variant this run draws
+ /// unasked ("Default": A2, or what -bordervariant names), then one per variant (Legacy, main's earlier look, then A-C2) into
+ /// &lt;-captureDir&gt; (default captures/borders) as &lt;variant&gt;-&lt;view&gt;.png.</summary>
+ public static void BorderVariants()
+ {
+ var args = System.Environment.GetCommandLineArgs();
+ int at = System.Array.IndexOf(args, "-captureDir");
+ var dir = at >= 0 && at + 1 < args.Length ? args[at + 1] : Path.Combine(CaptureDir, "borders");
+ var map = OpenAndBuild();
+ var previous = MapBorders.Variant;
+ int saved = QualitySettings.GetQualityLevel();
+ MapShaderGlobals.PinWaterTime(100f);
+ try
+ {
+ var subdistricts = Subdistricts1948.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", Subdistricts1948.FileName)));
+ var control = map.Control ?? Control1948.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", Control1948.FileName)));
+ new MapRegions(subdistricts, Armistice1949.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", Armistice1949.FileName))), control)
+ .Apply(subdistricts.ShownFrom);
+ var layer = MapBorders.Current ?? throw new System.InvalidOperationException("no region layer on the start date");
+ // The close view: the Primary hex nearest gameplay03 with a Secondary neighbour.
+ var centre = BorderProof.HexAt(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat);
+ BorderStyle Style(int q, int r) => layer.StyleOf(layer.RegionOf(q, r));
+ var close = map.Hexes.hexes.Where(h => Style(h.q, h.r) == BorderStyle.Primary
+ && MapBorders.NeighbourSteps.Any(d => Style(h.q + d.dq, h.r + d.dr) == BorderStyle.Secondary))
+ .OrderBy(h => BorderProof.Distance((h.q, h.r), centre)).FirstOrDefault()
+ ?? throw new System.InvalidOperationException("no Israeli/Arab boundary on the start date");
+ Debug.Log($"BorderVariants: close view over hex ({close.q}, {close.r}) at {close.lon:0.000}, {close.lat:0.000}");
+ var closePose = new PromoPose("close20", close.lon, close.lat, 20000f, PromoPose.Gameplay03.Yaw);
+ var rig = Camera.main.GetComponent<CameraRig>();
+ QualitySettings.SetQualityLevel(0, true); // Mobile: the WebGL tier
+ void Shoot(string prefix, IEnumerable<PromoPose> poses)
+ {
+ var sets = new[] { ("Default", previous) }
+ .Concat(((BorderVariant[])System.Enum.GetValues(typeof(BorderVariant))).Select(v => (v.ToString(), v)));
+ foreach (var (name, variant) in sets)
+ {
+ MapBorders.Variant = variant;
+ foreach (var pose in poses)
+ {
+ pose.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();
+ Save(Camera.main, 1920, 1080, Path.Combine(dir, $"{name}-{prefix}{pose.Name}.png"));
+ }
+ }
+ }
+ Shoot("", new[] { PromoPose.Gameplay03, closePose, PromoPose.Diorama02 });
+ BorderProof.Show(map);
+ Shoot("proof-", new[] { PromoPose.Gameplay03 });
+ }
+ finally
+ {
+ QualitySettings.SetQualityLevel(saved, true); MapBorders.Variant = previous; MapShaderGlobals.PinWaterTime(null);
+ if (MapBorders.Current != null) MapBorders.Use(null); // the layer and the synthetic proof go with the capture
+ }
+ }
+
/// <summary>The scripted trailer capture (issue #45): flies the camera through TrailerShot.Default and renders every frame
/// at 1920x1080 on the desktop tier (PC) into &lt;-captureDir&gt; (default captures/trailer) as frame-NNNNN.png, one numbered
/// sequence across the shots, with the water's clock pinned to the frame's time so a re-run gives the same camera, state
diff --git a/unity/Assets/Scripts/Map/MapBorders.cs b/unity/Assets/Scripts/Map/MapBorders.cs
index 6c1da2155..80d78f517 100644
--- a/unity/Assets/Scripts/Map/MapBorders.cs
+++ b/unity/Assets/Scripts/Map/MapBorders.cs
@@ -14,6 +14,17 @@ namespace Statecraft.Game.Map
/// drawn from its side).</summary>
public enum BorderStyle : byte { None = 0, Primary = 1, Secondary = 2, Neutral = 3 }
+ /// <summary>The Civ-like border prototype's variants for the owner to choose from (#196, owner 2026-10-26: "make the border
+ /// lines more visible and civ-like", "Try dark outline, Try stronger blue"). A2 is the default (owner ruling 2026-10-27:
+ /// "A2: stronger bands (Recommended)"; MapBorders.DefaultVariant). Legacy: main's earlier borders exactly, still
+ /// selectable. A: bands that hold their weight at every
+ /// zoom, an equal wash on both sides reaching a quarter of the hex, pixel floors and a territory tint that grows as the
+ /// camera pulls out. B: A with a thin dark outer rim. C: A with the Primary blue pushed toward Okabe-Ito's
+ /// colour-blind-safe blue (#0072B2). A2, B2, C2: the same on the stronger tier for gameplay03, the view players live in
+ /// (coordinator, 2026-10-26: A read almost like main there): a 6 px colour stripe floor, a 0.45 wash that holds most
+ /// of its strength until near its reach, and a 0.12 tint up close (MapBorders.Strong*).</summary>
+ public enum BorderVariant : byte { Legacy = 0, A = 1, B = 2, C = 3, A2 = 4, B2 = 5, C2 = 6 }
+
/// <summary>Which region each hex belongs to, and how each region is outlined: what the border renderer draws. A hex not
/// listed belongs to no region, and no band is drawn against it (the coast, the edge of the data). Region ids run from 1
/// to <see cref="MaxId"/>. The renderer draws only what a layer says, so a layer must come from real, sourced data (owner
@@ -67,38 +78,133 @@ namespace Statecraft.Game.Map
public const string ToggleName = "borders";
static readonly int RegionTex = Shader.PropertyToID("_ScRegionTex"), RegionInfo = Shader.PropertyToID("_ScRegionInfo"),
- Borders = Shader.PropertyToID("_ScBorders"),
+ Borders = Shader.PropertyToID("_ScBorders"), Min = Shader.PropertyToID("_ScBorderMin"), Tint = Shader.PropertyToID("_ScBorderTint"),
+ Rim = Shader.PropertyToID("_ScBorderRim"), Dash = Shader.PropertyToID("_ScBorderDash"),
Colour1 = Shader.PropertyToID("_ScBorderColour1"), Light1 = Shader.PropertyToID("_ScBorderLight1"), Shape1 = Shader.PropertyToID("_ScBorderShape1"),
Colour2 = Shader.PropertyToID("_ScBorderColour2"), Light2 = Shader.PropertyToID("_ScBorderLight2"), Shape2 = Shader.PropertyToID("_ScBorderShape2"),
Colour3 = Shader.PropertyToID("_ScBorderColour3"), Light3 = Shader.PropertyToID("_ScBorderLight3"), Shape3 = Shader.PropertyToID("_ScBorderShape3");
/// <summary>One style's look. Colours are sRGB (above 1: brighter than white before the grade), measured on
/// promo/final/03-gameplay-1936.png (2752 px wide) and set so the graded game matches them (docs/visual-v1.md, "Region borders"). BandM is the coloured plus light stripe in metres,
- /// so the band grows towards the camera as the promo's does; ColourShare the coloured stripe's part of it; Wash the
- /// wash's width as a multiple of the band, WashStrength its opacity at the band.</summary>
+ /// so the band grows towards the camera as the promo's does; ColourShare the coloured stripe's part of it; WashReach
+ /// how far the wash runs from the edge as a share of the hex's inradius, WashStrength its opacity at the band.</summary>
public readonly struct Style
{
- public readonly Color Colour, Light; public readonly float BandM, ColourShare, Wash, WashStrength;
- public Style(Color colour, Color light, float bandM, float colourShare, float wash, float washStrength)
- { Colour = colour; Light = light; BandM = bandM; ColourShare = colourShare; Wash = wash; WashStrength = washStrength; }
+ public readonly Color Colour, Light; public readonly float BandM, ColourShare, WashReach, WashStrength;
+ public Style(Color colour, Color light, float bandM, float colourShare, float washReach, float washStrength)
+ { Colour = colour; Light = light; BandM = bandM; ColourShare = colourShare; WashReach = washReach; WashStrength = washStrength; }
}
+ /// <summary>How far every style's wash runs from the edge: a quarter of the hex's inradius (about 1,080 m), the
+ /// reach the Civ VI research puts on each side of its border ribbon (prototype #196; was 0.9-1.0 of the band, about
+ /// 10% of the inradius with the band).</summary>
+ public const float WashReachShare = 0.25f;
+ /// <summary>Both sides' wash strength, equal so neither side's territory reads as the junior one (prototype #196;
+ /// the Secondary was 0.18 against the Primary's 0.40).</summary>
+ public const float SideWashStrength = 0.40f;
+ /// <summary>The stronger tier (A2, B2, C2): the colour stripe's floor, both sides' wash strength, the tint up close,
+ /// and a wash that holds (falls as 1 - x squared over its reach instead of a smoothstep), so it reads well into the
+ /// hex at gameplay03.</summary>
+ public const float StrongMinColourPx = 6f, StrongWashStrength = 0.45f, StrongTintNear = 0.12f;
+ public static bool Strong(BorderVariant v) => v >= BorderVariant.A2;
+
+ /// <summary>Legacy: main's styles, exactly (shape: band m, colour share, wash width times the band, wash strength),
+ /// with main's 2 px floor for the whole band and its far fade (StatecraftBorders.hlsl, ScBorderLegacy).</summary>
+ static readonly Vector4 LegacyShape1 = new Vector4(230f, 0.5f, 0.9f, 0.40f), LegacyShape2 = new Vector4(200f, 0.6f, 1.0f, 0.18f),
+ LegacyShape3 = new Vector4(200f, 0.6f, 0.8f, 0.14f);
+ public const float LegacyMinBandPx = 2f;
+ public static bool HasRim(BorderVariant v) => v == BorderVariant.B || v == BorderVariant.B2;
+ public static bool StrongBlue(BorderVariant v) => v == BorderVariant.C || v == BorderVariant.C2;
+
/// <summary>The promo's blue line (6 + 6 px of blue and white with a 10 px wash at 2752 px; white 251,251,248), the
/// heavier of the two, in the deeper blue of the owner's ruling (2026-10-14): about 89,119,156 on screen after the
/// grade (promo 03's Israeli side), against main's lighter 120,142,192.</summary>
- public static readonly Style Primary = new Style(new Color(0.29f, 0.40f, 0.56f), new Color(1.08f, 1.08f, 1.06f), 230f, 0.5f, 0.9f, 0.40f);
+ public static readonly Style Primary = new Style(new Color(0.29f, 0.40f, 0.56f), new Color(1.08f, 1.08f, 1.06f), 230f, 0.5f, WashReachShare, SideWashStrength);
+ /// <summary>Variant C's Primary: the same band in Okabe-Ito's colour-blind-safe blue #0072B2 (sRGB 0, 114, 178),
+ /// stronger and more saturated than the owner's 2026-10-14 deeper blue; a proposal, not a ruling.</summary>
+ public static readonly Style PrimaryStrongBlue = new Style(new Color(0f, 0.447f, 0.698f), new Color(1.08f, 1.08f, 1.06f), 230f, 0.5f, WashReachShare, SideWashStrength);
/// <summary>The promo's red-orange line (4 + 3 px with an 8 px wash; 176,93,61 and 246,188,124), a little more
/// saturated than the promo's so it keeps a contrast against both olive and dry-grass ground for colour-blind players
/// (GradeTests).</summary>
- public static readonly Style Secondary = new Style(new Color(0.75f, 0.31f, 0.13f), new Color(1.05f, 0.76f, 0.48f), 200f, 0.6f, 1.0f, 0.18f);
+ public static readonly Style Secondary = new Style(new Color(0.75f, 0.31f, 0.13f), new Color(1.05f, 0.76f, 0.48f), 200f, 0.6f, WashReachShare, SideWashStrength);
/// <summary>A grey line with a pale inner stripe and a faint wash, the width of the red-orange: neither side's colour
/// (contested, no-man's land, a demilitarized zone, the 1947 sub-districts before any side is sourced). Its lightness sits
/// between the two sides' so colour-blind players still tell it from both (GradeTests).</summary>
- public static readonly Style Neutral = new Style(new Color(0.46f, 0.46f, 0.44f), new Color(0.98f, 0.97f, 0.93f), 200f, 0.6f, 0.8f, 0.14f);
- /// <summary>The band draws at least MinBandPx wide (the overview), unless that would make it, with its wash, wider than
- /// MaxShareOfInradius of a hex's inradius: that cap wins (below about 8 px of inradius on screen the band goes under
- /// 2 px), so a far hex is never filled by its outline.</summary>
- public const float MinBandPx = 2f, MaxShareOfInradius = 0.5f;
+ public static readonly Style Neutral = new Style(new Color(0.46f, 0.46f, 0.44f), new Color(0.98f, 0.97f, 0.93f), 200f, 0.6f, WashReachShare, 0.14f);
+ /// <summary>The least on-screen widths, measured across the edge (metres per pixel along the band's normal, so they
+ /// hold under the camera's tilt): the colour stripe, the light stripe and the wash. They hold at every zoom (no far
+ /// fade), unless band plus wash would be wider than MaxShareOfInradius of a hex's inradius: that cap wins, the wash
+ /// giving way first, so a far hex is never filled by its outline (BandWidths).</summary>
+ public const float MinColourPx = 3f, MinLightPx = 1f, MinWashPx = 12f, MaxShareOfInradius = 0.5f;
+ /// <summary>The territory tint: TintNear of the region's colour over the whole region while a hex's inradius is
+ /// TintNearInradiusPx or more on screen, rising to TintFar at TintFarInradiusPx and below (the overview), so far off
+ /// the map reads as coloured territory with a firm edge (Civ V's 25% owned-hex fill; Civ VI's minimap).</summary>
+ public const float TintNear = 0.08f, TintFar = 0.25f, TintNearInradiusPx = 120f, TintFarInradiusPx = 40f;
+ /// <summary>The neutral style's dashes (a cue that is not colour, review S9 of #555): NeutralDashM metres a period,
+ /// the first NeutralDashOn of it drawn, the period doubling as the camera pulls out so a drawn dash is never under
+ /// NeutralDashMinPx.</summary>
+ public const float NeutralDashM = 2000f, NeutralDashOn = 0.65f, NeutralDashMinPx = 8f;
+ /// <summary>Variant B's dark outer rim along the edge, outside the colour stripe: RimM wide, never under RimMinPx,
+ /// drawn at RimOpacity in the band's colour at RimValue of its brightness. Not on a shared edge (one band, no seam).</summary>
+ public const float RimM = 50f, RimMinPx = 1f, RimOpacity = 0.6f, RimValue = 0.3f;
+
+ /// <summary>A band's on-screen widths (px) at <paramref name="metresPerPx"/> across its edge: the mirror of
+ /// StatecraftBorders.hlsl's ScBandWidths, for the tests. The wash runs to WashReach of the inradius from the edge.</summary>
+ public static (float rim, float colour, float light, float wash) BandWidths(Style s, float metresPerPx, float inradiusM, bool rim,
+ float minColourPx = MinColourPx)
+ {
+ float widest = MaxShareOfInradius * inradiusM / metresPerPx;
+ float rimPx = rim ? Mathf.Min(Mathf.Max(RimM / metresPerPx, RimMinPx), widest) : 0f;
+ float room = widest - rimPx;
+ float colour = Mathf.Max(s.BandM * s.ColourShare / metresPerPx, minColourPx);
+ float light = Mathf.Max(s.BandM * (1f - s.ColourShare) / metresPerPx, MinLightPx);
+ float wash = Mathf.Max(s.WashReach * inradiusM / metresPerPx - colour - light, MinWashPx);
+ wash = Mathf.Min(wash, Mathf.Max(room - colour - light, 0f));
+ float k = Mathf.Min(1f, room / Mathf.Max(colour + light, 1e-4f));
+ return (rimPx, colour * k, light * k, wash);
+ }
+
+ /// <summary>The territory tint's opacity when a hex's inradius is <paramref name="inradiusPx"/> on screen.</summary>
+ public static float TintAlpha(float inradiusPx, float near = TintNear) =>
+ Mathf.Lerp(near, TintFar, Mathf.Clamp01((TintNearInradiusPx - inradiusPx) / (TintNearInradiusPx - TintFarInradiusPx)));
+
+ /// <summary>The neutral dashes' period (m) at <paramref name="metresPerPx"/>: the mirror of the shader's.</summary>
+ public static float NeutralDashPeriodM(float metresPerPx) =>
+ NeutralDashM * Mathf.Pow(2f, Mathf.Max(0f, Mathf.Ceil(Mathf.Log(NeutralDashMinPx / NeutralDashOn * metresPerPx / NeutralDashM, 2f))));
+
+ /// <summary>The variant drawn when none is asked for: A2 (owner ruling 2026-10-27: "A2: stronger bands
+ /// (Recommended)").</summary>
+ public const BorderVariant DefaultVariant = BorderVariant.A2;
+
+ /// <summary>The variant drawn: DefaultVariant unless the "bordervariant=legacy|a|b|c|a2|b2|c2" URL parameter (WebGL)
+ /// or -bordervariant ... (desktop, editor) names one; anything else is DefaultVariant. Setting it redraws at once; it
+ /// outlives map builds.</summary>
+ public static BorderVariant Variant
+ {
+ get => variant ??= VariantRequested(Application.absoluteURL, Environment.GetCommandLineArgs(), Application.platform == RuntimePlatform.WebGLPlayer);
+ set { variant = value; if (texture != null) { SetStyles(); Push(); } }
+ }
+ static BorderVariant? variant;
+
+ public static BorderVariant VariantRequested(string? url, string[] args, bool webgl)
+ {
+ string? v = null;
+ if (webgl)
+ {
+ var m = System.Text.RegularExpressions.Regex.Match(url ?? "", @"[?&]bordervariant=((?i:legacy|[abc]2?))(?=[&#]|$)");
+ if (m.Success) v = m.Groups[1].Value;
+ }
+ else
+ {
+ int at = Array.IndexOf(args, "-bordervariant");
+ if (at >= 0 && at + 1 < args.Length) v = args[at + 1];
+ }
+ return v?.ToLowerInvariant() switch
+ {
+ "b" => BorderVariant.B, "c" => BorderVariant.C, "a2" => BorderVariant.A2, "b2" => BorderVariant.B2, "c2" => BorderVariant.C2,
+ "a" => BorderVariant.A, "legacy" => BorderVariant.Legacy, _ => DefaultVariant,
+ };
+ }
static Texture2D? texture;
static MapRuntimeAssets? owner;
@@ -134,9 +240,7 @@ namespace Statecraft.Game.Map
Current = null; hasLayer = false; toggleOn = true; noEarlyOut = false;
Shader.SetGlobalTexture(RegionTex, tex);
Shader.SetGlobalVector(RegionInfo, new Vector4(qMin, rMin, w, h));
- SetStyle(Colour1, Light1, Shape1, Primary);
- SetStyle(Colour2, Light2, Shape2, Secondary);
- SetStyle(Colour3, Light3, Shape3, Neutral);
+ SetStyles();
Push();
assets.OnTeardown(VisualToggles.Register(ToggleName, on => { toggleOn = on; Push(); }));
assets.OnTeardown(() => { texture = null; owner = null; banner = null; Current = null; hasLayer = false; noEarlyOut = false; Push(); });
@@ -191,18 +295,40 @@ namespace Statecraft.Game.Map
/// StatecraftBorders.hlsl's ScHexNormals, so bit i of the edge mask is the edge shared with neighbour i.</summary>
public static readonly (int dq, int dr)[] NeighbourSteps = { (1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1) };
+ static void SetStyles()
+ {
+ var v = Variant; bool strong = Strong(v);
+ if (v == BorderVariant.Legacy)
+ {
+ SetStyle(Colour1, Light1, Shape1, Primary); Shader.SetGlobalVector(Shape1, LegacyShape1);
+ SetStyle(Colour2, Light2, Shape2, Secondary); Shader.SetGlobalVector(Shape2, LegacyShape2);
+ SetStyle(Colour3, Light3, Shape3, Neutral); Shader.SetGlobalVector(Shape3, LegacyShape3);
+ Shader.SetGlobalVector(Min, new Vector4(0f, 0f, 0f, 1f)); // w 1: main's drawing (ScBorderLegacy)
+ Shader.SetGlobalVector(Rim, Vector4.zero);
+ return;
+ }
+ Style Side(Style s) => strong ? new Style(s.Colour, s.Light, s.BandM, s.ColourShare, s.WashReach, StrongWashStrength) : s;
+ SetStyle(Colour1, Light1, Shape1, Side(StrongBlue(v) ? PrimaryStrongBlue : Primary));
+ SetStyle(Colour2, Light2, Shape2, Side(Secondary));
+ SetStyle(Colour3, Light3, Shape3, Neutral);
+ Shader.SetGlobalVector(Min, new Vector4(MinLightPx, MinWashPx, strong ? 1f : 0f, 0f)); // w 0: the prototype's drawing
+ Shader.SetGlobalVector(Tint, new Vector4(strong ? StrongTintNear : TintNear, TintFar, TintNearInradiusPx, TintFarInradiusPx));
+ Shader.SetGlobalVector(Rim, new Vector4(RimM, RimMinPx, HasRim(v) ? RimOpacity : 0f, RimValue));
+ Shader.SetGlobalVector(Dash, new Vector4(NeutralDashM, NeutralDashOn, NeutralDashMinPx, 0f));
+ }
+
static void SetStyle(int colour, int light, int shape, Style s)
{
var c = s.Colour.linear; var l = s.Light.linear;
Shader.SetGlobalVector(colour, new Vector4(c.r, c.g, c.b, 1f));
Shader.SetGlobalVector(light, new Vector4(l.r, l.g, l.b, 1f));
- Shader.SetGlobalVector(shape, new Vector4(s.BandM, s.ColourShare, s.Wash, s.WashStrength));
+ Shader.SetGlobalVector(shape, new Vector4(s.BandM, s.ColourShare, s.WashReach, s.WashStrength));
}
static void Push()
{
bool drawn = toggleOn && hasLayer && texture != null;
- Shader.SetGlobalVector(Borders, new Vector4(MinBandPx, MaxShareOfInradius, noEarlyOut ? 1f : 0f, drawn ? 1f : 0f));
+ Shader.SetGlobalVector(Borders, new Vector4(Variant == BorderVariant.Legacy ? LegacyMinBandPx : Strong(Variant) ? StrongMinColourPx : MinColourPx, MaxShareOfInradius, noEarlyOut ? 1f : 0f, drawn ? 1f : 0f));
if (banner != null) banner.SetActive(drawn);
}
diff --git a/unity/Assets/Shaders/StatecraftBorders.hlsl b/unity/Assets/Shaders/StatecraftBorders.hlsl
index 3043f4d8c..314e71883 100644
--- a/unity/Assets/Shaders/StatecraftBorders.hlsl
+++ b/unity/Assets/Shaders/StatecraftBorders.hlsl
@@ -2,7 +2,8 @@
#define STATECRAFT_BORDERS_INCLUDED
// Region borders (promo-borders): the promo's two-tone outlines along hex edges, drawn inside each region along every edge
// it shares with a different region (as Civ draws them, so two outlined regions meet as a double band): a coloured stripe on
-// the edge, a light stripe inside it, then a soft wash of the colour fading inwards. Data driven: MapBorders (C#) bakes one
+// the edge, a light stripe inside it, then a soft wash of the colour fading inwards, over a light tint of the whole region
+// that grows as the camera pulls out (the Civ-like prototype for the owner, #196: MapBorders.Variant). Data driven: MapBorders (C#) bakes one
// texel per hex (_ScRegionTex) and sets the globals; with no region data, or the "borders" toggle off, _ScBorders.w is 0 and
// nothing is drawn. Included at the end of StatecraftMap.hlsl; the terrain calls ScBorderApply last.
@@ -11,12 +12,17 @@ TEXTURE2D(_ScRegionTex); // one texel per hex, linear RGBA8: r + 256 g the regi
// shared edge: each side draws ScSharedBand of the band, so the two make one band centred on the edge), a's low
// six bits which edges border another region (MapBorders.Use bakes them; issue #195)
float4 _ScRegionInfo; // x q of texel column 0, y r of texel row 0, z width, w height (texels)
-float4 _ScBorders; // x least band width (px), y widest band (+ wash) as a share of the hex's inradius,
+float4 _ScBorders; // x least colour stripe (px), y widest band (+ wash) as a share of the hex's inradius,
// z 1 = no early-out (tests prove the early-out exact), w 1 = on
+float4 _ScBorderMin; // x least light stripe (px), y least wash (px), z the wash's hold: 0 a smoothstep fall, 1 a 1 - x^2 one
+float4 _ScBorderDash; // the neutral style's dashes (a cue that is not colour, for colour-blind players: review S9 of #555):
+ // x metres a period, y the drawn share of it, z the least drawn dash (px)
+float4 _ScBorderTint; // x the territory tint near, y far; z the hex inradius (px) where it starts rising, w where it is full
+float4 _ScBorderRim; // the dark outer rim (variant B): x width (m), y least width (px), z opacity (0: none), w value (times the colour)
// Per style (1 primary: the Israeli side, 2 secondary: the other side, 3 neutral: contested, no-man's land, a
// demilitarized zone, or the 1947 sub-districts before any side is sourced): Colour rgb the edge stripe (linear); Light rgb
-// the inner stripe; Shape x the band's width (m; colour + light stripes), y the colour stripe's share of it, z the wash's
-// width (times the band's), w its strength.
+// the inner stripe; Shape x the band's width (m; colour + light stripes), y the colour stripe's share of it, z how far the
+// wash reaches from the edge (a share of the hex's inradius), w its strength.
float4 _ScBorderColour1, _ScBorderLight1, _ScBorderShape1;
float4 _ScBorderColour2, _ScBorderLight2, _ScBorderShape2;
float4 _ScBorderColour3, _ScBorderLight3, _ScBorderShape3;
@@ -26,9 +32,6 @@ float4 _ScBorderColour3, _ScBorderLight3, _ScBorderShape3;
// The share of its band each side of a shared edge draws. At exactly half, each half loses its partly covered outer pixel
// and the pair measured 6 px at gameplay03 against a full band's 8 (promo 03: about 8); at 0.6 the two measure as one band.
static const float ScSharedBand = 0.6;
-// The neutral style is dashed along its edge (a cue that is not colour, for colour-blind players: review S9 of #555):
-// ScNeutralDashM metres a period, the first ScNeutralDashOn of it drawn.
-static const float ScNeutralDashM = 2000.0, ScNeutralDashOn = 0.65;
static const float2 ScHexNormals[6] = { float2(1, 0), float2(0.5, -0.8660254), float2(-0.5, -0.8660254), float2(-1, 0),
float2(-0.5, 0.8660254), float2(0.5, 0.8660254) };
@@ -57,49 +60,155 @@ float2 ScHexAxial(float2 p, float size, out float2 v)
return float2(q, r);
}
-// Adds the borders to the terrain's outputs (unlit: the stripes and wash replace BaseColor and go out as Emission, so they
-// read the same in sun and shadow, as the promo's glowing lines do). mapM: metres east and north of the map's south-west
-// corner; water: ScWater's 0 (land) .. 1 (water): bands stay on land, so a boundary that reaches the coast stops at the
-// shore instead of running up to 4 km out to its hex's edge (review M7). Call it in uniform control flow (outside any
-// [branch]): it takes derivatives.
-void ScBorderApply(float2 mapM, float water, inout float3 baseColor, inout float3 emission)
+
+// ---- Legacy: main's borders, unchanged (the default until the owner picks a variant; MapBorders.Variant) ----
+// The neutral style's dashes as main draws them: ScLegacyDashM metres a period, the first ScLegacyDashOn of it drawn.
+static const float ScLegacyDashM = 2000.0, ScLegacyDashOn = 0.65;
+
+// How far main's band and wash can reach from an edge (m): the wider style's band (or the least width in pixels, at up to
+// 1.5x the footprint: the gradient's metres per pixel never exceed sqrt 2 of it) times 1 + its wash, plus a pixel for the
+// filter. A pixel farther than that from every edge of its hex is in no band, so it fetches no texel (review: 7 fetches on
+// every land pixel cost 3.3 ms at gameplay03).
+float ScLegacyReach(float footprint)
{
- float2 p = float2(mapM.x, _ScMap.y - mapM.y);
- float2 px = ddx(p), py = ddy(p);
- [branch] if (_ScBorders.w > 0.5)
+ float washMul = 1.0 + max(max(_ScBorderShape1.z, _ScBorderShape2.z), _ScBorderShape3.z);
+ return max(max(max(_ScBorderShape1.x, _ScBorderShape2.x), _ScBorderShape3.x), 1.5 * _ScBorders.x * footprint) * washMul + 1.5 * footprint;
+}
+
+// Main's drawing of one pixel (_ScBorderShape.z the wash's width times the band's, _ScBorders.x the least band width).
+void ScBorderLegacy(float4 own, float2 v, float2 p, float2 px, float2 py, float size, float inradius, float reach,
+ float footprint, float water, inout float3 baseColor, inout float3 emission)
+{
+ int edges = (int)own.z, sharedEdges = (int)own.w;
+ // A hex with no border edge draws nothing (the loop below would leave cover 0), so it skips the work.
+ [branch] if (own.x > 0.5 && own.y > 0.5 && edges != 0)
{
- float size = _ScMapOrigin.w, inradius = 0.8660254 * size;
- float2 v;
- float2 qr = ScHexAxial(p, size, v);
- // How far a band and its wash can reach from an edge (m): the wider style's band (or the least width in pixels, at
- // up to 1.5x the footprint: the gradient's metres per pixel never exceed sqrt 2 of it) times 1 + its wash, plus a
- // pixel for the filter. A pixel farther than that from every edge of its hex is in no band (the distance to an edge
- // segment is never less than to its line), so most pixels fetch no texel at all (review: 7 fetches on every land
- // pixel cost 3.3 ms at gameplay03).
- float footprint = max(length(px), length(py));
- float washMul = 1.0 + max(max(_ScBorderShape1.z, _ScBorderShape2.z), _ScBorderShape3.z);
- float reach = max(max(max(_ScBorderShape1.x, _ScBorderShape2.x), _ScBorderShape3.x), 1.5 * _ScBorders.x * footprint) * washMul + 1.5 * footprint;
- reach = _ScBorders.z > 0.5 ? 1e9 : reach;
- float edge = inradius - max(abs(v.x), max(abs(0.5 * v.x + 0.8660254 * v.y), abs(0.5 * v.x - 0.8660254 * v.y)));
- float4 own = edge < reach && water < 1.0 ? ScRegionAt(qr) : float4(0.0, 0.0, 0.0, 0.0);
- int edges = (int)own.z, sharedEdges = (int)own.w;
- // A hex with no border edge draws nothing (the loop below would leave cover 0), so it skips the work.
- [branch] if (own.x > 0.5 && own.y > 0.5 && edges != 0)
+ // bestPx: the distance (px) to the nearest band, measured in units of that edge's band (a shared edge draws
+ // ScSharedBand of it on each side), so where a shared and an unshared edge meet at a corner each keeps its own width.
+ float bestPx = 1e9, bestAa = 1.0, bestHalf = 1.0, bestAlong = 0.0;
+ [unroll] for (int i = 0; i < 6; i++)
+ {
+ float2 n = ScHexNormals[i];
+ // Only the edges within reach count (one, or two near a corner). Whether edge i borders another region is
+ // baked into the hex's own texel: the neighbours' six fetches here had pushed the terrain's fragment shader
+ // past a WebGL cost cliff (about 5 ms a frame at gameplay03, borders on or off: issue #195).
+ if (inradius - dot(v, n) >= reach) continue;
+ if (((edges >> i) & 1) != 0)
+ {
+ // Distance to the edge segment (corners rounded, so two border edges join without a notch), in pixels
+ // along the direction it grows (Task 8's anisotropic filter: metres per pixel across the line).
+ float2 t = float2(-n.y, n.x);
+ float2 closest = n * inradius + t * clamp(dot(v, t), -0.5 * size, 0.5 * size);
+ float2 e = v - closest;
+ float d = length(e);
+ float2 g = d > 1e-3 ? e / d : -n;
+ float aa = max(length(float2(dot(px, g), dot(py, g))), 1e-3);
+ float share = ((sharedEdges >> i) & 1) != 0 ? ScSharedBand : 1.0;
+ if (d / aa / share < bestPx / bestHalf) { bestPx = d / aa; bestAa = aa; bestHalf = share; bestAlong = dot(p, t); }
+ }
+ }
+ bool primary = own.y < 1.5, neutral = own.y > 2.5;
+ float4 colour = primary ? _ScBorderColour1 : (neutral ? _ScBorderColour3 : _ScBorderColour2);
+ float4 light = primary ? _ScBorderLight1 : (neutral ? _ScBorderLight3 : _ScBorderLight2);
+ float4 shape = primary ? _ScBorderShape1 : (neutral ? _ScBorderShape3 : _ScBorderShape2);
+ // The band is shape.x metres wide (it grows towards the camera, like the promo's), never thinner than the least
+ // width, and the band plus its wash never wider than _ScBorders.y of the inradius (far zooms: a hex stays a hex).
+ float widest = _ScBorders.y * inradius / bestAa;
+ float bandPx = min(max(shape.x / bestAa, _ScBorders.x), widest / (1.0 + shape.z));
+ // Far off (a band under about 4 px: the overview), the light stripe would read as a white line, so it turns
+ // into the colour and the wash fades: a far band is a thin line of the region's colour.
+ float near = smoothstep(2.5, 4.5, bandPx);
+ // A shared edge: this side draws ScSharedBand of the band (and of the wash), the neighbour as much again.
+ bandPx *= bestHalf;
+ float washPx = bandPx * shape.z;
+ // Box-filtered stripes: the colour from the edge to shape.y of the band, the light stripe to its end.
+ float cColour = saturate(shape.y * bandPx - bestPx + 0.5);
+ float cBand = saturate(bandPx - bestPx + 0.5);
+ // max(): a style with no wash (shape.z 0) must not make smoothstep divide by zero (review M3).
+ float wash = near * shape.w * (1.0 - smoothstep(bandPx, bandPx + max(washPx, 1e-3), bestPx)) * (1.0 - cBand);
+ float3 stripe = lerp(lerp(colour.rgb, light.rgb, near), colour.rgb, cBand > 0.0 ? cColour / cBand : 0.0);
+ float cover = saturate(cBand + wash);
+ float3 c = cBand > 0.0 || wash > 0.0 ? (stripe * cBand + colour.rgb * wash) / max(cover, 1e-4) : colour.rgb;
+ float a = cover * (1.0 - water);
+ if (neutral)
+ {
+ // box-filtered dash: the share of this pixel's footprint along the edge that falls on a drawn dash
+ float ph = frac(bestAlong / ScLegacyDashM), w = max(footprint / ScLegacyDashM, 1e-4);
+ float on = saturate((ScLegacyDashOn - ph) / w + 0.5) * saturate(ph / w + 0.5);
+ a *= lerp(on, ScLegacyDashOn, saturate(w * 4.0 - 1.0)); // far off, where dashes are sub-pixel: their mean
+ }
+ baseColor *= 1.0 - a;
+ emission = lerp(emission, c, a);
+ }
+}
+
+// ---- The Civ-like prototype (variants A, B, C, A2, B2, C2; #196) ----
+// A band's on-screen widths (px) across an edge at aa metres a pixel: x the rim, y the colour stripe, z the light stripe,
+// w the wash, each held to its floor (_ScBorders.x, _ScBorderMin, _ScBorderRim.y) so the band keeps its weight at every
+// zoom. The wash runs to shape.z of the inradius from the edge. Rim, band and wash together never pass _ScBorders.y of the
+// inradius (a far hex is never filled by its outline): the wash gives way first, then both stripes shrink together, and
+// the rim last. MapBorders.BandWidths mirrors it.
+float4 ScBandWidths(float4 shape, float aa, float inradius)
+{
+ float widest = _ScBorders.y * inradius / aa;
+ float rim = _ScBorderRim.z > 0.0 ? min(max(_ScBorderRim.x / aa, _ScBorderRim.y), widest) : 0.0;
+ float room = widest - rim;
+ float colourPx = max(shape.x * shape.y / aa, _ScBorders.x);
+ float lightPx = max(shape.x * (1.0 - shape.y) / aa, _ScBorderMin.x);
+ float washPx = max(shape.z * inradius / aa - colourPx - lightPx, _ScBorderMin.y);
+ washPx = min(washPx, max(room - colourPx - lightPx, 0.0));
+ float k = min(1.0, room / max(colourPx + lightPx, 1e-4));
+ return float4(rim, colourPx * k, lightPx * k, washPx);
+}
+
+// How far the prototype's rim, band and wash can reach from an edge (m), for any style (ScBandWidths): the stripes' metres
+// plus their pixel floors (at up to 1.5x the footprint) and the wash's floor, or the wash's reach if farther, never past
+// the cap; plus a pixel for the filter. Only the edge loop is skipped beyond it: the tint needs every region pixel's own
+// texel (one fetch: issue #195's rule still holds).
+float ScCivReach(float footprint, float inradius)
+{
+ float fp15 = 1.5 * footprint;
+ float bandMaxM = max(max(_ScBorderShape1.x, _ScBorderShape2.x), _ScBorderShape3.x);
+ float washShare = max(max(_ScBorderShape1.z, _ScBorderShape2.z), _ScBorderShape3.z);
+ float floorsPx = _ScBorders.x + _ScBorderMin.x + _ScBorderMin.y;
+ float rimM = _ScBorderRim.z > 0.0 ? max(_ScBorderRim.x, _ScBorderRim.y * fp15) : 0.0;
+ return min(_ScBorders.y * inradius, rimM + max(washShare * inradius, bandMaxM + floorsPx * fp15)) + fp15;
+}
+
+void ScBorderCiv(float4 own, float2 v, float2 p, float2 px, float2 py, float size, float inradius, float edge, float reach,
+ float footprint, float water, inout float3 baseColor, inout float3 emission)
+{
+ int edges = (int)own.z, sharedEdges = (int)own.w;
+ [branch] if (own.x > 0.5 && own.y > 0.5)
+ {
+ bool primary = own.y < 1.5, neutral = own.y > 2.5;
+ float4 colour = primary ? _ScBorderColour1 : (neutral ? _ScBorderColour3 : _ScBorderColour2);
+ float4 light = primary ? _ScBorderLight1 : (neutral ? _ScBorderLight3 : _ScBorderLight2);
+ float4 shape = primary ? _ScBorderShape1 : (neutral ? _ScBorderShape3 : _ScBorderShape2);
+ // The territory tint: _ScBorderTint.x of the region's colour while a hex is large on screen, rising to .y as it
+ // shrinks (the overview reads as coloured territory with a firm edge, not a hairline).
+ float tint = lerp(_ScBorderTint.x, _ScBorderTint.y,
+ saturate((_ScBorderTint.z - inradius / footprint) / max(_ScBorderTint.z - _ScBorderTint.w, 1e-3)));
+ float bandA = 0.0, washA = 0.0;
+ float3 stripe = colour.rgb;
+ // A hex with no border edge, or a pixel beyond every band's reach, gets the tint alone.
+ [branch] if (edges != 0 && edge < reach)
{
// bestPx: the distance (px) to the nearest band, measured in units of that edge's band (a shared edge draws
- // ScSharedBand of it on each side), so where a shared and an unshared edge meet at a corner each keeps its own width.
- float bestPx = 1e9, bestAa = 1.0, bestHalf = 1.0, bestAlong = 0.0;
+ // ScSharedBand of it on each side), so where a shared and an unshared edge meet at a corner each keeps its own
+ // width. Only an edge whose rim, band or wash reaches the pixel competes: under the camera's tilt an edge's pixels
+ // can be wider than another's, so otherwise a farther edge with nothing to draw here could win the pixel, and the
+ // early-out would not be exact (TheEarlyOutIsExact).
+ float bestPx = 1e9, bestHalf = 1.0, bestAlong = 0.0;
+ float4 bestW = float4(0.0, 0.0, 0.0, 0.0);
[unroll] for (int i = 0; i < 6; i++)
{
float2 n = ScHexNormals[i];
- // Only the edges within reach count (one, or two near a corner). Whether edge i borders another region is
- // baked into the hex's own texel: the neighbours' six fetches here had pushed the terrain's fragment shader
- // past a WebGL cost cliff (about 5 ms a frame at gameplay03, borders on or off: issue #195).
if (inradius - dot(v, n) >= reach) continue;
if (((edges >> i) & 1) != 0)
{
- // Distance to the edge segment (corners rounded, so two border edges join without a notch), in pixels
- // along the direction it grows (Task 8's anisotropic filter: metres per pixel across the line).
+ // Distance to the edge segment (corners rounded), in pixels across the edge (Task 8's anisotropic
+ // filter: metres per pixel along the direction it grows, so the pixel floors hold under the tilt).
float2 t = float2(-n.y, n.x);
float2 closest = n * inradius + t * clamp(dot(v, t), -0.5 * size, 0.5 * size);
float2 e = v - closest;
@@ -107,42 +216,72 @@ void ScBorderApply(float2 mapM, float water, inout float3 baseColor, inout float
float2 g = d > 1e-3 ? e / d : -n;
float aa = max(length(float2(dot(px, g), dot(py, g))), 1e-3);
float share = ((sharedEdges >> i) & 1) != 0 ? ScSharedBand : 1.0;
- if (d / aa / share < bestPx / bestHalf) { bestPx = d / aa; bestAa = aa; bestHalf = share; bestAlong = dot(p, t); }
+ // A shared edge draws ScSharedBand of the band and wash each side, and no rim (one band, no seam).
+ float4 w = ScBandWidths(shape, aa, inradius) * float4(share < 1.0 ? 0.0 : 1.0, share, share, share);
+ if (d / aa < w.x + w.y + w.z + w.w + 0.5 && d / aa / share < bestPx / bestHalf)
+ {
+ // The dash phase runs along the edge in one direction for both hexes (edges i and i + 3 are
+ // opposite: their tangents are flipped back), so the two halves of a shared neutral edge line up.
+ bestPx = d / aa; bestHalf = share; bestAlong = dot(p, i < 3 ? t : -t); bestW = w;
+ }
}
}
- bool primary = own.y < 1.5, neutral = own.y > 2.5;
- float4 colour = primary ? _ScBorderColour1 : (neutral ? _ScBorderColour3 : _ScBorderColour2);
- float4 light = primary ? _ScBorderLight1 : (neutral ? _ScBorderLight3 : _ScBorderLight2);
- float4 shape = primary ? _ScBorderShape1 : (neutral ? _ScBorderShape3 : _ScBorderShape2);
- // The band is shape.x metres wide (it grows towards the camera, like the promo's), never thinner than the least
- // width, and the band plus its wash never wider than _ScBorders.y of the inradius (far zooms: a hex stays a hex).
- float widest = _ScBorders.y * inradius / bestAa;
- float bandPx = min(max(shape.x / bestAa, _ScBorders.x), widest / (1.0 + shape.z));
- // Far off (a band under about 4 px: the overview), the light stripe would read as a white line, so it turns
- // into the colour and the wash fades: a far band is a thin line of the region's colour.
- float near = smoothstep(2.5, 4.5, bandPx);
- // A shared edge: this side draws ScSharedBand of the band (and of the wash), the neighbour as much again.
- bandPx *= bestHalf;
- float washPx = bandPx * shape.z;
- // Box-filtered stripes: the colour from the edge to shape.y of the band, the light stripe to its end.
- float cColour = saturate(shape.y * bandPx - bestPx + 0.5);
- float cBand = saturate(bandPx - bestPx + 0.5);
- // max(): a style with no wash (shape.z 0) must not make smoothstep divide by zero (review M3).
- float wash = near * shape.w * (1.0 - smoothstep(bandPx, bandPx + max(washPx, 1e-3), bestPx)) * (1.0 - cBand);
- float3 stripe = lerp(lerp(colour.rgb, light.rgb, near), colour.rgb, cBand > 0.0 ? cColour / cBand : 0.0);
- float cover = saturate(cBand + wash);
- float3 c = cBand > 0.0 || wash > 0.0 ? (stripe * cBand + colour.rgb * wash) / max(cover, 1e-4) : colour.rgb;
- float a = cover * (1.0 - water);
+ float rimEnd = bestW.x, colourEnd = rimEnd + bestW.y, bandEnd = colourEnd + bestW.z;
+ // Box-filtered, from the edge in: the rim, the colour stripe, the light stripe (coverage up to each end).
+ float cRim = rimEnd > 0.0 ? saturate(rimEnd - bestPx + 0.5) : 0.0;
+ float cColour = saturate(colourEnd - bestPx + 0.5), cBand = saturate(bandEnd - bestPx + 0.5);
+ float rimA = cRim * _ScBorderRim.z;
+ bandA = cBand - cRim + rimA;
+ stripe = bandA > 0.0 ? (colour.rgb * (cColour - cRim) + light.rgb * (cBand - cColour) + colour.rgb * _ScBorderRim.w * rimA) / bandA : colour.rgb;
+ // How far through the wash (0 at the band, 1 at its reach; max(): no division by zero for a style with no
+ // wash, review M3). It falls as a smoothstep, or (the stronger tier) as x^2, holding its strength farther in.
+ float x = saturate((bestPx - bandEnd) / max(bestW.w, 1e-3));
+ washA = shape.w * (1.0 - lerp(x * x * (3.0 - 2.0 * x), x * x, _ScBorderMin.z));
if (neutral)
{
- // box-filtered dash: the share of this pixel's footprint along the edge that falls on a drawn dash
- float ph = frac(bestAlong / ScNeutralDashM), w = max(footprint / ScNeutralDashM, 1e-4);
- float on = saturate((ScNeutralDashOn - ph) / w + 0.5) * saturate(ph / w + 0.5);
- a *= lerp(on, ScNeutralDashOn, saturate(w * 4.0 - 1.0)); // far off, where dashes are sub-pixel: their mean
+ // box-filtered dash: the share of this pixel's footprint along the edge that falls on a drawn dash. The
+ // period doubles from _ScBorderDash.x as the camera pulls out, so a drawn dash is never under
+ // _ScBorderDash.z px (doubling keeps every other dash in place, so zooming does not make them swim).
+ float period = _ScBorderDash.x * exp2(max(0.0, ceil(log2(max(_ScBorderDash.z / _ScBorderDash.y * footprint / _ScBorderDash.x, 1e-6)))));
+ float ph = frac(bestAlong / period), fw = max(footprint / period, 1e-4);
+ float on = saturate((_ScBorderDash.y - ph) / fw + 0.5) * saturate(ph / fw + 0.5);
+ bandA *= on; washA *= on;
}
- baseColor *= 1.0 - a;
- emission = lerp(emission, c, a);
}
+ // The wash and the tint are the region's colour under the band: the stronger of the two.
+ float fill = max(washA, tint) * (1.0 - bandA);
+ float cover = bandA + fill;
+ float3 c = cover > 0.0 ? (stripe * bandA + colour.rgb * fill) / cover : colour.rgb;
+ float a = cover * (1.0 - water);
+ baseColor *= 1.0 - a;
+ emission = lerp(emission, c, a);
+ }
+}
+
+// Adds the borders to the terrain's outputs (unlit: the stripes, wash and tint replace BaseColor and go out as Emission,
+// so they read the same in sun and shadow, as the promo's glowing lines do). mapM: metres east and north of the map's
+// south-west corner; water: ScWater's 0 (land) .. 1 (water): bands stay on land, so a boundary that reaches the coast stops
+// at the shore instead of running up to 4 km out to its hex's edge (review M7). _ScBorderMin.w picks main's drawing
+// (legacy, the default) or the prototype's. Call it in uniform control flow (outside any [branch]): it takes derivatives.
+void ScBorderApply(float2 mapM, float water, inout float3 baseColor, inout float3 emission)
+{
+ float2 p = float2(mapM.x, _ScMap.y - mapM.y);
+ float2 px = ddx(p), py = ddy(p);
+ [branch] if (_ScBorders.w > 0.5)
+ {
+ float size = max(_ScMapOrigin.w, 1.0), inradius = 0.8660254 * size; // max(): never a zero hex (5 km here)
+ float2 v;
+ float2 qr = ScHexAxial(p, size, v);
+ bool legacy = _ScBorderMin.w > 0.5;
+ float footprint = legacy ? max(length(px), length(py)) : max(max(length(px), length(py)), 1e-4);
+ float reach = legacy ? ScLegacyReach(footprint) : ScCivReach(footprint, inradius);
+ reach = _ScBorders.z > 0.5 ? 1e9 : reach;
+ float edge = inradius - max(abs(v.x), max(abs(0.5 * v.x + 0.8660254 * v.y), abs(0.5 * v.x - 0.8660254 * v.y)));
+ // One texel a pixel at most (issue #195): main's drawing fetches only within reach; the prototype's tint needs it on
+ // every region pixel.
+ float4 own = (!legacy || edge < reach) && water < 1.0 ? ScRegionAt(qr) : float4(0.0, 0.0, 0.0, 0.0);
+ [branch] if (legacy) ScBorderLegacy(own, v, p, px, py, size, inradius, reach, footprint, water, baseColor, emission);
+ else ScBorderCiv(own, v, p, px, py, size, inradius, edge, reach, footprint, water, baseColor, emission);
}
}
diff --git a/unity/Assets/Tests/EditMode/BorderCivTests.cs b/unity/Assets/Tests/EditMode/BorderCivTests.cs
new file mode 100644
index 000000000..327bf275f
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/BorderCivTests.cs
@@ -0,0 +1,481 @@
+#nullable enable
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+
+/// <summary>The Civ-like border prototype (#196, owner 2026-10-26): its variants' rules (MapBorders.BandWidths, TintAlpha,
+/// the neutral dashes), which StatecraftBorders.hlsl mirrors, rendered checks of each variant, and the switch. A2 is the
+/// default (owner ruling 2026-10-27); BorderTests, GradeTests and SubdistrictTests pin Legacy (main's earlier look) and run
+/// main's assertions unchanged on it.</summary>
+public class BorderCivTests
+{
+ const float Inradius = 4330.127f; // 5 km hexes
+ static readonly float[] MetresPerPx = { 2f, 12f, 35f, 87f, 146f, 300f, 600f, 2000f };
+ static readonly BorderVariant[] Prototypes = { BorderVariant.A, BorderVariant.B, BorderVariant.C, BorderVariant.A2, BorderVariant.B2, BorderVariant.C2 };
+ static MapBorders.Style[] Styles => new[] { MapBorders.Primary, MapBorders.Secondary, MapBorders.Neutral, MapBorders.PrimaryStrongBlue };
+
+ [TearDown]
+ public void Reset()
+ {
+ MapBorders.Variant = MapBorders.DefaultVariant;
+ MapBorders.NoEarlyOut = false;
+ MapShaderGlobals.PinWaterTime(null);
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear();
+ }
+
+ static float Median(IEnumerable<float> v) { var s = v.OrderBy(x => x).ToList(); return s[s.Count / 2]; }
+
+ /// <summary>The variant's Primary style and colour floor, as SetStyles installs them.</summary>
+ static (MapBorders.Style style, float minColour) PrimaryOf(BorderVariant v) =>
+ (MapBorders.StrongBlue(v) ? MapBorders.PrimaryStrongBlue : MapBorders.Primary, MapBorders.Strong(v) ? MapBorders.StrongMinColourPx : MapBorders.MinColourPx);
+
+ // ---- The rules (MapBorders' mirror of the shader) ----
+
+ /// <summary>Minimum widths: colour stripe >= 3 px (6 on the stronger tier), light >= 1 px, wash >= 12 px at every zoom,
+ /// unless rim, band and wash would pass half the inradius: then the wash gives way first, then the stripes, the rim
+ /// last. Up close the world widths rule (the band grows towards the camera).</summary>
+ [Test]
+ public void BandWidthsKeepTheirPixelFloorsUnderTheCap()
+ {
+ foreach (var minColour in new[] { MapBorders.MinColourPx, MapBorders.StrongMinColourPx })
+ foreach (var rim in new[] { false, true })
+ foreach (var s in Styles)
+ foreach (var mpp in MetresPerPx)
+ {
+ var w = MapBorders.BandWidths(s, mpp, Inradius, rim, minColour);
+ float widest = MapBorders.MaxShareOfInradius * Inradius / mpp, room = widest - w.rim;
+ string at = $"{mpp} m/px, band {s.BandM} m, rim {rim}, floor {minColour}";
+ Assert.LessOrEqual(w.rim + w.colour + w.light + w.wash, widest + 1e-3f, $"{at}: never past the cap, rim included");
+ if (rim) Assert.AreEqual(Mathf.Min(Mathf.Max(MapBorders.RimM / mpp, MapBorders.RimMinPx), widest), w.rim, 1e-4f, at);
+ else Assert.AreEqual(0f, w.rim, at);
+ if (minColour + MapBorders.MinLightPx + MapBorders.MinWashPx <= room)
+ {
+ Assert.GreaterOrEqual(w.colour, minColour - 1e-4f, at);
+ Assert.GreaterOrEqual(w.light, MapBorders.MinLightPx - 1e-4f, at);
+ Assert.GreaterOrEqual(w.wash, MapBorders.MinWashPx - 1e-4f, at);
+ }
+ else if (minColour + MapBorders.MinLightPx <= room)
+ {
+ Assert.GreaterOrEqual(w.colour, minColour - 1e-4f, $"{at}: the stripes keep their floors");
+ Assert.AreEqual(room - w.colour - w.light, w.wash, 1e-3f, $"{at}: the wash gives way first");
+ }
+ else Assert.AreEqual(0f, w.wash, $"{at}: the wash goes before the stripes shrink");
+ }
+ var close = MapBorders.BandWidths(MapBorders.Primary, 2f, Inradius, rim: false);
+ Assert.AreEqual(230f * 0.5f / 2f, close.colour, 1e-3f, "up close the world width rules");
+ Assert.AreEqual(MapBorders.WashReachShare * Inradius / 2f, close.colour + close.light + close.wash, 1e-2f, "the wash reaches a quarter of the inradius");
+ Assert.AreEqual(MapBorders.RimMinPx, MapBorders.BandWidths(MapBorders.Primary, 300f, Inradius, rim: true).rim, "the rim keeps 1 px");
+ Assert.AreEqual(MapBorders.RimM / 5f, MapBorders.BandWidths(MapBorders.Primary, 5f, Inradius, rim: true).rim, 1e-4f, "and 50 m up close");
+ }
+
+ /// <summary>Equal wash: both sides (and variant C's blue) wash alike, every style reaches the same quarter of the inradius.</summary>
+ [Test]
+ public void BothSidesWashAlike()
+ {
+ Assert.AreEqual(MapBorders.Primary.WashStrength, MapBorders.Secondary.WashStrength);
+ Assert.AreEqual(MapBorders.Primary.WashStrength, MapBorders.PrimaryStrongBlue.WashStrength);
+ Assert.That(MapBorders.Primary.WashStrength, Is.InRange(0.35f, 0.40f));
+ foreach (var s in Styles) Assert.AreEqual(MapBorders.WashReachShare, s.WashReach);
+ Assert.AreEqual(0.25f, MapBorders.WashReachShare);
+ }
+
+ /// <summary>The territory tint: 0.08 (0.12 on the stronger tier) while a hex is large on screen, rising to 0.25 at the
+ /// overview.</summary>
+ [Test]
+ public void TheTintRisesAsTheHexShrinks()
+ {
+ Assert.AreEqual(0.08f, MapBorders.TintAlpha(400f), 1e-6f);
+ Assert.AreEqual(0.08f, MapBorders.TintAlpha(120f), 1e-6f);
+ Assert.AreEqual(0.165f, MapBorders.TintAlpha(80f), 1e-6f);
+ Assert.AreEqual(0.25f, MapBorders.TintAlpha(40f), 1e-6f);
+ Assert.AreEqual(0.25f, MapBorders.TintAlpha(8f), 1e-6f);
+ for (float px = 8f; px < 400f; px += 1f) Assert.LessOrEqual(MapBorders.TintAlpha(px + 1f), MapBorders.TintAlpha(px));
+ Assert.AreEqual(0.12f, MapBorders.TintAlpha(400f, MapBorders.StrongTintNear), 1e-6f, "the stronger tier up close");
+ Assert.AreEqual(0.25f, MapBorders.TintAlpha(40f, MapBorders.StrongTintNear), 1e-6f);
+ }
+
+ /// <summary>The neutral dashes stay at least 8 px on screen: their period doubles from 2 km as the camera pulls out
+ /// (doubling keeps every other dash in place).</summary>
+ [Test]
+ public void NeutralDashesStayAtLeastEightPixels()
+ {
+ Assert.AreEqual(MapBorders.NeutralDashM, MapBorders.NeutralDashPeriodM(10f), "up close: the 2 km period");
+ for (float mpp = 1f; mpp < 2000f; mpp *= 1.13f)
+ {
+ float period = MapBorders.NeutralDashPeriodM(mpp);
+ Assert.GreaterOrEqual(period * MapBorders.NeutralDashOn / mpp, MapBorders.NeutralDashMinPx - 1e-3f, $"{mpp} m/px");
+ float doublings = Mathf.Log(period / MapBorders.NeutralDashM, 2f);
+ Assert.AreEqual(Mathf.Round(doublings), doublings, 1e-4f, $"{mpp} m/px: a power-of-two multiple of 2 km");
+ }
+ }
+
+ /// <summary>The owner's pick, 27 Oct 2026 ("A2: stronger bands (Recommended)"): with no flag, in the WebGL URL or on the
+ /// command line, the map draws A2.</summary>
+ [Test]
+ public void WithNoFlagTheMapDrawsA2()
+ {
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested("https://x.invalid/", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested("https://x.invalid/?golden", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested(null, new[] { "Statecraft" }, webgl: false));
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested("", new[] { "Unity", "-batchmode" }, webgl: false));
+ }
+
+ /// <summary>A bad selection draws the default (A2, WithNoFlagTheMapDrawsA2); "legacy" draws main's earlier
+ /// look; a URL parameter or a command-line flag picks a variant, and the switch reaches the shader. Every transition
+ /// installs its whole set of globals (B2 to C2 drops the rim, C2 to A drops the blue, back to Legacy restores main's).</summary>
+ [Test]
+ public void TheVariantsSwitchAndLegacyStaysSelectable()
+ {
+ Assert.AreEqual(BorderVariant.A2, MapBorders.DefaultVariant);
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested("https://x.invalid/?bordervariant=bx", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested("https://x.invalid/?bordervariant=legacyx", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested(null, new[] { "Statecraft", "-bordervariant", "zz" }, webgl: false));
+ Assert.AreEqual(BorderVariant.Legacy, MapBorders.VariantRequested("https://x.invalid/?bordervariant=legacy", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.Legacy, MapBorders.VariantRequested("https://x.invalid/?golden&bordervariant=Legacy#x", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.Legacy, MapBorders.VariantRequested(null, new[] { "Statecraft", "-bordervariant", "legacy" }, webgl: false));
+ Assert.AreEqual(BorderVariant.A, MapBorders.VariantRequested("https://x.invalid/?bordervariant=a", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.B, MapBorders.VariantRequested("https://x.invalid/?golden&bordervariant=b", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.C, MapBorders.VariantRequested("https://x.invalid/?bordervariant=C#x", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.A2, MapBorders.VariantRequested("https://x.invalid/?bordervariant=a2", new string[0], webgl: true));
+ Assert.AreEqual(BorderVariant.B, MapBorders.VariantRequested(null, new[] { "Statecraft", "-bordervariant", "b" }, webgl: false));
+ Assert.AreEqual(BorderVariant.C2, MapBorders.VariantRequested(null, new[] { "Statecraft", "-bordervariant", "C2" }, webgl: false));
+
+ BorderTests.Open();
+ Vector4 G(string name) => Shader.GetGlobalVector(name);
+ var blue = MapBorders.Primary.Colour.linear; var strong = MapBorders.PrimaryStrongBlue.Colour.linear;
+ void Expect(BorderVariant v)
+ {
+ MapBorders.Variant = v;
+ string at = v.ToString();
+ if (v == BorderVariant.Legacy)
+ {
+ Assert.AreEqual(1f, G("_ScBorderMin").w, at);
+ Assert.AreEqual(MapBorders.LegacyMinBandPx, G("_ScBorders").x, at);
+ Assert.AreEqual(new Vector4(230f, 0.5f, 0.9f, 0.40f), G("_ScBorderShape1"), at);
+ Assert.AreEqual(new Vector4(200f, 0.6f, 1.0f, 0.18f), G("_ScBorderShape2"), at);
+ Assert.AreEqual(new Vector4(200f, 0.6f, 0.8f, 0.14f), G("_ScBorderShape3"), at);
+ Assert.AreEqual(0f, G("_ScBorderRim").z, at);
+ Assert.AreEqual(new Vector4(blue.r, blue.g, blue.b, 1f), G("_ScBorderColour1"), at);
+ return;
+ }
+ Assert.AreEqual(0f, G("_ScBorderMin").w, at);
+ Assert.AreEqual(MapBorders.Strong(v) ? MapBorders.StrongMinColourPx : MapBorders.MinColourPx, G("_ScBorders").x, at);
+ float wash = MapBorders.Strong(v) ? MapBorders.StrongWashStrength : MapBorders.SideWashStrength;
+ Assert.AreEqual(wash, G("_ScBorderShape1").w, at); Assert.AreEqual(wash, G("_ScBorderShape2").w, at);
+ Assert.AreEqual(MapBorders.Strong(v) ? 1f : 0f, G("_ScBorderMin").z, at);
+ Assert.AreEqual(MapBorders.Strong(v) ? MapBorders.StrongTintNear : MapBorders.TintNear, G("_ScBorderTint").x, at);
+ Assert.AreEqual(MapBorders.HasRim(v) ? MapBorders.RimOpacity : 0f, G("_ScBorderRim").z, at);
+ var c = MapBorders.StrongBlue(v) ? strong : blue;
+ Assert.AreEqual(new Vector4(c.r, c.g, c.b, 1f), G("_ScBorderColour1"), at);
+ }
+ foreach (var v in new[] { BorderVariant.Legacy, BorderVariant.A, BorderVariant.B, BorderVariant.C, BorderVariant.A2, BorderVariant.B2,
+ BorderVariant.C2, BorderVariant.B2, BorderVariant.A, BorderVariant.C, BorderVariant.Legacy })
+ Expect(v);
+ }
+
+ // ---- Rendered: the shader against its mirror, for every variant ----
+
+ /// <summary>Each prototype variant's rendered Primary band (colour and light stripes) is the width
+ /// MapBorders.BandWidths predicts for the metres per pixel measured along the walk, at gameplay03 and at 150 km (where
+ /// the pixel floors bind): no narrower than 0.5 px under it, and no more than 2 px over it (the band's two box-filtered
+ /// end pixels count whole when partly covered; measured +1.3 to +1.7 px). A shader that drifted from its C# mirror
+ /// fails here.</summary>
+ [UnityTest]
+ public IEnumerator EveryVariantDrawsTheWidthsItsMirrorPredicts()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ RenderSample.TiltShift(false);
+ BorderProof.Show(map);
+ var (inner, outer) = BorderTests.ProofEdge(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, "coastal_plain");
+ foreach (var distance in new[] { PromoPose.Gameplay03.Distance, 150000f })
+ {
+ BorderTests.LookAtEdge(map, rig, inner);
+ rig.Distance = distance; rig.Apply();
+ foreach (var v in Prototypes)
+ {
+ MapBorders.Variant = v;
+ var (style, minColour) = PrimaryOf(v);
+ var walks = BorderTests.WalkEdge(map, cam, inner, outer, 9, 1920, 1080);
+ // metres per pixel along each walk, from its first and last distinct pixel
+ float mpp = Median(walks.Select(w => (w.SignedM[w.SignedM.Count - 1] - w.SignedM[0]) / Vector2.Distance(w.Px[w.Px.Count - 1], w.Px[0])));
+ var want = MapBorders.BandWidths(style, mpp, Inradius, MapBorders.HasRim(v), minColour);
+ float gain = MapBorders.StrongBlue(v) ? 0.6f : 0.45f; // above each blue's wash
+ float got = Median(walks.Select(w => BorderTests.Read(w, -1, BorderTests.Blueness, gain).WidthPx));
+ TestContext.WriteLine($"{v} at {distance / 1000f:0} km ({mpp:0.0} m/px): band {got:0.0} px, mirror {want.colour + want.light:0.0} px (colour {want.colour:0.0}, light {want.light:0.0})");
+ Assert.That(got - (want.colour + want.light), Is.InRange(-0.5f, 2f), $"{v} at {distance / 1000f:0} km");
+ }
+ }
+ }
+
+ /// <summary>Review M6 for every prototype variant: the early-out is exact (BorderTests.TheEarlyOutIsExact, run with
+ /// each variant drawn; that test itself runs on Legacy).</summary>
+ [UnityTest]
+ public IEnumerator TheEarlyOutIsExactInEveryVariant()
+ {
+ foreach (var v in Prototypes)
+ {
+ TestContext.WriteLine($"variant {v}");
+ MapBorders.Variant = v;
+ var run = new BorderTests().TheEarlyOutIsExact(); // stepped here: its frames are this test's
+ while (run.MoveNext()) yield return run.Current;
+ }
+ }
+
+ /// <summary>The colour-blind checks (GradeTests, unchanged bounds) for every prototype variant; the neutral stripe is
+ /// read above the variants' grey wash and tint (0.10, Legacy's 0.02). Each variant asserts its own dash gaps and walks.</summary>
+ [UnityTest]
+ public IEnumerator ColourBlindPlayersTellTheStylesApartInEveryVariant()
+ {
+ foreach (var v in Prototypes)
+ {
+ TestContext.WriteLine($"variant {v}");
+ MapBorders.Variant = v;
+ var styles = new GradeTests().ColourBlindPlayersTellTheBorderStylesApart(); // stepped here: its frames are this test's
+ while (styles.MoveNext()) yield return styles.Current;
+ MapBorders.Variant = v;
+ var neutral = GradeTests.NeutralBandApart(0.10f);
+ while (neutral.MoveNext()) yield return neutral.Current;
+ }
+ }
+
+ // ---- Rendered: the new rules (A; red on main where noted, measured on c7851de3 before Legacy kept main's look) ----
+
+ /// <summary>Far off a band holds its weight instead of fading to a hairline. At the overview's distance on the proof's
+ /// coastal-plain edge by gameplay03, the Primary side still shows its light stripe and its band, wash and tint change
+ /// several pixels within 1.5 km of the edge (main: 3 px changed, light lift 0.000).</summary>
+ [UnityTest]
+ public IEnumerator AtTheOverviewABandKeepsItsLightStripeAndWash()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ MapBorders.Variant = BorderVariant.A;
+ RenderSample.TiltShift(false);
+ BorderProof.Show(map);
+ var (inner, outer) = BorderTests.ProofEdge(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, "coastal_plain");
+ BorderTests.LookAtEdge(map, rig, inner);
+ rig.Distance = PromoPose.Diorama02.Distance; rig.Apply();
+ var changed = new List<float>(); var lift = new List<float>();
+ foreach (var w in BorderTests.WalkEdge(map, cam, inner, outer, 9, 1920, 1080))
+ {
+ int n = 0; float l = float.MinValue;
+ for (int k = 0; k < w.On.Count; k++)
+ {
+ if (w.SignedM[k] >= 0f) continue;
+ if (RenderSample.DeltaE(w.On[k], w.Off[k]) >= 3f) n++;
+ l = Mathf.Max(l, RenderSample.Luma(w.On[k]) - RenderSample.Luma(w.Off[k]));
+ }
+ changed.Add(n); lift.Add(l);
+ }
+ float c = Median(changed), li = Median(lift);
+ TestContext.WriteLine($"overview distance, edge {inner}-{outer}: median {c:0} primary-side pixels changed within 1.5 km, light stripe lift {li:0.000}");
+ Assert.GreaterOrEqual(c, 7f, "far off, band, wash and tint keep their weight");
+ Assert.GreaterOrEqual(li, 0.05f, "far off, the light stripe still shows");
+ }
+
+ /// <summary>Both sides' territory is washed alike: at gameplay03, 500-900 m inside each side of a primary-secondary
+ /// edge, the wash's opacity (each pixel's step from the land towards its side's stripe colour) is within 25% on the two
+ /// sides (main: nothing that far in; the Secondary's wash was 0.18 against the Primary's 0.40).</summary>
+ [UnityTest]
+ public IEnumerator BothSidesWashTheirTerritoryAlike()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ MapBorders.Variant = BorderVariant.A;
+ RenderSample.TiltShift(false);
+ BorderProof.Show(map);
+ var (inner, outer) = BorderTests.ProofEdge(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, "coastal_plain");
+ BorderTests.LookAtEdge(map, rig, inner);
+ var p = new List<float>(); var s = new List<float>();
+ foreach (var w in BorderTests.WalkEdge(map, cam, inner, outer, 9, 1920, 1080))
+ {
+ var pc = BorderTests.Read(w, -1, BorderTests.Blueness, 0.45f).Stripe; var sc = BorderTests.Read(w, +1, BorderTests.Redness, 0.2f).Stripe;
+ for (int k = 0; k < w.On.Count; k++)
+ {
+ float m = Mathf.Abs(w.SignedM[k]);
+ if (m < 500f || m > 900f) continue;
+ // opacity: the projection of on - off onto stripe - off
+ var colour = w.SignedM[k] < 0f ? pc : sc;
+ Vector3 d = new Vector3(w.On[k].r - w.Off[k].r, w.On[k].g - w.Off[k].g, w.On[k].b - w.Off[k].b);
+ Vector3 to = new Vector3(colour.r - w.Off[k].r, colour.g - w.Off[k].g, colour.b - w.Off[k].b);
+ if (to.sqrMagnitude < 1e-3f) continue;
+ (w.SignedM[k] < 0f ? p : s).Add(Vector3.Dot(d, to) / to.sqrMagnitude);
+ }
+ }
+ float pm = Median(p), sm = Median(s);
+ TestContext.WriteLine($"gameplay03 500-900 m in: wash opacity primary {pm:0.000} ({p.Count} px), secondary {sm:0.000} ({s.Count} px)");
+ Assert.GreaterOrEqual(Mathf.Min(pm, sm), 0.05f, "both sides washed 500-900 m in");
+ Assert.GreaterOrEqual(Mathf.Min(pm, sm) / Mathf.Max(pm, sm), 0.75f, "the two sides' wash within 25%");
+ }
+
+ /// <summary>The pixel floors: at 150 km, where the Primary band's 230 m is under 3 px, its colour and light stripes
+ /// together still measure at least 3.5 px (main: 3.0 px, one 2 px floor for the whole band).</summary>
+ [UnityTest]
+ public IEnumerator AtMidZoomTheBandKeepsItsPixelFloors()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ MapBorders.Variant = BorderVariant.A;
+ RenderSample.TiltShift(false);
+ BorderProof.Show(map);
+ var (inner, outer) = BorderTests.ProofEdge(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, "coastal_plain");
+ BorderTests.LookAtEdge(map, rig, inner);
+ rig.Distance = 150000f; rig.Apply();
+ float pm = Median(BorderTests.WalkEdge(map, cam, inner, outer, 9, 1920, 1080).Select(w => BorderTests.Read(w, -1, BorderTests.Blueness, 0.45f).WidthPx));
+ TestContext.WriteLine($"150 km, edge {inner}-{outer}: primary band {pm:0.0} px (median)");
+ Assert.GreaterOrEqual(pm, 3.5f, "colour stripe >= 3 px plus light stripe >= 1 px");
+ }
+
+ /// <summary>At the overview (diorama02) the territory reads as tinted with a firm edge: the proof changes much of the
+ /// land, but under a light tint, and its primary pixels read blue with few near-white (the light stripe is 1 px).</summary>
+ [UnityTest]
+ public IEnumerator AtTheOverviewTerritoryReadsTintedWithAFirmEdge()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ MapBorders.Variant = BorderVariant.A;
+ RenderSample.TiltShift(false);
+ PromoPose.Diorama02.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();
+ VisualToggles.Set(MapBorders.ToggleName, false);
+ var off = RenderSample.Render(cam, 1920, 1080);
+ VisualToggles.Set(MapBorders.ToggleName, true);
+ BorderProof.Show(map);
+ var on = RenderSample.Render(cam, 1920, 1080);
+ float share = BorderTests.Changed(on, off, 0.06f), strong = BorderTests.Changed(on, off, 0.25f);
+ int changed = 0, white = 0; float gain = 0f;
+ for (int i = 0; i < on.Pixels.Length; i++)
+ {
+ Color a = on.Pixels[i], b = off.Pixels[i];
+ if (Mathf.Max(Mathf.Abs(a.r - b.r), Mathf.Max(Mathf.Abs(a.g - b.g), Mathf.Abs(a.b - b.b))) <= 0.06f || BorderTests.Blueness(a) <= BorderTests.Blueness(b)) continue;
+ changed++; gain += BorderTests.Blueness(a) - BorderTests.Blueness(b);
+ if (Mathf.Min(a.r, Mathf.Min(a.g, a.b)) > 0.80f) white++;
+ }
+ float whiteShare = white / (float)Mathf.Max(changed, 1), meanGain = gain / Mathf.Max(changed, 1);
+ TestContext.WriteLine($"diorama02: {share:P2} changed (> 0.06), {strong:P2} strongly (> 0.25); {whiteShare:P1} of bluer pixels near-white, mean blueness gain {meanGain:0.000}");
+ Assert.That(share, Is.InRange(0.15f, 0.60f), "the territory reads tinted");
+ Assert.Less(strong, 0.10f, "a light tint, not an opaque fill");
+ Assert.Less(whiteShare, 0.08f, "far bands read as the region's colour");
+ Assert.Greater(meanGain, 0.10f, "far primary territory reads blue");
+ }
+
+ /// <summary>No band along a hex in no region (the coast): with the tint, the land within 300 m of the coast edge changes
+ /// no more than the same hex 1-1.5 km in (+2 ΔE), and no sea pixel changes.</summary>
+ [UnityTest]
+ public IEnumerator NoBandRunsAlongTheCoastOnlyTheTint()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ MapBorders.Variant = BorderVariant.A;
+ RenderSample.TiltShift(false);
+ PromoPose.Gameplay03.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();
+ var layer = BorderProof.Show(map);
+ var centre = BorderProof.HexAt(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat);
+ var byHex = map.Hexes.hexes.ToDictionary(h => (h.q, h.r));
+ (int q, int r)? land = null;
+ foreach (var h in map.Hexes.hexes.OrderBy(h => BorderProof.Distance((h.q, h.r), centre)))
+ {
+ if (!h.land || !byHex.TryGetValue((h.q - 1, h.r), out var west) || west.land) continue;
+ int id = layer.RegionOf(h.q, h.r);
+ if (MapBorders.NeighbourSteps.Any(d => { int o = layer.RegionOf(h.q + d.dq, h.r + d.dr); return o != 0 && o != id; })) continue;
+ land = (h.q, h.r); break;
+ }
+ Assert.IsNotNull(land);
+ int moved = 0, sea = 0; var near = new List<float>(); var deep = new List<float>();
+ foreach (var w in BorderTests.WalkEdge(map, cam, land!.Value, (land.Value.q - 1, land.Value.r), 3, 960, 540))
+ for (int k = 0; k < w.On.Count; k++)
+ {
+ float d = RenderSample.DeltaE(w.On[k], w.Off[k]), m = w.SignedM[k];
+ if (m > 0f) { sea++; if (d >= 2f) moved++; }
+ else if (m > -300f) near.Add(d);
+ else if (m < -1000f) deep.Add(d);
+ }
+ float nm = Median(near), dm = Median(deep);
+ TestContext.WriteLine($"coast edge at {land.Value}: {moved}/{sea} sea pixels moved; land ΔE near the edge {nm:0.0}, deep in {dm:0.0}");
+ Assert.AreEqual(0, moved, "the sea is untouched");
+ Assert.LessOrEqual(nm, dm + 2f, "no band along the coast: only the tint the whole hex has");
+ }
+
+ /// <summary>A shared neutral edge's dashes line up on both sides (one dash phase per edge, not per hex).
+ /// Across the proof's blocks drawn all Neutral (every block boundary a shared neutral edge), at 11 points along an edge
+ /// the two sides within 80 m of it are both on a dash or both in a gap at least 9 times.</summary>
+ [UnityTest]
+ public IEnumerator SharedNeutralDashesLineUpAcrossTheEdge()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ MapBorders.Variant = BorderVariant.A;
+ RenderSample.TiltShift(false);
+ BorderProof.Show(map);
+ var (inner, outer) = BorderTests.ProofEdge(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, "coastal_plain");
+ MapBorders.Use(BorderTests.Blocks(map, _ => BorderStyle.Neutral));
+ BorderTests.LookAtEdge(map, rig, inner);
+ rig.Distance = 20000f; rig.Apply();
+ int agree = 0, total = 0, onDash = 0;
+ foreach (var w in BorderTests.WalkEdge(map, cam, inner, outer, 11, 1920, 1080))
+ {
+ bool Drawn(int sign) => Enumerable.Range(0, w.On.Count).Any(k => Mathf.Sign(w.SignedM[k]) == sign && Mathf.Abs(w.SignedM[k]) <= 80f
+ && RenderSample.DeltaE(w.On[k], w.Off[k]) >= 10f); // the grey stripe, well above the neutral wash and tint
+ bool a = Drawn(-1), b = Drawn(+1);
+ total++; if (a == b) agree++; if (a) onDash++;
+ }
+ TestContext.WriteLine($"shared neutral edge {inner}-{outer}: {agree}/{total} walks agree across the edge, {onDash} on a dash");
+ Assert.GreaterOrEqual(agree, 9, "the two halves' dashes line up");
+ Assert.That(onDash, Is.InRange(1, total - 1), "the walks see both dashes and gaps");
+ }
+
+ /// <summary>The stronger tier at gameplay03 (the view players live in): A2's Primary band is wider than A's (the 6 px
+ /// colour floor) and its wash reads farther in (700-1000 m: the held wash and the 0.12 tint).</summary>
+ [UnityTest]
+ public IEnumerator TheStrongerTierReadsHeavierAtGameplay03()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ RenderSample.TiltShift(false);
+ BorderProof.Show(map);
+ var (inner, outer) = BorderTests.ProofEdge(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, "coastal_plain");
+ BorderTests.LookAtEdge(map, rig, inner);
+ (float band, float wash) Measure(BorderVariant v)
+ {
+ MapBorders.Variant = v;
+ var walks = BorderTests.WalkEdge(map, cam, inner, outer, 9, 1920, 1080);
+ float band = Median(walks.Select(w => BorderTests.Read(w, -1, BorderTests.Blueness, 0.45f).WidthPx));
+ float wash = Median(walks.SelectMany(w => Enumerable.Range(0, w.On.Count).Where(k => w.SignedM[k] <= -700f && w.SignedM[k] >= -1000f)
+ .Select(k => RenderSample.DeltaE(w.On[k], w.Off[k]))));
+ return (band, wash);
+ }
+ var a = Measure(BorderVariant.A); var a2 = Measure(BorderVariant.A2);
+ TestContext.WriteLine($"gameplay03: primary band A {a.band:0.0} px, A2 {a2.band:0.0} px; wash ΔE 700-1000 m in: A {a.wash:0.0}, A2 {a2.wash:0.0}");
+ Assert.GreaterOrEqual(a2.band, a.band + 1f, "A2's band is wider");
+ Assert.Greater(a2.wash, a.wash * 1.3f, "A2's wash reads farther in");
+ }
+
+ /// <summary>Variant B: a dark rim on the edge. Close up (20 km), the darkest Primary pixel within 60 m of a
+ /// primary-secondary proof edge is clearly darker with B than with A (and with B2 than with A2).</summary>
+ [UnityTest]
+ public IEnumerator VariantBDrawsADarkRimOnTheEdge()
+ {
+ var (map, cam, rig) = BorderTests.Open();
+ yield return null;
+ RenderSample.TiltShift(false);
+ BorderProof.Show(map);
+ var (inner, outer) = BorderTests.ProofEdge(map, PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, "coastal_plain");
+ BorderTests.LookAtEdge(map, rig, inner);
+ rig.Distance = 20000f; rig.Apply();
+ float Darkest(BorderVariant v)
+ {
+ MapBorders.Variant = v;
+ return BorderTests.WalkEdge(map, cam, inner, outer, 5, 1920, 1080)
+ .Select(w => Enumerable.Range(0, w.On.Count).Where(k => w.SignedM[k] < 0f && w.SignedM[k] > -60f).Select(k => RenderSample.Luma(w.On[k])).DefaultIfEmpty(1f).Min())
+ .OrderBy(x => x).ElementAt(2);
+ }
+ float a = Darkest(BorderVariant.A), b = Darkest(BorderVariant.B), a2 = Darkest(BorderVariant.A2), b2 = Darkest(BorderVariant.B2);
+ TestContext.WriteLine($"20 km: darkest primary pixel within 60 m of the edge: A {a:0.000}, B {b:0.000}; A2 {a2:0.000}, B2 {b2:0.000}");
+ Assert.Less(b, a - 0.05f, "B's rim darkens the edge");
+ Assert.Less(b2, a2 - 0.05f, "B2's rim darkens the edge");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/BorderCivTests.cs.meta b/unity/Assets/Tests/EditMode/BorderCivTests.cs.meta
new file mode 100644
index 000000000..9783bccda
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/BorderCivTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 6627f73876384ab794a8d5324062a2b5
diff --git a/unity/Assets/Tests/EditMode/BorderTests.cs b/unity/Assets/Tests/EditMode/BorderTests.cs
index 8497c0fb2..986cff7ac 100644
--- a/unity/Assets/Tests/EditMode/BorderTests.cs
+++ b/unity/Assets/Tests/EditMode/BorderTests.cs
@@ -12,9 +12,16 @@ using UnityEngine.TestTools;
/// synthetic BorderProof pattern; the real 1948 sub-districts, which play draws (GameRoot), are SubdistrictTests'.</summary>
public class BorderTests
{
+ /// <summary>These tests pin main's earlier look (the Legacy variant; A2 is the default since the owner's ruling of
+ /// 2026-10-27, and BorderCivTests covers it and the prototype's other variants, #196), so no earlier test's variant leaks
+ /// in and Legacy keeps main's assertions.</summary>
+ [SetUp]
+ public void Legacy() => MapBorders.Variant = BorderVariant.Legacy;
+
[TearDown]
public void Reset()
{
+ MapBorders.Variant = MapBorders.DefaultVariant;
MapShaderGlobals.PinWaterTime(null);
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear();
}
diff --git a/unity/Assets/Tests/EditMode/GradeTests.cs b/unity/Assets/Tests/EditMode/GradeTests.cs
index 52388fb7e..e3a3b6bae 100644
--- a/unity/Assets/Tests/EditMode/GradeTests.cs
+++ b/unity/Assets/Tests/EditMode/GradeTests.cs
@@ -13,8 +13,13 @@ using UnityEngine.TestTools;
/// <summary>Plan Task 4: the grade, the tonemapper, the vignette, and what they do to readability.</summary>
public class GradeTests
{
+ /// <summary>The border checks here pin main's earlier look (the Legacy variant; A2 is the default since the owner's
+ /// ruling of 2026-10-27, and BorderCivTests runs these checks on it and the prototype's other variants, #196).</summary>
+ [SetUp]
+ public void Legacy() => MapBorders.Variant = BorderVariant.Legacy;
+
[TearDown]
- public void Reset() { EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear(); }
+ public void Reset() { MapBorders.Variant = MapBorders.DefaultVariant; EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear(); }
static (MapScene map, CameraRig rig, VolumeProfile profile) Open()
{
@@ -202,7 +207,12 @@ public class GradeTests
/// apart, the neutral band's stronger stripe >= 15 from the land, its two stripes >= 20 apart; and it is dashed, a cue
/// that is not colour (review S9 of #555): some walks fall in a gap.</summary>
[UnityTest]
- public IEnumerator ColourBlindPlayersTellTheNeutralBandFromBothSides()
+ public IEnumerator ColourBlindPlayersTellTheNeutralBandFromBothSides() => NeutralBandApart(0.02f);
+
+ /// <summary>The body of ColourBlindPlayersTellTheNeutralBandFromBothSides with the neutral stripe's least greyness gain
+ /// as a parameter: the Civ-like prototype's variants (#196) wash and tint the neutral side, so BorderCivTests reads its
+ /// stripe above that (0.10).</summary>
+ internal static IEnumerator NeutralBandApart(float neutralGain)
{
var (map, cam, rig) = BorderTests.Open();
yield return null;
@@ -226,7 +236,7 @@ public class GradeTests
var b = BorderTests.WalkEdge(map, cam, inner, outer, 5, 1920, 1080);
for (int i = 0; i < a.Count; i++)
{
- var p = BorderTests.Read(a[i], -1, BorderTests.Blueness, 0.45f); var n = BorderTests.Read(a[i], +1, Greyness, 0.02f);
+ var p = BorderTests.Read(a[i], -1, BorderTests.Blueness, 0.45f); var n = BorderTests.Read(a[i], +1, Greyness, neutralGain);
var s = BorderTests.Read(b[i], +1, BorderTests.Redness);
if (n.WidthPx < 1f) { gaps++; continue; } // a walk through a gap between the neutral band's dashes
drawn++;
diff --git a/unity/Assets/Tests/EditMode/SubdistrictTests.cs b/unity/Assets/Tests/EditMode/SubdistrictTests.cs
index bb42c30ce..9094c7710 100644
--- a/unity/Assets/Tests/EditMode/SubdistrictTests.cs
+++ b/unity/Assets/Tests/EditMode/SubdistrictTests.cs
@@ -27,11 +27,20 @@ public class SubdistrictTests
static UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
string saveDir = "";
- [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-subd-" + Guid.NewGuid().ToString("N"));
+ /// <summary>Saves go to a temporary folder. The rendered check pins main's earlier look (the Legacy variant): its
+ /// "outlines, not fills" bound is Legacy's, since the default A2 also tints the territory (owner ruling 2026-10-27,
+ /// #196; BorderCivTests covers A2).</summary>
+ [SetUp]
+ public void TempSaves()
+ {
+ saveDir = Path.Combine(Path.GetTempPath(), "statecraft-subd-" + Guid.NewGuid().ToString("N"));
+ MapBorders.Variant = BorderVariant.Legacy;
+ }
[TearDown]
public void DiscardScene()
{
+ MapBorders.Variant = MapBorders.DefaultVariant;
MapShaderGlobals.PinWaterTime(null);
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear();
if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);