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.

fix(visual): Task 8 review round 1: box-filtered grid lines from the edge-normal footprint, sea lines at 0.10 with a footprint fade, even-row seam strips

eyalgolanee555ac8927e
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index 369b9e9dc..6ad56fac8 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -214,6 +214,30 @@ and tilt-shift are not in this worktree).
- **Look (t08-grid).** The sea lattice runs on past the map's edge with no step. At the 250 km overview the sea lattice is
dense and reads strongly; land lines are faint, nearly invisible on the desert.
+### Task 8 fix round 1
+- **Line anti-aliasing (review I1).** `fwidth` of the V-shaped edge distance collapsed on the line itself. The fix projects
+ the derivatives of the continuous grid coordinate on the nearest edge's normal (metres per pixel across the edge) and
+ box-filters: `saturate(0.5 * widthPx + 0.5 - d / aa)`.
+ - New rendered test `GridLinesAreUnbrokenAndAboutTheirWidthAtGameplay03` (1920x1080, opacities forced to 1, linear luma).
+ - Red at b409955: sea peak ratio 0.41 along one edge, FWHM 2.74 px.
+ - Green: sea ratio 0.85, FWHM 1.66 px (1.51-1.95); land FWHM 1.62 px (1.37-1.97).
+- **Weights (review I2).** `GridWaterOpacity` 0.35 -> 0.10. The distance fade is now lerp(1, 0.35). Lines also fade out as a hex
+ shrinks from 30 to 10 px on screen (circumradius over the pixel footprint). Land stays 0.25 until the grade merges.
+ - Sea line in `gameplay03` (x 120-170, y 480-560): background 49, peak 83, +34, ratio 1.69, 2 px wide. Before: +86,
+ 2.75, 4 px. Promo (x 470-520, y 550-580): background 109, peak 151, +43, ratio 1.39. Our ratio is higher only
+ because our sea is darker (pre-grade).
+ - diorama02 near sea line: +6 over 73 (before +50). Grid coverage at 1920x1080: 0.74% at 20 km, 0.76% at 250 km
+ (was 3.1% / 18.2% at 960x540).
+- **Seam (M1).** The close strips sit on even hex rows (x = 0 a hex centre); all 32 lines (grid off and on, four yaws)
+ are asserted, max 0.004.
+- **Rift.** Arava line change 0.015 (bound 0.012, land opacity unchanged).
+- **Profile** (machine load average about 7, spreads up to 1 ms):
+ - `PROFILE summary visual=all pose=gameplay03 runs=3 median_avg_ms=1.71 spread_ms=0.97 median_p95_ms=3.00`
+ - `PROFILE summary visual=-grid pose=gameplay03 runs=3 median_avg_ms=2.22 spread_ms=0.99 median_p95_ms=4.00`
+ - `PROFILE summary visual=all pose=diorama02 runs=3 median_avg_ms=7.23 spread_ms=0.67 median_p95_ms=8.00`
+ - `PROFILE summary visual=-grid pose=diorama02 runs=3 median_avg_ms=7.22 spread_ms=0.54 median_p95_ms=8.00`
+- **Build.** WebGL, no `Shader error`; golden values OK in the checkpoint run.
+
## Checkpoints
| Task | Name | Images | Owner verdict |
|---|---|---|---|
@@ -223,3 +247,4 @@ and tilt-shift are not in this worktree).
| 7 | t07-sea | captures/visual/t07-sea/*-compare*.png, hero06judea.png, hero06negev.png, editor/*-compare*.png | (owner) |
| 7 (fix 1) | t07-sea-r1 | captures/visual/t07-sea-r1/*-compare*.png, hero06judea.png, hero06negev.png, editor/*-compare*.png | (owner) |
| 8 | t08-grid | captures/visual/t08-grid/*-compare*.png, hero06judea.png, hero06negev.png, editor/*-compare*.png | (owner) |
+| 8 (fix 1) | t08-grid-r1 | captures/visual/t08-grid-r1/*-compare*.png, hero06judea.png, hero06negev.png, editor/*-compare*.png | (owner) |
diff --git a/unity/Assets/Scripts/Map/MapShaderGlobals.cs b/unity/Assets/Scripts/Map/MapShaderGlobals.cs
index a94956946..7c1456281 100644
--- a/unity/Assets/Scripts/Map/MapShaderGlobals.cs
+++ b/unity/Assets/Scripts/Map/MapShaderGlobals.cs
@@ -27,9 +27,10 @@ namespace Statecraft.Game.Map
/// <summary>Real elevations between which the haze thickens, low in the Jordan rift.</summary>
public const float RiftHazeTopM = -100f, RiftHazeFullM = -400f;
- /// <summary>Hex line opacity on land and water, and width in pixels (anti-aliased, the same at every zoom). Light,
- /// faint lines on land as in the promo.</summary>
- public const float GridLandOpacity = 0.25f, GridWaterOpacity = 0.35f, GridWidthPx = 1.5f;
+ /// <summary>Hex line opacity on land and water, and width in pixels (box-filtered, the same at every zoom). Light,
+ /// faint lines as in the promo: water 0.10 (Task 8 review I2: 0.35 gave sea lines 2.6x their background's luma
+ /// against the promo's 1.4x).</summary>
+ public const float GridLandOpacity = 0.25f, GridWaterOpacity = 0.10f, GridWidthPx = 1.5f;
static Vector4 haze, hazeWater;
diff --git a/unity/Assets/Scripts/Map/PixelErrorProfile.cs b/unity/Assets/Scripts/Map/PixelErrorProfile.cs
index 62e4c5c68..2999c4332 100644
--- a/unity/Assets/Scripts/Map/PixelErrorProfile.cs
+++ b/unity/Assets/Scripts/Map/PixelErrorProfile.cs
@@ -8,8 +8,9 @@ using UnityEngine;
namespace Statecraft.Game.Map
{
- /// <summary>Measures frame time with the terrain's heightmapPixelError at 1 (M2's value, which keeps the hex overlay
- /// draped visibly) and at Unity's default 5, from the diorama camera over central Israel, then restores the M2 value.
+ /// <summary>Measures frame time with the terrain's heightmapPixelError at 1 (M2's value, which kept the old hex line
+ /// overlay draped visibly; it now keeps the selection band clear of the ground) and at Unity's default 5, from the
+ /// diorama camera over central Israel, then restores the M2 value.
/// Logs "PROFILE pixelError=&lt;e&gt; frames=&lt;n&gt; avg_ms=&lt;a&gt; p95_ms=&lt;p&gt;" per setting and "PROFILE done".
/// Asked for by "profile" in the WebGL page URL (a whole query parameter, UrlFlags.Has) or -profile on desktop.</summary>
public static class PixelErrorProfile
diff --git a/unity/Assets/Shaders/StatecraftMap.hlsl b/unity/Assets/Shaders/StatecraftMap.hlsl
index 2493ea5d8..6c8b40e54 100644
--- a/unity/Assets/Shaders/StatecraftMap.hlsl
+++ b/unity/Assets/Shaders/StatecraftMap.hlsl
@@ -116,8 +116,9 @@ float3 ScGround(float2 uv, float2 mapM, float3 n, float3 positionWS, float4 bake
}
// Distance (m) from p to the nearest edge of its hex: tools/hexgrid.py's pointy-top axial layout, (0, 0) at the north-west
-// corner, p.x east and p.y south (HexGrid.EdgeDistance is the C# twin).
-float ScHexEdgeDistance(float2 p, float size)
+// corner, p.x east and p.y south (HexGrid.EdgeDistance is the C# twin). n is that edge's outward unit normal (constant over
+// each sixth of a hex).
+float ScHexEdgeDistance(float2 p, float size, out float2 n)
{
float qf = (0.57735027 * p.x - p.y / 3.0) / size;
float rf = 0.66666667 * p.y / size;
@@ -126,28 +127,42 @@ float ScHexEdgeDistance(float2 p, float size)
float dq = abs(q - qf), dr = abs(r - rf), ds = abs(s - sf);
if (dq > dr && dq > ds) q = -r - s; else if (dr > ds) r = -q - s;
float2 v = p - float2(size * (1.7320508 * q + 0.8660254 * r), size * 1.5 * r);
- float m = max(abs(v.x), max(abs(0.5 * v.x + 0.8660254 * v.y), abs(0.5 * v.x - 0.8660254 * v.y)));
+ float a = v.x, b = 0.5 * v.x + 0.8660254 * v.y, c = 0.5 * v.x - 0.8660254 * v.y;
+ float m = abs(a); n = float2(a < 0.0 ? -1.0 : 1.0, 0.0);
+ if (abs(b) > m) { m = abs(b); n = (b < 0.0 ? -1.0 : 1.0) * float2(0.5, 0.8660254); }
+ if (abs(c) > m) { m = abs(c); n = (c < 0.0 ? -1.0 : 1.0) * float2(0.5, -0.8660254); }
return 0.8660254 * size - m;
}
-// Anti-aliased coverage (0..1) of a hex line widthPx pixels wide at mapM (metres east and north of the south-west corner):
-// fwidth turns the metre distance into pixels, so the line keeps its width at every zoom. Call it in uniform control flow
-// (outside any [branch]): fwidth needs the neighbouring pixels.
-float ScGridLine(float2 mapM, float widthPx)
+float ScHexEdgeDistance(float2 p, float size) { float2 n; return ScHexEdgeDistance(p, size, n); }
+
+// Box-filtered coverage (0..1) of a hex line widthPx pixels wide at mapM (metres east and north of the south-west corner);
+// footprintM returns the metres per pixel (the larger screen axis). The pixel's extent across the edge comes from the
+// derivatives of the continuous grid coordinate, projected on the edge's normal (Task 8 review I1: fwidth of the V-shaped
+// distance collapses on the line itself and broke it into dashes). Call it in uniform control flow (outside any [branch]).
+float ScGridLine(float2 mapM, float widthPx, out float footprintM)
{
- float d = ScHexEdgeDistance(float2(mapM.x, _ScMap.y - mapM.y), _ScMapOrigin.w);
- float aa = max(fwidth(d), 1e-3);
- return 1.0 - smoothstep(0.5 * widthPx * aa, (0.5 * widthPx + 1.0) * aa, d);
+ float2 p = float2(mapM.x, _ScMap.y - mapM.y);
+ float2 px = ddx(p), py = ddy(p);
+ footprintM = max(length(px), length(py));
+ float2 n;
+ float d = ScHexEdgeDistance(p, _ScMapOrigin.w, n);
+ float aa = max(length(float2(dot(px, n), dot(py, n))), 1e-3); // metres per pixel across the edge
+ return saturate(0.5 * widthPx + 0.5 - d / aa);
}
-// The grid as drawn on both the terrain and the skirt's sea: on/off, thinner towards the overview. Light lines on land and
-// water, as in the promo (ruling 2: the promo wins over M2's dark lines).
+// The grid as drawn on both the terrain and the skirt's sea: on/off, thinner towards the overview, and gone where a hex
+// is under about 10 px on screen (full from 30 px), so far hexes never form a wash. Light lines on land and water, as in
+// the promo (ruling 2: the promo wins over M2's dark lines).
static const float3 ScGridLandSrgb = float3(0.93, 0.90, 0.80);
static const float3 ScGridWaterSrgb = float3(0.82, 0.90, 0.95);
float ScGridAmount(float2 mapM, float3 positionWS)
{
- float fade = lerp(1.0, 0.6, saturate((length(_WorldSpaceCameraPos - positionWS) - 40000.0) / 200000.0));
- return ScGridLine(mapM, _ScGrid.z) * _ScGrid.w * fade;
+ float footprintM;
+ float cover = ScGridLine(mapM, _ScGrid.z, footprintM);
+ float fade = lerp(1.0, 0.35, saturate((length(_WorldSpaceCameraPos - positionWS) - 40000.0) / 200000.0));
+ fade *= saturate((_ScMapOrigin.w / max(footprintM, 1e-3) - 10.0) / 20.0);
+ return cover * _ScGrid.w * fade;
}
#endif
diff --git a/unity/Assets/Tests/EditMode/HexGridTests.cs b/unity/Assets/Tests/EditMode/HexGridTests.cs
index ee6a2e170..30a9bbfa6 100644
--- a/unity/Assets/Tests/EditMode/HexGridTests.cs
+++ b/unity/Assets/Tests/EditMode/HexGridTests.cs
@@ -12,15 +12,8 @@ public class HexGridTests
{
const float Size = 5000f;
- /// <summary>Track A's tilt-shift (merged later) blurs the top and bottom bands of every render; the width and colour
- /// renders here must not see it (task-3 carry, merge note m6). A no-op while the switch does not exist.</summary>
- internal static void TiltShift(bool on)
- {
- if (System.Linq.Enumerable.Contains(VisualToggles.Names, "tiltshift")) VisualToggles.Set("tiltshift", on);
- }
-
[TearDown]
- public void Reset() { TiltShift(true); EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear(); }
+ public void Reset() { RenderSample.TiltShift(true); EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear(); }
[Test]
public void CentresAreTheInradiusFromEveryEdgeAndCornersAndEdgesAreZero()
@@ -66,7 +59,7 @@ public class HexGridTests
var map = Object.FindFirstObjectByType<MapScene>(); map.Build();
var cam = Camera.main;
var rig = cam.GetComponent<CameraRig>();
- TiltShift(false);
+ RenderSample.TiltShift(false);
return (map, cam, rig);
}
@@ -111,9 +104,10 @@ public class HexGridTests
foreach (var distance in new[] { CameraController.MinDistance, CameraController.MaxDistance })
{
rig.LookAt = edgeMid; rig.Distance = distance; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();
- var on = RenderSample.Render(cam, 960, 540);
+ // At the game's 1920x1080: lines fade out by their hexes' size in pixels (Task 8 fix round 1, I2).
+ var on = RenderSample.Render(cam, 1920, 1080);
VisualToggles.Set("grid", false);
- var off = RenderSample.Render(cam, 960, 540);
+ var off = RenderSample.Render(cam, 1920, 1080);
VisualToggles.Set("grid", true);
float covered = RenderSample.FractionDarker(on, off, 0.02f) + RenderSample.FractionDarker(off, on, 0.02f);
TestContext.WriteLine($"{distance} m: grid covers {covered:P2}");
@@ -121,6 +115,86 @@ public class HexGridTests
}
}
+ /// <summary>Task 8 review I1, rendered at the gameplay03 pose (1920x1080): along one straight hex edge on the sea and one
+ /// on land, the line is about GridWidthPx wide (median full width at half maximum, across the line, 1 to 2.5 px; no
+ /// sample under 1 px) and, on the sea, never breaks (each sample's peak at least 0.7 of the edge's strongest). Both
+ /// opacities are set to 1 for the measurement, so the line's profile is measured, not its colour; differences are in
+ /// linear luma. The break check is on the sea only: its background is even, while a land line's peak also follows
+ /// the lit ground under it (0.54 along a land edge whose widths all lie in 1.4-2.0 px). Land and sea share ScGridLine.</summary>
+ [UnityTest]
+ public IEnumerator GridLinesAreUnbrokenAndAboutTheirWidthAtGameplay03()
+ {
+ var (map, cam, rig) = Open();
+ yield return null;
+ PromoPose.Gameplay03.Apply(rig, map.Frame);
+ rig.TopInset = 0; rig.Apply();
+ float size = map.Hexes.hex_size_km * 1000f, inradius = Mathf.Sqrt(3f) / 2f * size;
+ var origin = map.Terrain.transform.position;
+ HexJson? Find(double lon, double lat, System.Func<HexJson, bool> ok)
+ {
+ HexJson? best = null; double bestD = double.MaxValue;
+ foreach (var h in map.Hexes.hexes)
+ {
+ var east = System.Array.Find(map.Hexes.hexes, e => e.q == h.q + 1 && e.r == h.r);
+ if (east == null || !ok(h) || !ok(east)) continue;
+ double dd = (h.lon - lon) * (h.lon - lon) + (h.lat - lat) * (h.lat - lat);
+ if (dd < bestD) { bestD = dd; best = h; }
+ }
+ return best;
+ }
+ var edges = new[] { ("sea", Find(34.72, 32.02, h => h.biome == "sea")), ("land", Find(34.95, 32.0, h => h.land && h.biome != "lake")) };
+ const int W = 1920, H = 1080, N = 25;
+ try
+ {
+ foreach (var (what, hex) in edges)
+ {
+ Assert.IsNotNull(hex, what);
+ var c = HexGrid.Centre(hex!.q, hex.r, size);
+ var world = new Vector3[N + 2]; var px = new Vector2[N + 2];
+ Vector3 At(float t)
+ {
+ var w = HexGrid.ToWorld(new Vector2(c.x + inradius, c.y - size / 2f + t * size), origin, map.Frame.LengthM);
+ w.y = map.Terrain.SampleHeight(w) + origin.y;
+ return w;
+ }
+ for (int i = 0; i < N; i++) world[i] = At(0.1f + 0.8f * i / (N - 1));
+ world[N] = At(0f); world[N + 1] = At(1f);
+ Shader.SetGlobalVector(MapShaderGlobals.Grid, new Vector4(1f, 1f, MapShaderGlobals.GridWidthPx, 1f));
+ var on = RenderSample.Render(cam, W, H, world, px);
+ VisualToggles.Set("grid", false);
+ var off = RenderSample.Render(cam, W, H, world, px);
+ VisualToggles.Set("grid", true);
+ // Across the line: a horizontal profile is 1 / |n.x| times as wide as the line, n the line's screen normal.
+ var dir = (px[N + 1] - px[N]).normalized; float nx = Mathf.Abs(dir.y);
+ float Lin(Color s) => RenderSample.Luma(new Color(Mathf.GammaToLinearSpace(s.r), Mathf.GammaToLinearSpace(s.g), Mathf.GammaToLinearSpace(s.b)));
+ var peaks = new float[N]; var widths = new float[N];
+ for (int i = 0; i < N; i++)
+ {
+ int x0 = Mathf.RoundToInt(px[i].x), y0 = Mathf.RoundToInt(px[i].y);
+ var prof = new float[17];
+ for (int k = 0; k < 17; k++) prof[k] = Mathf.Max(0f, Lin(on.At(x0 + k - 8, y0)) - Lin(off.At(x0 + k - 8, y0)));
+ int m = 0; for (int k = 1; k < 17; k++) if (prof[k] > prof[m]) m = k;
+ float peak = prof[m], half = peak / 2f;
+ int l = m; while (l > 0 && prof[l - 1] >= half) l--;
+ int r = m; while (r < 16 && prof[r + 1] >= half) r++;
+ // Linear interpolation of the two half-maximum crossings.
+ float left = l > 0 ? l - (prof[l] - half) / Mathf.Max(prof[l] - prof[l - 1], 1e-6f) : l - 0.5f;
+ float right = r < 16 ? r + (prof[r] - half) / Mathf.Max(prof[r] - prof[r + 1], 1e-6f) : r + 0.5f;
+ peaks[i] = peak; widths[i] = (right - left) * nx;
+ }
+ float max = Mathf.Max(peaks), min = Mathf.Min(peaks);
+ var sorted = (float[])widths.Clone(); System.Array.Sort(sorted);
+ float median = sorted[N / 2];
+ TestContext.WriteLine($"{what} edge of ({hex.q}, {hex.r}): peak min {min:0.000} max {max:0.000} ratio {min / max:0.00}; FWHM median {median:0.00} px, range {sorted[0]:0.00}-{sorted[N - 1]:0.00} (|n.x| {nx:0.00})");
+ Assert.Greater(max, 0.02f, $"{what}: a line is drawn");
+ if (what == "sea") Assert.GreaterOrEqual(min / max, 0.7f, $"{what}: the line never breaks along the edge");
+ Assert.GreaterOrEqual(sorted[0], 1f, $"{what}: no sample along the edge is under a pixel wide");
+ Assert.That(median, Is.InRange(1f, 2.5f), $"{what}: the line is about {MapShaderGlobals.GridWidthPx} px wide");
+ }
+ }
+ finally { VisualToggles.Set("grid", true); }
+ }
+
[Test]
public void TheLineMeshAndItsMaterialAreGone()
{
diff --git a/unity/Assets/Tests/EditMode/MapTests.cs b/unity/Assets/Tests/EditMode/MapTests.cs
index 07f1b0a8e..09c04a310 100644
--- a/unity/Assets/Tests/EditMode/MapTests.cs
+++ b/unity/Assets/Tests/EditMode/MapTests.cs
@@ -105,9 +105,10 @@ public class MapTests
}
[Test]
- public void TerrainUsesFineLodSoTheCoarseSurfaceDoesNotCoverTheOverlay()
+ public void TerrainUsesFineLodSoTheCoarseSurfaceDoesNotCoverTheSelectionBand()
{
- // At the default heightmapPixelError (5) far cameras get a coarse LOD whose surface sits above the draped lines (K2).
+ // At the default heightmapPixelError (5) far cameras get a coarse LOD whose surface sits above draped geometry (K2);
+ // since visual v1 Task 8 that is the selection band (the hex grid is drawn by the terrain shader itself).
var terrainMat = TerrainMaterial();
var go = MapBuilder.Build(Paths.StreamingMap, HexesJson, terrainMat);
try { Assert.AreEqual(MapBuilder.TerrainPixelError, go.GetComponent<Terrain>().heightmapPixelError); Assert.AreEqual(1f, MapBuilder.TerrainPixelError); }
diff --git a/unity/Assets/Tests/EditMode/RenderSample.cs b/unity/Assets/Tests/EditMode/RenderSample.cs
index f8dfc5847..6039a2a70 100644
--- a/unity/Assets/Tests/EditMode/RenderSample.cs
+++ b/unity/Assets/Tests/EditMode/RenderSample.cs
@@ -45,6 +45,13 @@ public sealed class RenderSample
return sum / n;
}
+ /// <summary>Track A's tilt-shift blurs the top and bottom bands of every render; width and colour renders must not see
+ /// it (task-3 carry, merge note m6). A no-op while the switch does not exist.</summary>
+ public static void TiltShift(bool on)
+ {
+ if (System.Linq.Enumerable.Contains(Statecraft.Game.Map.VisualToggles.Names, "tiltshift")) Statecraft.Game.Map.VisualToggles.Set("tiltshift", on);
+ }
+
public static float Luma(Color c) => 0.2126f * c.r + 0.7152f * c.g + 0.0722f * c.b;
/// <summary>Mean |dL/dx| + |dL/dy| over the rows from y0 to y1 (fractions of the height, 0 = bottom): local contrast,
diff --git a/unity/Assets/Tests/EditMode/SettlementTests.cs b/unity/Assets/Tests/EditMode/SettlementTests.cs
index a07131558..9c301b3dd 100644
--- a/unity/Assets/Tests/EditMode/SettlementTests.cs
+++ b/unity/Assets/Tests/EditMode/SettlementTests.cs
@@ -350,12 +350,12 @@ public class MapSceneTests
// Visual v1 Task 8: the terrain shader draws the grid, light and faint as in the promo; the line shows if the
// corner's neighbourhood changes when the grid is switched off (tilt-shift off: a colour test, task-3 carry m6).
var cam = Camera.main; var px = new Vector2[1];
- HexGridTests.TiltShift(false);
+ RenderSample.TiltShift(false);
var on = RenderSample.Render(cam, 1600, 900, new[] { corner }, px);
VisualToggles.Set("grid", false);
var off = RenderSample.Render(cam, 1600, 900, new[] { corner }, px);
VisualToggles.Set("grid", true);
- HexGridTests.TiltShift(true);
+ RenderSample.TiltShift(true);
float change = 0f;
for (int dx = -2; dx <= 2; dx++)
for (int dy = -2; dy <= 2; dy++)
@@ -403,10 +403,13 @@ public class MapSceneTests
var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
var size = map.Terrain.terrainData.size;
// Visual v1 Task 8 (review I3): both sides draw the same hex grid; the lattice runs on past the edge and is
- // mirror-symmetric about it (x = 0 is a hex edge on odd rows). With the grid off, Task 7's check runs unchanged. With
- // it on, the same pairs and strip are checked, except the close strip at yaw 90/270 (logged, not asserted): there the
- // edge runs along the view, foreshortened, so the x = 0 hex line falls unequally into the two +-600 m patches (seen:
- // 0.014 at yaw 270, the near patch lighter). As in Task 7's re-review, yaw 0/180 test the strip at full sensitivity.
+ // mirror-symmetric about it. Every pair is checked with the grid off and on, at four yaws. Task 8 fix round 1 (M1):
+ // the close strips are centred on even hex rows, where x = 0 is a hex centre, so their +-600 m patches (five, 2 km
+ // apart along the edge) all lie over 2.2 km from any line; on an odd row the x = 0 hex line itself fell unequally
+ // into the two foreshortened patches at yaw 90/270.
+ float rowM = 1.5f * map.Hexes.hex_size_km * 1000f;
+ float EvenRowZ(float fromNorthM) => size.z - 2f * Mathf.Round(fromNorthM / rowM / 2f) * rowM;
+ float midZ = EvenRowZ(0.45f * size.z), northZ = EvenRowZ(2f * rowM);
// (The plan's one-row hex-centre pairs at x = +-4330 m were tried and dropped: at yaw 180 the middle-row pair differs
// by 0.027 with the grid off too, a warm view-dependent sun glint on the terrain side, not a grid or seam effect.)
try
@@ -417,8 +420,8 @@ public class MapSceneTests
var cases = new[] {
(new Vector3(3000, 0, size.z * 0.55f), new Vector3(2500, 0, size.z * 0.55f), new Vector3(-2500, 0, size.z * 0.55f)),
(new Vector3(3000, 0, size.z - 3000), new Vector3(2500, 0, size.z - 2500), new Vector3(-2500, 0, size.z + 2500)),
- (new Vector3(3000, 0, size.z * 0.55f), new Vector3(600, 0, size.z * 0.55f), new Vector3(-600, 0, size.z * 0.55f)),
- (new Vector3(3000, 0, size.z - 8000), new Vector3(600, 0, size.z - 8000), new Vector3(-600, 0, size.z - 8000)) };
+ (new Vector3(3000, 0, midZ), new Vector3(600, 0, midZ), new Vector3(-600, 0, midZ)),
+ (new Vector3(3000, 0, northZ), new Vector3(600, 0, northZ), new Vector3(-600, 0, northZ)) };
foreach (var yaw in new[] { 0f, 90f, 180f, 270f })
foreach (var (look, inside, beyond) in cases)
{
@@ -436,9 +439,8 @@ public class MapSceneTests
Color a = Color.clear, b = Color.clear;
for (int r = 0; r < rows; r++) { a += s.Mean((int)px[2 * r].x, (int)px[2 * r].y, 3) / rows; b += s.Mean((int)px[2 * r + 1].x, (int)px[2 * r + 1].y, 3) / rows; }
var diff = Mathf.Abs(a.r - b.r) + Mathf.Abs(a.g - b.g) + Mathf.Abs(a.b - b.b);
- bool logged = grid && close && (yaw == 90f || yaw == 270f);
- TestContext.WriteLine($"seam grid={grid} at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}, difference {diff:0.000}{(logged ? " (logged only)" : "")}");
- if (!logged) Assert.Less(diff, 0.012f, $"seam grid={grid} at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}");
+ TestContext.WriteLine($"seam grid={grid} at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}, difference {diff:0.000}");
+ Assert.Less(diff, 0.012f, $"seam grid={grid} at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}");
}
}
}
@@ -462,15 +464,15 @@ public class MapSceneTests
Assert.AreEqual(0.5f, cam.WorldToViewportPoint(rig.LookAt).y, 1e-3f, "the inset is undone");
}
- /// <summary>Playtest 1, item 10: the selected hex gets an outline in the highlight colour, draped on the terrain like
- /// the hex overlay (HexMath corners), drawn with the editor-made overlay material (no runtime material).</summary>
+ /// <summary>Playtest 1, item 10: the selected hex gets an outline in the highlight colour, draped on the terrain
+ /// (HexMath corners), drawn with its own editor-made material (no runtime material).</summary>
[Test]
public void SelectingAHexOutlinesItOnTheTerrain()
{
var map = NewMap(); map.Build();
var selection = Load(SelectionMatPath);
// Fix round 1, M2: its own editor-made material, whose shader pulls the band towards the camera in depth (Offset), so
- // the overlay lines under its edge cannot z-fight with it at long range.
+ // it cannot z-fight with the ground at long range.
Assert.AreEqual("Statecraft/HexSelection", selection.shader.name);
StringAssert.IsMatch(@"(?m)^\s*Offset\s+-\d+\s*,\s*-\d+", File.ReadAllText(AssetDatabase.GetAssetPath(selection.shader)));
Assert.Greater(selection.renderQueue, 2000, "drawn after the opaque terrain (queue Geometry+10)");