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 7 review round 1: full-width haze tests, a water-haze assert, a close seam strip, a running-mean skirt hold, land skips the water shading

eyalgolan9b09a9c89e00
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index a91aa5dd0..38073f27f 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -158,6 +158,35 @@ distance needs no smoothing (Task 5 carry). Plateau edge (diorama02): the Jordan
edge at the edge's broad height instead of sagging at once, as a flat muted band level with the map's eastern rim. A
faint low-contrast banding remains there at grazing angles.
+### Task 7 fix round 1
+- **Haze at full width (review I1, the Task 6 carry).**
+ - At diorama02, the haze toggle moves the far band 0.047 and the near band 0.002 over the full width. Task 6 measured
+ 0.023 / 0.026, with the sea and skirt unhazed. Restricted to the land column it was 0.069 / 0.026.
+ - So `TheHazeThickensWithDistance` and `TheHazeStartsBeyondTheNearestDioramaLandAndGrowsWithDistance` sample x 0..1
+ again. By distance: near 0.0019, mid 0.0212, far 0.0473.
+ - `TheOpenSeaStaysBlueUnderTheHaze` now asserts that the water haze applies. The open sea at about 300 km moves 0.059
+ in luma with the haze on, and 0.000 with `ScHazeWater` dropped on both sides (the red check).
+- **Seam test close pair (M1).**
+ - The pair sits at +-600 m across the edge. Each side is the mean of five 7x7 patches, 2 km apart along the edge,
+ because a single 1 km patch carries one wave cell or glint sparkle on its own (up to 0.012).
+ - A step of 5% on the skirt sea only within 1.5 km of the edge passes the +-2.5 km pairs (0.000) and fails the close
+ pair (0.015). All 16 lines are <= 0.004.
+- **Skirt hold (M4).**
+ - The hold is now a running mean over the edge's own samples (prefix sums, +-8 km). It replaces the 17 taps 1 km apart.
+ - East edge, spoke-to-spoke step 20 km out: 8.5 -> 5.2 m. What remains is the plateau's own trend along the edge.
+ - The test bound is under 0.18 x the edge's step.
+ - The faint grazing-angle banding in diorama02 is gone.
+- **Land skips the water shading (M3).** `[branch]` on `water > 0`.
+ - gameplay03 `all` minus `-water`: 0.03 ms before, 0.01 ms after. Both are inside the spreads, so there is no
+ measurable change on this GPU.
+ - Before, on the build at `6757168`: `PROFILE summary visual=all pose=gameplay03 runs=3 median_avg_ms=2.49 spread_ms=0.17`
+ and `visual=-water ... median_avg_ms=2.46 spread_ms=0.06`.
+ - After: `visual=all ... median_avg_ms=2.55 spread_ms=0.07`, `visual=-water ... median_avg_ms=2.54 spread_ms=0.02`;
+ diorama02 `all` 7.34 ms (before 7.38 ms).
+ - The earlier 0.68 ms water cost was run-to-run noise.
+- **Build and boot.** WebGL 77.1 MB, no `Shader error`. Boot `--cpu 1`: `map_build_ms` 469, `first_frame_ms` 3598
+ (budgets 743 / 5321).
+
## Checkpoints
| Task | Name | Images | Owner verdict |
|---|---|---|---|
@@ -165,3 +194,4 @@ faint low-contrast banding remains there at grazing angles.
| 6 | t06-terrain | captures/visual/t06-terrain/*-compare*.png, editor/*-compare*.png | (owner) |
| 6 (fix 1) | t06-terrain-r1 | captures/visual/t06-terrain-r1/*-compare*.png, hero06judea.png, hero06negev.png, editor/*-compare*.png | (owner) |
| 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) |
diff --git a/unity/Assets/Scripts/Map/MapBuilder.cs b/unity/Assets/Scripts/Map/MapBuilder.cs
index 0e4774f7b..248b9ae89 100644
--- a/unity/Assets/Scripts/Map/MapBuilder.cs
+++ b/unity/Assets/Scripts/Map/MapBuilder.cs
@@ -182,9 +182,10 @@ namespace Statecraft.Game.Map
public const float SeaToleranceM = 0.5f;
/// <summary>The land and sea past the map's edge (fix round 2, R2-1 and N1). Each edge sample continues outward: a sea
- /// sample stays flat at sea level (submesh 0, the sea material, lit like the terrain's sea, so no seam shows); a land
- /// sample falls from the edge's height to sea level (submesh 1, a muted land tone), so Sinai, Jordan and Lebanon read
- /// as land. A segment with a land end is land. Corner fans close the four corners. Every triangle lies outside the
+ /// sample stays flat at sea level (submesh 0, Sea.mat: the unlit Statecraft/Sea, shaded by the same ScWaterShade as the
+ /// terrain's own water, so no seam shows); a land sample meets the terrain's edge at ring 0, then holds the along-edge
+ /// mean of the edge's height (SkirtHoldSmoothingM) and eases to sea level by the last ring (SkirtFall; submesh 1, a
+ /// muted land tone), so Sinai, Jordan and Lebanon read as land. A segment with a land end is land. Corner fans close the four corners. Every triangle lies outside the
/// terrain's footprint, so nothing covers the map (the old full sea plane hid all land below about -10 m).</summary>
public static Mesh BuildBorderSkirt(TerrainData data, float elevMinM, MapRuntimeAssets assets)
{
@@ -195,18 +196,26 @@ namespace Statecraft.Game.Map
int samples = data.heightmapResolution - 1;
var verts = new List<Vector3>(); var sea = new List<int>(); var land = new List<int>();
bool IsLand(float h) => Mathf.Abs(h / VerticalExaggeration + elevMinM) > SeaToleranceM;
- // The edge's height averaged along the edge over +-SkirtHoldSmoothingM (17 samples, clamped to the map).
- float Held(Vector2 p, Vector2 outward)
+ // The edge's heights and their running mean over +-SkirtHoldSmoothingM of the edge's own samples (prefix sums; the
+ // window is cut short at the edge's ends). Every sample counts, so no ridge between taps aliases (fix round 1, M4).
+ float[] HeldAlong(Vector2 a, Vector2 b, float[] h)
{
- var along = new Vector2(outward.y, -outward.x);
- float sum = 0f;
- for (int j = -8; j <= 8; j++) sum += Height(p + along * (SkirtHoldSmoothingM * j / 8f));
- return sum / 17f;
+ for (int i = 0; i <= samples; i++) h[i] = Height(Vector2.Lerp(a, b, (float)i / samples));
+ var sum = new double[samples + 2];
+ for (int i = 0; i <= samples; i++) sum[i + 1] = sum[i] + h[i];
+ int w = Mathf.Max(1, Mathf.RoundToInt(SkirtHoldSmoothingM / ((b - a).magnitude / samples)));
+ var held = new float[samples + 1];
+ for (int i = 0; i <= samples; i++)
+ {
+ int lo = Mathf.Max(0, i - w), hi = Mathf.Min(samples, i + w);
+ held[i] = (float)((sum[hi + 1] - sum[lo]) / (hi - lo + 1));
+ }
+ return held;
}
- // One ring of vertices outward from an edge point; returns the index of its first vertex.
- int Spoke(Vector2 p, Vector2 outward, bool isLand, Vector2? outward2 = null)
+ // One ring of vertices outward from an edge point (h its height, held the height the rings past it hold); returns
+ // the index of its first vertex.
+ int Spoke(Vector2 p, float h, float held, Vector2 outward, bool isLand, Vector2? outward2 = null)
{
- float h = Height(p), held = isLand ? Held(p, outward) : seaY;
int first = verts.Count;
for (int k = 0; k < SkirtRings.Length; k++)
{
@@ -240,14 +249,17 @@ namespace Statecraft.Game.Map
(new Vector2(size.x, size.z), new Vector2(0, size.z), Vector2.up), // north
(new Vector2(0, size.z), new Vector2(0, 0), Vector2.left), // west
};
- foreach (var (a, b, n) in edges)
+ var heights = new float[edges.Length][]; var helds = new float[edges.Length][];
+ for (int e = 0; e < edges.Length; e++) { heights[e] = new float[samples + 1]; helds[e] = HeldAlong(edges[e].a, edges[e].b, heights[e]); }
+ for (int e = 0; e < edges.Length; e++)
{
+ var (a, b, n) = edges[e];
int prev = -1; bool prevLand = false;
for (int i = 0; i <= samples; i++)
{
var p = Vector2.Lerp(a, b, (float)i / samples);
- bool isLand = IsLand(Height(p));
- int spoke = Spoke(p, n, isLand);
+ bool isLand = IsLand(heights[e][i]);
+ int spoke = Spoke(p, heights[e][i], helds[e][i], n, isLand);
if (prev >= 0) Quad(prevLand || isLand ? land : sea, prev, spoke);
prev = spoke; prevLand = isLand;
}
@@ -256,8 +268,10 @@ namespace Statecraft.Game.Map
for (int e = 0; e < edges.Length; e++)
{
var corner = edges[e].b; var n1 = edges[e].n; var n2 = edges[(e + 1) % edges.Length].n;
- bool isLand = IsLand(Height(corner));
- int s1 = Spoke(corner, n1, isLand), sd = Spoke(corner, n1, isLand, n2), s2 = Spoke(corner, n2, isLand);
+ int e2 = (e + 1) % edges.Length;
+ float h = heights[e][samples], held1 = helds[e][samples], held2 = helds[e2][0]; // the corner ends edge e, starts e2
+ bool isLand = IsLand(h);
+ int s1 = Spoke(corner, h, held1, n1, isLand), sd = Spoke(corner, h, 0.5f * (held1 + held2), n1, isLand, n2), s2 = Spoke(corner, h, held2, n2, isLand);
Quad(isLand ? land : sea, s1, sd); Quad(isLand ? land : sea, sd, s2);
}
var mesh = assets.Own(new Mesh { name = "BorderSkirt", indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 });
diff --git a/unity/Assets/Shaders/StatecraftTerrain.hlsl b/unity/Assets/Shaders/StatecraftTerrain.hlsl
index ab4264211..8bcda7215 100644
--- a/unity/Assets/Shaders/StatecraftTerrain.hlsl
+++ b/unity/Assets/Shaders/StatecraftTerrain.hlsl
@@ -22,7 +22,10 @@ void StatecraftTerrain_float(float2 UV, float3 PositionWS, float3 NormalWS, Unit
// fully occluded surface, so Lit adds nothing (no diffuse, specular colour 0, indirect light times occlusion 0): exactly
// what Sea.shader returns past the edge. Land keeps its after-lighting haze through the same Emission.
float elevM = (PositionWS.y - _ScMap.z) / _ScMap.w;
- float3 waterColour = ScHazeWater(ScWaterShade(coast, elevM, PositionWS, mapM), PositionWS);
+ // Land pixels (water 0, spatially coherent) skip the water shading: its noise and second shadow lookup would only be
+ // multiplied away (Task 7 fix round 1, M3).
+ float3 waterColour = 0;
+ [branch] if (water > 0.0) waterColour = ScHazeWater(ScWaterShade(coast, elevM, PositionWS, mapM), PositionWS);
BaseColor = ground * (1.0 - h) * (1.0 - water);
NormalOut = normalize(lerp(n, float3(0, 1, 0), water));
Occlusion = lerp(lerp(1.0, ao, 0.8), 0.0, water);
diff --git a/unity/Assets/Tests/EditMode/SeaTests.cs b/unity/Assets/Tests/EditMode/SeaTests.cs
index e12aa9c2f..be50d1856 100644
--- a/unity/Assets/Tests/EditMode/SeaTests.cs
+++ b/unity/Assets/Tests/EditMode/SeaTests.cs
@@ -65,7 +65,10 @@ public class SeaTests
/// <summary>Task 7 checkpoint finding: holding each edge vertex's own height for 20 km drew the edge's ridges out as long
/// stripes across the Jordan skirt. Along the east edge, the held ring 2 is far smoother from spoke to spoke than the
- /// edge (ring 0, which meets the terrain exactly).</summary>
+ /// edge (ring 0, which meets the terrain exactly). Fix round 1 (review M4): the hold is a running mean over the edge's
+ /// own samples, not 17 taps 1 km apart that undersampled ridges shorter than about 2 km: under 18% of the edge's step.
+ /// What a +-8 km mean keeps is the plateau's own trend along the edge (about 400 m of exaggerated height over 16 km, over
+ /// a 77-sample window: 5.2 m per spoke); the 17 taps added their aliasing on top (8.5 m).</summary>
[Test]
public void TheHeldSkirtCarriesThePlateauNotTheEdgesRidges()
{
@@ -84,7 +87,7 @@ public class SeaTests
}
TestContext.WriteLine($"east edge: {pairs} spoke pairs, mean step at the edge {edge / pairs:0.0} m, held 20 km out {held / pairs:0.0} m");
Assert.Greater(pairs, 500);
- Assert.Less(held, 0.25f * edge, "the held rings carry the plateau's broad height, not the edge's ridges");
+ Assert.Less(held, 0.18f * edge, "the held rings carry the plateau's broad height, not the edge's ridges (no aliasing)");
}
static float Luma(Color c) => RenderSample.Luma(c);
@@ -143,7 +146,9 @@ public class SeaTests
}
/// <summary>Review I2: at the country-wide pose (about 300 km from the camera) the open sea stays saturated blue under the
- /// water haze: b > r + 0.15 (worked out in Step 4: about 0.21 before the grade). And the water toggle exists.</summary>
+ /// water haze: b > r + 0.15 (worked out in Step 4: about 0.21 before the grade). And the water toggle exists. Fix round
+ /// 1 (review I1): the water haze applies at all: with the haze off the same sample moves by more than 0.01 in luma
+ /// (about 0.18 x 0.33 of the way to the cool water haze at about 300 km).</summary>
[UnityTest]
public IEnumerator TheOpenSeaStaysBlueUnderTheHaze()
{
@@ -156,7 +161,12 @@ public class SeaTests
var px = new Vector2[1];
var s = RenderSample.Render(cam, 960, 540, new[] { sea }, px);
var c = s.Mean((int)px[0].x, (int)px[0].y, 2);
- TestContext.WriteLine($"open sea at the diorama pose {c}, b - r = {c.b - c.r:0.000}");
+ VisualToggles.Set("haze", false);
+ var clear = RenderSample.Render(cam, 960, 540, new[] { sea }, px);
+ VisualToggles.Set("haze", true);
+ var c0 = clear.Mean((int)px[0].x, (int)px[0].y, 2);
+ TestContext.WriteLine($"open sea at the diorama pose {c}, b - r = {c.b - c.r:0.000}; haze off {c0}, luma shift {Luma(c) - Luma(c0):0.000}");
Assert.Greater(c.b, c.r + 0.15f);
+ Assert.Greater(Mathf.Abs(Luma(c) - Luma(c0)), 0.01f, "the water haze moves the far open sea");
}
}
diff --git a/unity/Assets/Tests/EditMode/SettlementTests.cs b/unity/Assets/Tests/EditMode/SettlementTests.cs
index 3a70edc16..7fe5febe4 100644
--- a/unity/Assets/Tests/EditMode/SettlementTests.cs
+++ b/unity/Assets/Tests/EditMode/SettlementTests.cs
@@ -377,7 +377,10 @@ public class MapSceneTests
public System.Collections.IEnumerator TheSeaBeyondTheEdgeMatchesTheTerrainSea()
{
// Visual v1 Task 7: both sides now shade with StatecraftMap.hlsl ScWaterShade, whose waves vary over a few hundred
- // metres, so 7x7-pixel patch means are compared (still 0.012), at four yaws (Review Focus 1).
+ // metres, so 7x7-pixel patch means are compared (still 0.012), at four yaws (Review Focus 1). Task 7 fix round 1 (M1):
+ // a close pair at +-600 m straddles the edge too, so a step at the edge is told from a view-dependent gradient. Each
+ // side of the close pair is the mean of five such patches 2 km apart along the edge: a step at the edge runs along
+ // all of it, while a single 1 km patch still carries one wave cell or glint sparkle (up to 0.012 on its own).
EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
var map = Object.FindFirstObjectByType<MapScene>();
map.Build();
@@ -387,16 +390,26 @@ public class MapSceneTests
foreach (var yaw in new[] { 0f, 90f, 180f, 270f })
foreach (var (look, inside, beyond) in 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 - 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)) })
{
rig.LookAt = look; rig.Distance = 120000f; rig.Yaw = yaw; rig.TopInset = 0; rig.Apply();
var y = map.Terrain.SampleHeight(inside);
- var px = new Vector2[2];
- var s = RenderSample.Render(cam, 1600, 900, new[] { new Vector3(inside.x, y, inside.z), new Vector3(beyond.x, y, beyond.z) }, px);
- Color a = s.Mean((int)px[0].x, (int)px[0].y, 3), b = s.Mean((int)px[1].x, (int)px[1].y, 3);
+ bool close = Mathf.Abs(inside.x) < 1000f;
+ int rows = close ? 5 : 1;
+ var world = new Vector3[2 * rows]; var px = new Vector2[2 * rows];
+ for (int r = 0; r < rows; r++)
+ {
+ float dz = (r - (rows - 1) / 2f) * 2000f;
+ world[2 * r] = new Vector3(inside.x, y, inside.z + dz); world[2 * r + 1] = new Vector3(beyond.x, y, beyond.z + dz);
+ }
+ var s = RenderSample.Render(cam, 1600, 900, world, px);
+ 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);
- TestContext.WriteLine($"seam at {look}, yaw {yaw}: terrain sea {a}, beyond {b}, difference {diff:0.000}");
- Assert.Less(diff, 0.012f, $"seam at {look}, yaw {yaw}: terrain sea {a}, beyond {b}");
+ TestContext.WriteLine($"seam at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}, difference {diff:0.000}");
+ Assert.Less(diff, 0.012f, $"seam at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}");
}
}
diff --git a/unity/Assets/Tests/EditMode/TerrainShaderTests.cs b/unity/Assets/Tests/EditMode/TerrainShaderTests.cs
index c2c6e76be..49503bcd9 100644
--- a/unity/Assets/Tests/EditMode/TerrainShaderTests.cs
+++ b/unity/Assets/Tests/EditMode/TerrainShaderTests.cs
@@ -172,10 +172,10 @@ public class TerrainShaderTests
finally { mat.SetTexture("_ScBakeTex", real); mat.SetTexture("_ScAoTex", realAo); Object.DestroyImmediate(neutral); }
}
- /// <summary>Rendered at the country-wide pose: the haze moves the far (top) band more than the near (bottom) band. Both
- /// bands are sampled in the column x 0.45..0.6, which is the map's land from top to bottom at this pose: in Task 6 only
- /// the land carries haze, and across the full width the far band is mostly the Mediterranean and the border skirt
- /// (no haze until Task 7), which hid the effect (full width: far 0.023, near 0.026; land column: far 0.069, near 0.026).</summary>
+ /// <summary>Rendered at the country-wide pose: the haze moves the far (top) band more than the near (bottom) band, across
+ /// the full width. Task 6 sampled only the land column x 0.45..0.6, because then only the land carried haze and the far
+ /// band's sea and border skirt hid the effect (full width: far 0.023, near 0.026). Since Task 7 the sea on both sides
+ /// takes the water haze, so the full width is measured again (Task 7 fix round 1).</summary>
[UnityTest]
public IEnumerator TheHazeThickensWithDistance()
{
@@ -185,7 +185,7 @@ public class TerrainShaderTests
PromoPose.Diorama02.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();
VisualToggles.Set("haze", false); var clear = RenderSample.Render(cam, 480, 270);
VisualToggles.Set("haze", true); var hazy = RenderSample.Render(cam, 480, 270);
- const float x0 = 0.45f, x1 = 0.6f;
+ const float x0 = 0f, x1 = 1f;
float far = Mathf.Abs(hazy.MeanLuma(x0, 0.8f, x1, 0.95f) - clear.MeanLuma(x0, 0.8f, x1, 0.95f));
float near = Mathf.Abs(hazy.MeanLuma(x0, 0.05f, x1, 0.2f) - clear.MeanLuma(x0, 0.05f, x1, 0.2f));
TestContext.WriteLine($"haze shift far {far:0.000}, near {near:0.000}");
@@ -194,7 +194,7 @@ public class TerrainShaderTests
/// <summary>Review I1: the haze is a depth cue, not a veil. At the country-wide pose the nearest land (bottom band,
/// about 205 km away) is inside the haze's start distance and barely moves; the middle and far bands move more and
- /// more. Land column x 0.45..0.6, as in TheHazeThickensWithDistance.</summary>
+ /// more. Full width, as in TheHazeThickensWithDistance (Task 7 fix round 1: the sea is hazed too).</summary>
[UnityTest]
public IEnumerator TheHazeStartsBeyondTheNearestDioramaLandAndGrowsWithDistance()
{
@@ -204,7 +204,7 @@ public class TerrainShaderTests
PromoPose.Diorama02.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();
VisualToggles.Set("haze", false); var clear = RenderSample.Render(cam, 480, 270);
VisualToggles.Set("haze", true); var hazy = RenderSample.Render(cam, 480, 270);
- float Shift(float y0, float y1) => Mathf.Abs(hazy.MeanLuma(0.45f, y0, 0.6f, y1) - clear.MeanLuma(0.45f, y0, 0.6f, y1));
+ float Shift(float y0, float y1) => Mathf.Abs(hazy.MeanLuma(0f, y0, 1f, y1) - clear.MeanLuma(0f, y0, 1f, y1));
float near = Shift(0.05f, 0.2f), mid = Shift(0.425f, 0.575f), far = Shift(0.8f, 0.95f);
TestContext.WriteLine($"haze by distance near {near:0.0000}, mid {mid:0.0000}, far {far:0.0000}");
Assert.Less(near, 0.008f, "about no haze at the nearest land");