A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: rails, ballast, sleepers and road verges after promo 03 (refs #35) (#404)
Eyal Golanb10e95e03ca1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fb012b0fe..457db1ee7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -199,6 +199,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBwidth, centred on the edge, instead of two full bands side by side; the Mandate frontier and a primary-secondary edgekeep the full band. Far off (a band under about 4 px, the overview) a band is a thin line of its colour, not a whiteone. Visual only (refs #196).+- Map: the railway and road look after promo 03 (`Route.shader` only): the two rails are drawn at least 0.8 px wide and+ brighter, so they stand out at the gameplay zoom; the sleepers run every 100 m, a fine texture instead of a coarse ladder; the+ ballast is a cooler stone grey; roads have darker worn verges, so they read on pale ground. No mesh, data or boot change+ (refs #35).- Land round 2 (refs #33): the ground's colours move from yellow-olive and gold to promo 03's warm dry ground, in thebiome palette and the land-use bake. Hedges, tree lines and farm tracks are drawn about 150 m wide, so the fields readat the gameplay zoom. The hills get round bushes with a soft shadow, a stronger garrigue and clearer terraces. It is adiff --git a/docs/routes.md b/docs/routes.mdindex e2f817dbe..0e11b71da 100644--- a/docs/routes.md+++ b/docs/routes.md@@ -197,10 +197,23 @@ measurement in `docs/units.md`:- u runs across the ribbon and v along it, in metres.**The shader** (`Statecraft/Route`). It is transparent and has no new keywords; the shadow keywords are the terrain's.-- The road is pale dirt with faint wheel ruts. At the country-wide pose (a pixel over 60–150 m), it darkens to a- grey-brown line, so it reads as the promo diorama's roads do instead of vanishing on pale ground.-- The railway is a grey-brown ballast bed with darker shoulders, dark sleepers and two light steel rails, after the- promo video's 0:21 close-up.+- The road is pale dirt with faint wheel ruts and darker worn verges (0.32 of the width either side of the line, about+ 1 px each at gameplay03), so it reads on pale sand and dry grass by its edges, as promo 03's tracks do. At the+ country-wide pose (a pixel over 60–150 m), it darkens to a grey-brown line, so it reads as the promo diorama's roads+ do instead of vanishing on pale ground.+- The railway is a cool grey stone ballast bed with darker shoulders, dark sleepers every 100 m and two bright steel+ rails, after promo 03 and the video's 0:21 close-up (refs #35, `.superpowers/borders-routes-r1/PLAN.md` R1 and R2).+ - A rail is 0.036 of the 680 m bed, about 0.7 px at gameplay03, so its box filter left it faint: averaged along the+ line (`TheRailsReadAsTwoBrightLinesAtGameplay03`, two railways, 30 points each), a rail stood 0.10–0.11 luma above+ the bed beside it. It is now drawn at least 0.8 px wide (`RailMinPx`) and brighter, and stands 0.18–0.21 above it+ (bound 0.15). The two fade out where they would merge, under 3 px apart (the overview).+ - Roads: on the eight palest-ground road crossings in the gameplay03 frame (`RoadsReadOnPaleGroundByTheirVerges`),+ the verges are darker than the core by at least 0.04 and darker than the ground beside them on 6 of 8 (bound 5);+ with main's shader on 0 of 8.+ - The sleepers were every 150 m at a duty of 0.4: a dark bar of about 1.7 px every 4.3 px, a coarse ladder. At 100 m+ and 0.35 they are a fine texture, as the promo's.+ - The ballast was a grey-brown (0.50, 0.46, 0.41) close to the land's ochre; it is now a stone grey (0.56, 0.54, 0.50),+ with shoulders (0.44, 0.42, 0.39).- Every pattern is box-filtered to the pixel, so it fades to its mean at the overview instead of shimmering.- It is lit like the ground: the sun with its shadows and the ambient probe. Then come the hex grid and the land hazefrom `StatecraftMap.hlsl`.diff --git a/unity/Assets/Shaders/Route.shader b/unity/Assets/Shaders/Route.shaderindex e6207a965..3c665a077 100644--- a/unity/Assets/Shaders/Route.shader+++ b/unity/Assets/Shaders/Route.shader@@ -26,22 +26,31 @@ Shader "Statecraft/Route"float _Opacity;CBUFFER_END- // Colours (sRGB) after the promo's gameplay frame (promo/final/03): pale packed dirt; a grey-brown ballast bed- // with dark timber sleepers and light steel rails (promo video 0:21).+ // Colours (sRGB) after the promo's gameplay frame (promo/final/03): pale packed dirt with darker worn verges that+ // outline it on pale ground, as the promo's tracks read; a cool grey stone ballast bed with dark timber sleepers and+ // bright steel rails (promo video 0:21).static const float3 RoadSrgb = float3(0.86, 0.78, 0.62);static const float3 RutSrgb = float3(0.72, 0.63, 0.48);- static const float3 BallastSrgb = float3(0.50, 0.46, 0.41);- static const float3 BankSrgb = float3(0.42, 0.37, 0.31); // the embankment's shoulders, darker+ static const float3 VergeSrgb = float3(0.42, 0.35, 0.26);+ static const float3 BallastSrgb = float3(0.56, 0.54, 0.50);+ static const float3 BankSrgb = float3(0.44, 0.42, 0.39); // the embankment's shoulders, darkerstatic const float3 SleeperSrgb = float3(0.30, 0.22, 0.15);// Far off (a pixel over FarFromM, full by FarToM: the country-wide pose), pale dirt on pale ground would vanish,// so a road darkens to a grey-brown line, as the promo's diorama draws its roads (a symbolic far look).static const float3 RoadFarSrgb = float3(0.50, 0.44, 0.36);static const float FarFromM = 60.0, FarToM = 150.0;- static const float3 RailSrgb = float3(0.72, 0.70, 0.66); // light worn steel, as the promo video's close-up- // The railway's pattern, in metres along (v) and as a share of the ribbon across (u).- static const float SleeperSpacingM = 150.0, SleeperDuty = 0.4, SleeperHalfSpan = 0.29;+ static const float3 RailSrgb = float3(0.90, 0.89, 0.86); // bright worn steel, as the promo video's close-up+ // The railway's pattern, in metres along (v) and as a share of the ribbon across (u). Sleepers every 100 m (about+ // 3 px at the gameplay zoom: a fine texture, as the promo's, not a coarse ladder).+ static const float SleeperSpacingM = 100.0, SleeperDuty = 0.35, SleeperHalfSpan = 0.29;static const float RailOffset = 0.12, RailHalfWidth = 0.018;+ // A rail is drawn at least RailMinPx wide, so at the gameplay zoom (its true 0.036 of the bed is under a pixel) it+ // still reads as a bright line; the rails fade out where the two would merge (under RailFadeToPx apart).+ static const float RailMinPx = 0.8, RailFadeFromPx = 1.5, RailFadeToPx = 3.0;static const float RutOffset = 0.16, RutHalfWidth = 0.05;+ // The verges: a darker worn strip either side of the dirt, just inside the soft edge (RoadEdge), where the road is+ // still nearly opaque, so the dark line outlines the pale core on pale ground.+ static const float VergeOffset = 0.31, VergeHalfWidth = 0.09, VergeStrength = 0.9, RoadEdge = 0.18;struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; float2 uv : TEXCOORD0; };struct Varyings { float4 positionCS : SV_POSITION; float3 positionWS : TEXCOORD0; float3 normalWS : TEXCOORD1; float2 uv : TEXCOORD2; };@@ -93,7 +102,9 @@ Shader "Statecraft/Route"float across = Band(u, 0.5, SleeperHalfSpan, du);float sleeper = across * PulseBox(v, dv, SleeperSpacingM, SleeperDuty);albedo = lerp(albedo, SRGBToLinear(SleeperSrgb), sleeper);- float rails = saturate(Band(u, 0.5 - RailOffset, RailHalfWidth, du) + Band(u, 0.5 + RailOffset, RailHalfWidth, du));+ float railH = max(RailHalfWidth, 0.5 * RailMinPx * du);+ float rails = saturate(Band(u, 0.5 - RailOffset, railH, du) + Band(u, 0.5 + RailOffset, railH, du));+ rails *= smoothstep(RailFadeFromPx, RailFadeToPx, 2.0 * RailOffset / du); // the two rails' spacing in pixelsalbedo = lerp(albedo, SRGBToLinear(RailSrgb), rails);float e = max(0.16, du); // the soft edge, at least a pixel wide (review M5)alpha = smoothstep(0.0, e, u) * smoothstep(1.0, 1.0 - e, u);@@ -103,8 +114,10 @@ Shader "Statecraft/Route"albedo = SRGBToLinear(RoadSrgb);float ruts = saturate(Band(u, 0.5 - RutOffset, RutHalfWidth, du) + Band(u, 0.5 + RutOffset, RutHalfWidth, du));albedo = lerp(albedo, SRGBToLinear(RutSrgb), 0.6 * ruts);+ float verges = saturate(Band(u, 0.5 - VergeOffset, VergeHalfWidth, du) + Band(u, 0.5 + VergeOffset, VergeHalfWidth, du));+ albedo = lerp(albedo, SRGBToLinear(VergeSrgb), VergeStrength * verges);albedo = lerp(albedo, SRGBToLinear(RoadFarSrgb), smoothstep(FarFromM, FarToM, dv));- float e = max(0.3, du);+ float e = max(RoadEdge, du);alpha = smoothstep(0.0, e, u) * smoothstep(1.0, 1.0 - e, u);}albedo = lerp(albedo, SRGBToLinear(ScGridLandSrgb), grid * _ScGrid.x);diff --git a/unity/Assets/Tests/EditMode/RouteTests.cs b/unity/Assets/Tests/EditMode/RouteTests.csindex b38ea6023..602e0c093 100644--- a/unity/Assets/Tests/EditMode/RouteTests.cs+++ b/unity/Assets/Tests/EditMode/RouteTests.cs@@ -664,4 +664,165 @@ public class RouteTests}finally { VisualToggles.SetAll(true); Object.DestroyImmediate(map.gameObject); }}++ /// <summary>A walk across a route at gameplay03's pose: the pixels from -<paramref name="halfM"/> to +halfM across the+ /// line at the line point nearest (lon, lat), with the routes on and off, and each pixel's offset (m) from the line.</summary>+ sealed class Across { public readonly List<Color> On = new List<Color>(), Off = new List<Color>(); public readonly List<float> M = new List<float>(); }++ static List<Across> WalkAcross(MapScene map, Camera cam, List<Vector2> line, IEnumerable<int> at, float halfM, float stepM)+ {+ var data = map.Terrain.terrainData; var origin = map.Terrain.transform.position;+ var world = new List<Vector3>(); var offs = new List<(int walk, float m)>();+ int walk = 0;+ foreach (int i in at)+ {+ var dir = (line[Mathf.Min(line.Count - 1, i + 1)] - line[Mathf.Max(0, i - 1)]).normalized; var side = new Vector2(dir.y, -dir.x);+ for (float m = -halfM; m <= halfM + 1e-3f; m += stepM)+ {+ var q = line[i] + side * m;+ world.Add(new Vector3(q.x, RouteLayer.Ground(data, origin, q), q.y)); offs.Add((walk, m));+ }+ walk++;+ }+ var px = new Vector2[world.Count];+ var on = RenderSample.Render(cam, 1920, 1080, world.ToArray(), px);+ VisualToggles.Set(RouteLayer.RoutesToggle, false);+ var off = RenderSample.Render(cam, 1920, 1080);+ VisualToggles.Set(RouteLayer.RoutesToggle, true);+ var walks = Enumerable.Range(0, walk).Select(_ => new Across()).ToList();+ var seen = new HashSet<(int, int, int)>();+ for (int k = 0; k < world.Count; k++)+ {+ int x = Mathf.FloorToInt(px[k].x), y = Mathf.FloorToInt(px[k].y);+ if (!seen.Add((offs[k].walk, x, y))) continue;+ var w = walks[offs[k].walk]; w.On.Add(on.At(x, y)); w.Off.Add(off.At(x, y)); w.M.Add(offs[k].m);+ }+ return walks;+ }++ /// <summary><paramref name="count"/> points of <paramref name="line"/> in the frame's middle, spread along the line; null+ /// when fewer lie there.</summary>+ static List<int> InFrame(MapScene map, Camera cam, List<Vector2> line, int count)+ {+ var data = map.Terrain.terrainData; var origin = map.Terrain.transform.position;+ var inside = new List<int>();+ for (int i = 2; i + 2 < line.Count; i++)+ {+ var v = cam.WorldToViewportPoint(new Vector3(line[i].x, RouteLayer.Ground(data, origin, line[i]), line[i].y));+ if (v.z > 0 && v.x > 0.2f && v.x < 0.8f && v.y > 0.3f && v.y < 0.7f) inside.Add(i);+ }+ if (inside.Count < count) return null;+ return Enumerable.Range(0, count).Select(k => inside[(int)((k + 0.5f) * inside.Count / count)]).ToList();+ }++ /// <summary>Promo 03 and the video's 0:21 close-up draw two bright steel rails on the grey ballast. A rail is 0.036 of+ /// the 680 m bed, under a pixel at gameplay03, so it is drawn at least RailMinPx wide. A line detector at gameplay03+ /// (tilt-shift off, the train hidden): at 30 points along each of two railways in the frame's middle, the luma at each+ /// offset across the line, averaged along the line (so the sleepers, which cross it, average out and a line along it+ /// stays); on each side, the rail's offset (0.12 of the width, about 82 m) stands above the bed either side of it by+ /// RailContrast.</summary>+ [Test]+ public void TheRailsReadAsTwoBrightLinesAtGameplay03()+ {+ var map = BuildMap();+ try+ {+ RenderSample.TiltShift(false);+ VisualToggles.Set(RouteLayer.TrainToggle, false);+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();+ PromoPose.Gameplay03.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();+ var routes = RoutePaths.Parse(CommittedYaml, Bounds);+ var data = map.Terrain.terrainData; var origin = map.Terrain.transform.position;+ const float Step = 5f, Half = 200f;+ int n = Mathf.RoundToInt(2 * Half / Step) + 1;+ foreach (var id in new[] { "eastern_railway", "jaffa_jerusalem_railway" })+ {+ var line = RouteLayer.Resample(RouteLayer.World(map.Frame, routes.First(r => r.Id == id)), 60f).points;+ var at = InFrame(map, cam, line, 30);+ Assert.IsNotNull(at, $"{id} crosses the middle of the gameplay frame");+ var world = new List<Vector3>();+ foreach (int i in at)+ {+ var dir = (line[Mathf.Min(line.Count - 1, i + 1)] - line[Mathf.Max(0, i - 1)]).normalized; var side = new Vector2(dir.y, -dir.x);+ for (int k = 0; k < n; k++)+ {+ var q = line[i] + side * (-Half + k * Step);+ world.Add(new Vector3(q.x, RouteLayer.GradeHeight(data, origin, q, dir), q.y));+ }+ }+ var px = new Vector2[world.Count];+ var on = RenderSample.Render(cam, 1920, 1080, world.ToArray(), px);+ var profile = new float[n];+ for (int j = 0; j < world.Count; j++) profile[j % n] += RenderSample.Luma(on.At(Mathf.FloorToInt(px[j].x), Mathf.FloorToInt(px[j].y))) / at.Count;+ float Window(float lo, float hi, int sign, bool max)+ {+ var v = Enumerable.Range(0, n).Select(k => (m: -Half + k * Step, l: profile[k]))+ .Where(x => Mathf.Sign(x.m) == sign && Mathf.Abs(x.m) >= lo && Mathf.Abs(x.m) <= hi).Select(x => x.l).ToList();+ return max ? v.Max() : v.Average();+ }+ TestContext.WriteLine($"{id}: profile along the line {string.Join(" ", profile.Select(l => l.ToString("0.000")))}");+ foreach (int sign in new[] { -1, +1 })+ {+ float rail = Window(65f, 100f, sign, true), bed = 0.5f * (Window(20f, 50f, sign, false) + Window(115f, 145f, sign, false));+ TestContext.WriteLine($"{id} side {sign}: rail {rail:0.000} bed {bed:0.000} contrast {rail - bed:0.000}");+ Assert.GreaterOrEqual(rail - bed, RailContrast, $"{id}: the rail on side {sign} reads as a bright line along the bed");+ }+ }+ }+ finally { VisualToggles.SetAll(true); Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>Bound for the rail test, set from its log.</summary>+ const float RailContrast = 0.15f; // measured 0.18-0.21 (main's shader: 0.10-0.11)++ /// <summary>Promo 03's dirt tracks read on any ground by their darker worn edges. On the palest ground a road crosses in+ /// the gameplay03 frame (the sand and dry grass, where a pale road alone melts in), across the road the verges are+ /// darker than its core by VergeStep, and darker than the ground beside them with the routes off.</summary>+ [Test]+ public void RoadsReadOnPaleGroundByTheirVerges()+ {+ var map = BuildMap();+ try+ {+ RenderSample.TiltShift(false);+ VisualToggles.Set(RouteLayer.TrainToggle, false);+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();+ PromoPose.Gameplay03.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();+ var routes = RoutePaths.Parse(CommittedYaml, Bounds);+ // Every road point in the frame's middle, walked across; the palest ground (the routes off) first.+ var walks = new List<(string id, Across w, float ground)>();+ foreach (var r in routes.Where(r => r.Kind == RoutePaths.Road))+ {+ var line = RouteLayer.World(map.Frame, r);+ var at = InFrame(map, cam, line, 6);+ if (at == null) continue;+ foreach (var w in WalkAcross(map, cam, line, at, 300f, 5f))+ {+ var g = w.M.Select((m, k) => (m, k)).Where(x => Mathf.Abs(x.m) > 200f).Select(x => RenderSample.Luma(w.Off[x.k])).ToList();+ if (g.Count > 0) walks.Add((r.Id, w, g.Average()));+ }+ }+ var pale = walks.OrderByDescending(x => x.ground).Take(8).ToList();+ Assert.GreaterOrEqual(pale.Count, 6, "roads cross the gameplay frame");+ int read = 0;+ foreach (var (id, w, ground) in pale)+ {+ float Mean(float lo, float hi, List<Color> c) { var v = w.M.Select((m, k) => (m, k)).Where(x => Mathf.Abs(x.m) >= lo && Mathf.Abs(x.m) <= hi).Select(x => RenderSample.Luma(c[x.k])).ToList(); return v.Count == 0 ? float.NaN : v.Average(); }+ float core = Mean(0f, 30f, w.On);+ // The verge's darkest pixel on each side.+ float VergeSide(int sign) { var v = w.M.Select((m, k) => (m, k)).Where(x => Mathf.Sign(x.m) == sign && Mathf.Abs(x.m) >= 60f && Mathf.Abs(x.m) <= 130f).Select(x => RenderSample.Luma(w.On[x.k])).ToList(); return v.Count == 0 ? float.NaN : v.Min(); }+ float verge = Mathf.Max(VergeSide(-1), VergeSide(+1)); // the weaker side+ float off = Mean(60f, 130f, w.Off);+ bool ok = core - verge >= VergeStep && verge < off - VergeBelowGround;+ if (ok) read++;+ TestContext.WriteLine($"{id}: ground {ground:0.000} core {core:0.000} verge {verge:0.000} (off {off:0.000}) -> {(ok ? "reads" : "melts")}");+ }+ TestContext.WriteLine($"{read} of {pale.Count} pale-ground walks read");+ Assert.GreaterOrEqual(read / (float)pale.Count, PaleReadShare, "roads read on pale ground");+ }+ finally { VisualToggles.SetAll(true); Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>Bounds for the road test, set from its log.</summary>+ const float VergeStep = 0.04f, VergeBelowGround = 0.01f, PaleReadShare = 0.6f;}