A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Fix: no checker on the open sea up close (B10) (#191)
Eyal Golan6f17ccec9458
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4fdef00d4..4aa1ff441 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -89,3 +89,5 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB- The Cabinet's "Appoint to …" heading has its own column again and stays clear of the portrait grid's scroll bar.- The "Not done" toast is opaque and sits clear of the open screen.- "International Standing" keeps to one line on a full-width bar.+- The open sea no longer shows a blocky checker up close (about 6-20 km): its waves now come from smooth gradient noise+ on rotated lattices instead of value noise differenced along the map's axes. Presentation only.diff --git a/docs/visual-v1.md b/docs/visual-v1.mdindex e358edfdc..2301410c9 100644--- a/docs/visual-v1.md+++ b/docs/visual-v1.md@@ -989,9 +989,30 @@ Review round 1 (staff review I1-I2, M1-M8) is folded in; the values below are th- the 700 m swell (unchanged);- a 170 m chop moving the other way, `ScChopGain` 1.4 times the swell, full under a 40 m pixel and gone by 170 m.- The tilt is `ScWaveTilt` 0.6 under a 50 m pixel (gameplay03 is about 45 m: chop and sparkle show). It eases to Task 7's- 0.15 by 120 m: the far sea reads calm, and the seam test's patch means stay within bound (at a flat 0.6, one 7x7 patch- at 120 km carried 0.032 against 0.012). Glint unchanged (0.06).+ The tilt is `ScWaveTilt` 0.6 under a 50 m pixel (gameplay03 is about 45 m: chop and sparkle show). It eases to+ `ScWaveTiltFar` 0.10 by 120 m (Task 7's 0.15 until sea-fix): the far sea reads calm, and the seam test's patch means+ stay within bound (at a flat 0.6, one 7x7 patch at 120 km carried 0.032 against 0.012). The glint (0.06) fades out+ between 60 and 120 m pixels (sea-fix, below).++ Bug B10 (sea-fix): both layers were value noise differenced along the map's axes, on axis-aligned lattices. Their+ slope jumped at every cell edge, so the open sea showed a blocky checker at 6-20 km. Both layers are now gradient noise+ with its analytic slope (`ScGradientNoiseD`, quintic fade: smooth across cell edges), the swell's lattice turned+ 0.6 rad and the chop's -0.9 rad (`ScWaveSlope`), scaled by `ScWaveSlopeGain` 0.22 to the old layers' strength (open+ sea luma std at 6 / 12 / 18 km: 5.5 / 6.6 / 6.8 before, 6.0 / 6.8 / 7.1 after, in 8-bit levels). Fewer hashes than+ before: 4 gradients per layer against 16 value-noise lookups. `TheOpenSeaHasNoBlockGrid` renders the open sea straight+ down at 4 m a pixel and folds the luma gradient by its position in each old lattice's cell; the block-edge energy+ ((largest bin - smallest) / mean, bound 0.25) was 0.660 before (170 m along z) and 0.122 after. `MapCapture.SeaClose`+ renders the sea at 6, 12 and 18 km. With the new swell the seam test's single +-2.5 km patches (one 7x7 patch is about+ one swell cell at 120 km) read up to 0.016 apart (bound 0.012) at the far tilt of 0.15, so the far tilt is now 0.10,+ and the glint, the near zoom's sparkle, fades out between 60 and 120 m pixels.+ Frame time (headless; another session loaded the machine, load average 4-18, so the spreads are wide):+ - `PROFILE summary visual=all pose=gameplay03 runs=3 median_avg_ms=8.35 spread_ms=0.11 median_p95_ms=10.00`+ - `PROFILE summary visual=-water pose=gameplay03 runs=3 median_avg_ms=8.03 spread_ms=2.69 median_p95_ms=9.00`+ - `PROFILE summary visual=all pose=diorama02 runs=3 median_avg_ms=13.54 spread_ms=0.22 median_p95_ms=14.00`+ - `PROFILE summary visual=-water pose=diorama02 runs=3 median_avg_ms=13.24 spread_ms=0.21 median_p95_ms=14.00`++ Water and shore cost 0.32 ms at gameplay03 (inside a 2.69 ms spread) and 0.30 ms at diorama02, against the 2.5 ms+ budget (0.89 / 0.13 ms in promo-sea round 1); p95 with everything on is 10 / 14 ms, under 16.7 ms.- **Surf** (review I2).- A swash line, full to `ScSwashM` 180 m and gone by 324 m.- Breakers through a `ScSurfM` 900 m zone. They are a squared triangle wave in the distance from the shore, spacingdiff --git a/unity/Assets/Editor/MapCapture.cs b/unity/Assets/Editor/MapCapture.csindex bb73a4a4a..709627e5e 100644--- a/unity/Assets/Editor/MapCapture.cs+++ b/unity/Assets/Editor/MapCapture.cs@@ -133,6 +133,31 @@ public static class MapCapturefinally { MapShaderGlobals.PinWaterTime(null); QualitySettings.SetQualityLevel(saved, true); }}+ /// <summary>The open sea up close (bug B10, the checker): the web tier (quality level 0) at 6, 12 and 18 km over the sea+ /// west of Tel Aviv (34.70 E, 32.08 N), the water's clock pinned, at 1920x1080 into <-captureDir> (default+ /// captures/visual/sea-close) as sea-<km>km.png.</summary>+ public static void SeaClose()+ {+ 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, "visual", "sea-close");+ var map = OpenAndBuild();+ var rig = Camera.main.GetComponent<CameraRig>();+ int saved = QualitySettings.GetQualityLevel();+ try+ {+ QualitySettings.SetQualityLevel(0, true);+ MapShaderGlobals.PinWaterTime(100f);+ var look = map.Frame.ToWorld(34.70, 32.08, 0); look.y = map.Terrain.SampleHeight(look);+ foreach (var km in new[] { 6, 12, 18 })+ {+ rig.LookAt = look; rig.Distance = km * 1000f; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();+ Save(Camera.main, 1920, 1080, Path.Combine(dir, $"sea-{km}km.png"));+ }+ }+ finally { MapShaderGlobals.PinWaterTime(null); QualitySettings.SetQualityLevel(saved, true); }+ }+/// <summary>Renders each promo pose (PromoPose.All) at 1920x1080 once per quality tier (0 = Mobile, the WebGL tier;/// 1 = PC) into <-captureDir> (default captures/visual/editor) as <tier>-<pose>.png. Editor renders show no UI/// Toolkit labels; tools/art_checkpoint.sh pairs them with the WebGL screenshots, which do. With -units it adds the unitdiff --git a/unity/Assets/Shaders/StatecraftMap.hlsl b/unity/Assets/Shaders/StatecraftMap.hlslindex 487b33c9f..f754d091e 100644--- a/unity/Assets/Shaders/StatecraftMap.hlsl+++ b/unity/Assets/Shaders/StatecraftMap.hlsl@@ -25,6 +25,34 @@ float ScNoise(float2 p)return lerp(lerp(ScHash(i), ScHash(i + float2(1, 0)), u.x), lerp(ScHash(i + float2(0, 1)), ScHash(i + float2(1, 1)), u.x), u.y);}+// Gradient noise and its derivative, (value, d/dp.x, d/dp.y): random unit gradients at the lattice corners, blended with+// the quintic fade, so the field and its slope are smooth across cell edges (bug B10: the waves' value-noise differences+// jumped at the lattice lines, a checker up close). The value is in about [-0.7, 0.7].+float3 ScGradientNoiseD(float2 p)+{+ float2 i = floor(p), f = frac(p);+ float2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);+ float2 du = 30.0 * f * f * (f * (f - 2.0) + 1.0);+ float ha = ScHash(i) * 6.2831853, hb = ScHash(i + float2(1, 0)) * 6.2831853;+ float hc = ScHash(i + float2(0, 1)) * 6.2831853, hd = ScHash(i + float2(1, 1)) * 6.2831853;+ float2 ga = float2(cos(ha), sin(ha)), gb = float2(cos(hb), sin(hb)), gc = float2(cos(hc), sin(hc)), gd = float2(cos(hd), sin(hd));+ float va = dot(ga, f), vb = dot(gb, f - float2(1, 0)), vc = dot(gc, f - float2(0, 1)), vd = dot(gd, f - float2(1, 1));+ float k = va - vb - vc + vd;+ float v = va + u.x * (vb - va) + u.y * (vc - va) + u.x * u.y * k;+ float2 d = ga + u.x * (gb - ga) + u.y * (gc - ga) + u.x * u.y * (ga - gb - gc + gd) + du * (u.yx * k + float2(vb, vc) - va);+ return float3(v, d);+}++// The slope of a gradient-noise wave layer at mapM: its lattice turned by `angle` (so no two layers, and neither, line up+// with the map's axes or the hex grid) and drifting along `drift` (cells per second), the slope turned back to map axes.+float2 ScWaveSlope(float2 mapM, float cellM, float angle, float2 drift, float time)+{+ float s, c; sincos(angle, s, c);+ float2 p = mapM / cellM;+ float2 d = ScGradientNoiseD(float2(c * p.x - s * p.y, s * p.x + c * p.y) + drift * time).yz;+ return float2(c * d.x + s * d.y, -s * d.x + c * d.y);+}+// Low in the rift the haze grows by up to this share (1.5 saturated the rift at the country-wide zoom: Task 6 review I1).static const float ScRiftHazeBoost = 0.6;@@ -65,6 +93,8 @@ static const float3 ScDeepSrgb = float3(0.27, 0.40, 0.54);static const float3 ScFlatSeaSrgb = float3(0.20, 0.36, 0.47); // the "water" toggle's flat sea (x 0.8)static const float3 ScGalileeSrgb = float3(0.20, 0.45, 0.55); // fresh water (-300..-100 m): the Sea of Galileestatic const float ScChopGain = 1.4; // the chop's share of the wave tilt against the swell's+static const float ScWaveSlopeGain = 0.22; // gradient-noise slope -> the old layers' strength+static const float ScWaveTiltFar = 0.10; // ... and beyond a 120 m pixel (Task 7: 0.15 everywhere)static const float ScWaveTilt = 0.6; // wave normal tilt at the gameplay zoom (Task 7: 0.15)// The surf: a swash line along the sand (full to ScSwashM) and breakers rolling shoreward through the surf zone// (ScSurfM), broken along the shore by noise. The breakers are a squared triangle wave in the distance from the shore,@@ -125,19 +155,19 @@ float3 ScWaterShade(float coast, float elevM, float3 positionWS, float2 mapM, flc = lerp(c, SRGBToLinear(ScGalileeSrgb), fresh * 0.7);float time = ScWaterClock();- float2 p = mapM / 700.0;- float2 g = float2(ScNoise(p + float2(time * 0.05, 0.0)) - ScNoise(p + float2(0.37 + time * 0.05, 0.0)),- ScNoise(p.yx + float2(0.0, time * 0.04)) - ScNoise(p.yx + float2(0.0, 0.41 + time * 0.04)));- // The chop: a 170 m layer moving the other way, full while a pixel covers under 40 m, gone by 170 m (the gameplay pose- // sees it, the overview averages it away).+ // The swell: a 700 m gradient-noise layer turned 0.6 rad. Bug B10: it was value noise differenced along the map's axes+ // (on an axis-aligned lattice), whose slope jumped at every cell edge; ScWaveSlopeGain scales the smooth slope to the+ // old layers' strength.+ float2 g = ScWaveSlopeGain * ScWaveSlope(mapM, 700.0, 0.6, float2(0.05, 0.02), time);+ // The chop: a 170 m layer turned -0.9 rad and moving the other way, full while a pixel covers under 40 m, gone by+ // 170 m (the gameplay pose sees it, the overview averages it away).float chop = 1.0 - smoothstep(40.0, 170.0, footprintM);- float2 q = mapM / 170.0;- g += ScChopGain * chop * float2(ScNoise(q - float2(time * 0.11, 0.0)) - ScNoise(q + float2(0.29 - time * 0.11, 0.0)),- ScNoise(q.yx - float2(0.0, time * 0.09)) - ScNoise(q.yx + float2(0.0, 0.33 - time * 0.09)));- // The wave tilt: ScWaveTilt near (pixels under 50 m: the gameplay zoom shows the chop and sparkle), easing to Task 7's- // 0.15 by 120 m, where a pixel spans a good part of a swell cell: the far sea reads as a calm surface, and patch means- // either side of the map's edge stay within the seam test's 0.012 (at 0.6 a single 7x7 patch at 120 km carried 0.03).- float tilt = lerp(ScWaveTilt, 0.15, smoothstep(50.0, 120.0, footprintM));+ g += ScChopGain * chop * ScWaveSlopeGain * ScWaveSlope(mapM, 170.0, -0.9, float2(-0.11, -0.07), time);+ // The wave tilt: ScWaveTilt near (pixels under 50 m: the gameplay zoom shows the chop and sparkle), easing to 0.10 by+ // 120 m, where a pixel spans a good part of a swell cell: the far sea reads as a calm surface, and patch means either+ // side of the map's edge stay within the seam test's 0.012 (at 0.6 a single 7x7 patch at 120 km carried 0.03; with the+ // gradient-noise swell (sea-fix) Task 7's far 0.15 left single patches up to 0.016 apart).+ float tilt = lerp(ScWaveTilt, ScWaveTiltFar, smoothstep(50.0, 120.0, footprintM));float3 n = normalize(float3(g.x * tilt, 1.0, g.y * tilt));#if defined(UNIVERSAL_REALTIME_LIGHTS_INCLUDED) && !defined(SHADERGRAPH_PREVIEW)Light sun = GetMainLight(TransformWorldToShadowCoord(positionWS)); // review I6: the water receives the sun's shadows@@ -151,8 +181,11 @@ float3 ScWaterShade(float coast, float elevM, float3 positionWS, float2 mapM, flfloat3 lit = c * (0.55 + 0.45 * saturate(dot(n, l)) * lc * shadow);// A small glint (Task 7: 0.06, not the plan's 0.25). Where the camera's pitch meets the sun's height (50 deg each with// Map.unity's default sun, at yaw 180) the 0.25 lobe lit a warm patch rising 0.08 in sRGB red over 6 km of open sea, a- // view-dependent gradient that read as a seam between samples 5 km apart either side of the map's edge.- lit += pow(saturate(dot(reflect(-l, n), v)), 80.0) * 0.06 * lc * shadow;+ // view-dependent gradient that read as a seam between samples 5 km apart either side of the map's edge. The glint is+ // the near zoom's sparkle: it fades out between 60 and 120 m pixels, where the calmer far sea turned it back into that+ // smooth warm gradient (sea-fix: up to 0.016 between the seam test's +-2.5 km patches with the gradient-noise waves).+ float glint = 0.06 * (1.0 - smoothstep(60.0, 120.0, footprintM));+ lit += pow(saturate(dot(reflect(-l, n), v)), 80.0) * glint * lc * shadow;// Surf: the swash line, then breakers (crests every ScBreakerSpacingM, rolling in: the phase grows with time towards// the shore; box-filtered over ScBreakers' width) whose crests break up along the coast (a 300 m noise, faded to its mean once adiff --git a/unity/Assets/Tests/EditMode/SeaTests.cs b/unity/Assets/Tests/EditMode/SeaTests.csindex 107f56687..0ab1047f5 100644--- a/unity/Assets/Tests/EditMode/SeaTests.cs+++ b/unity/Assets/Tests/EditMode/SeaTests.cs@@ -317,6 +317,56 @@ public class SeaTestsAssert.Less(far, 0.01f, "the overview sees the breakers' mean, not a crawl");}+ /// <summary>Bug B10: the open sea showed a blocky checker up close. The waves came from value noise on map-aligned+ /// lattices (700 m swell, 170 m chop), differenced along the axes, so the shading jumped at the lattice lines. Rendered+ /// straight down (orthographic, 4 m a pixel, 25 km offshore, the chop and tilt at full strength), the luma gradient+ /// across each axis is folded by its position within each lattice's cell (16 bins): a block grid piles its edges into a+ /// few bins, isotropic waves spread them evenly. The block-edge energy is (largest bin - smallest) / mean.</summary>+ [UnityTest]+ public IEnumerator TheOpenSeaHasNoBlockGrid()+ {+ var map = OpenMap();+ yield return null;+ VisualToggles.Set("grid", false);+ MapShaderGlobals.PinWaterTime(100f);+ var centre = map.Frame.ToWorld(34.45, 32.0, 0); centre.y = map.Terrain.SampleHeight(centre);+ var origin = map.Terrain.transform.position;+ const int n = 1024; const float metresPerPixel = 4f;+ var go = new GameObject("TopSea"); var cam = go.AddComponent<Camera>();+ try+ {+ cam.orthographic = true; cam.orthographicSize = n * metresPerPixel / 2f; cam.aspect = 1f;+ cam.transform.position = centre + Vector3.up * 20000f; cam.transform.rotation = Quaternion.Euler(90, 0, 0);+ cam.nearClipPlane = 100f; cam.farClipPlane = 60000f;+ var r = RenderSample.Render(cam, n, n);+ float x0 = centre.x - origin.x - n * metresPerPixel / 2f, z0 = centre.z - origin.z - n * metresPerPixel / 2f;+ float worst = 0f; string log = "";+ foreach (var cell in new[] { 700f, 170f })+ foreach (var alongX in new[] { true, false })+ {+ var sum = new double[16]; var count = new int[16];+ for (int j = 1; j < n - 1; j++)+ for (int i = 1; i < n - 1; i++)+ {+ // The edge between pixel (i, j) and its next neighbour lies at map metre x0 + (i + 1) * 4 (x+ // east; image row 0 is the south edge, so rows run north like map z).+ float edgeM = (alongX ? x0 + (i + 1) * metresPerPixel : z0 + (j + 1) * metresPerPixel) / cell;+ int bin = Mathf.Clamp((int)((edgeM - Mathf.Floor(edgeM)) * 16f), 0, 15);+ float d = alongX ? Luma(r.At(i + 1, j)) - Luma(r.At(i, j)) : Luma(r.At(i, j + 1)) - Luma(r.At(i, j));+ sum[bin] += Mathf.Abs(d); count[bin]++;+ }+ double lo = double.MaxValue, hi = 0, all = 0;+ for (int b = 0; b < 16; b++) { double m = sum[b] / count[b]; lo = System.Math.Min(lo, m); hi = System.Math.Max(hi, m); all += m / 16; }+ float energy = (float)((hi - lo) / all);+ worst = Mathf.Max(worst, energy);+ log += $"{cell:0} m {(alongX ? "x" : "z")} {energy:0.000}; ";+ }+ TestContext.WriteLine($"block-edge energy: {log}worst {worst:0.000}");+ Assert.Less(worst, 0.25f, "no lattice of block edges in the sea's shading");+ }+ finally { Object.DestroyImmediate(go); }+ }+/// <summary>Rendered: the Dead Sea is pale turquoise, much lighter than the open Mediterranean.</summary>[UnityTest]public IEnumerator TheDeadSeaIsPalerThanTheOpenSea()