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.

Map: a walnut frame and a dark table round the board at the overview (refs #36) (#525)

Eyal Golan58d7b5d87152
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 549d82c58..16a3f059d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
## [Unreleased]
### Added
+- The map's frame (refs #36, promo 02): at the overview the board now ends in a walnut frame on a dark wooden table,
+ with a bevel of cut earth where the relief stands above the frame and the frame's lip where the sea and low coast meet
+ it. It replaces the border skirt's flat tan slab and the sea past the map's edge. At 16:9 only the overview shows it (the
+ camera fit of #174 keeps it off screen wherever the view is no wider than the map: below about 106 km at 16:9, 53 km
+ at 32:9; a portrait window never shows it); one draw call, no shadow pass, no golden moves.
- GDD v0.1 Phase 1, training (refs #377), behind the `systems.loop` switch: `Train` sends a city's civilians without work
to basic training in a military camp (recruits, a count) or pioneer training in a Hakhshara (halutzim, movable units at
the city's hex), paid from the Treasury without borrowing; `CancelTraining` returns the people but not the Money (D-A3).
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index 06a2d8944..a17715fa4 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -1652,6 +1652,13 @@ Each item below was ruled to the art track (controller, rank 10). None blocks la
the terrain's (0.82, 0.69, 0.43), so the step shrank, but the skirt is 17% of diorama02 and its saturation rose 0.34 ->
0.47. That took the frame to saturation 0.488 against the 0.48 bar (warmth 0.129). Do not move the bar to exclude the
skirt. The earlier line saying a lower-chroma colour is the next candidate is withdrawn.
+ **Done in #36 (frame round the map).** The skirt is gone: the board ends in a bevel (cut earth where the edge stands
+ above the frame, the frame's lip where the sea and the low coast meet it), a walnut frame and a dark wooden table
+ (`MapBuilder.BuildFrame`, `MapFrame.shader`). The frame and table read the haze at sea level or higher (at world y 0 the
+ rift boost made it 1.6x), and the table takes 0.4 of that; the full haze lifted it to a flat khaki. WebGL diorama02
+ against main (c2774ecc, with #502's olives): saturation 0.405 -> 0.359, contrast 0.173 -> 0.222 (promo 0.200), warmth
+ 0.118 -> 0.129 (bar 0.087-0.145). gameplay03 and both hero shots: no land pixel moves by more than 3/255; 1 sea pixel
+ of gameplay03 moves by up to 13/255 (the water's own clock, unpinned in the player). The sea no longer runs past the map's west edge, so the sea-seam tests went with the skirt.
2. **Settlement markers float.** At the web shadow texel (about 100 m at 60 km with a 2048 map) the markers (symbolic
scale, 300-700 m) show long detached shadows, so they look as if they hover. Set the sun's shadow bias (depth and normal
bias) at kit scale: offsets of about 100-150 m at that texel. Do not just turn marker shadows off.
diff --git a/unity/Assets/Editor/MapCapture.cs b/unity/Assets/Editor/MapCapture.cs
index c2e1039b3..1117a11a3 100644
--- a/unity/Assets/Editor/MapCapture.cs
+++ b/unity/Assets/Editor/MapCapture.cs
@@ -31,7 +31,7 @@ public static class MapCapture
var scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var controller = Camera.main.gameObject.AddComponent<CameraController>(); // adds the CameraRig it requires
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load(MapMaterials.TerrainPath), Load(MapMaterials.MarkerPath), Load(MapMaterials.SelectionPath), Load(MapMaterials.SeaPath), Load(MapMaterials.BorderLandPath));
+ map.Configure(Load(MapMaterials.TerrainPath), Load(MapMaterials.MarkerPath), Load(MapMaterials.SelectionPath), Load(MapMaterials.SeaPath), Load(MapMaterials.FramePath));
map.ConfigureKits(Load(MapMaterials.KitPath), Load(MapMaterials.TreePath));
var boot = new GameObject("Boot").AddComponent<GameBoot>();
boot.Configure(map);
diff --git a/unity/Assets/Editor/MapMaterials.cs b/unity/Assets/Editor/MapMaterials.cs
index d364a7b42..f4d0ee2ae 100644
--- a/unity/Assets/Editor/MapMaterials.cs
+++ b/unity/Assets/Editor/MapMaterials.cs
@@ -13,7 +13,7 @@ namespace Statecraft.Game.EditorTools
public const string MarkerPath = Folder + "/SettlementMarker.mat";
public const string SelectionPath = Folder + "/HexSelection.mat";
public const string SeaPath = Folder + "/Sea.mat";
- public const string BorderLandPath = Folder + "/BorderLand.mat";
+ public const string FramePath = Folder + "/MapFrame.mat";
public const string KitPath = Folder + "/Kit.mat";
public const string TreePath = Folder + "/Tree.mat";
@@ -36,16 +36,13 @@ namespace Statecraft.Game.EditorTools
EditorUtility.SetDirty(marker);
// The selected hex's outline: its own shader (Assets/Shaders/HexSelection.shader) with a depth offset (fix round 1, M2).
Make(SelectionPath, "Statecraft/HexSelection", Statecraft.Game.Map.MapScene.SelectionColour);
- // The skirt's sea past the map's edge: the terrain's own water shading (StatecraftMap.hlsl ScWaterShade), so no seam.
+ // The water: MapScene's TerrainWater draws with a copy of it (StatecraftMap.hlsl ScWaterShade).
var sea = Make(SeaPath, "Statecraft/Sea", null);
sea.SetTexture("_ScCoastTex", Tex(Statecraft.Game.Map.MapTexturePaths.Coast));
EditorUtility.SetDirty(sea);
- // Neighbouring land past the map's edge (Sinai, Jordan, Lebanon): one muted land tone, lit and matte like the sea
- // (fix round 2, R2-1).
- var land = Make(BorderLandPath, "Universal Render Pipeline/Lit", Statecraft.Game.Map.MapBuilder.BorderLandColour);
- land.SetFloat("_Smoothness", 0f); land.SetFloat("_Metallic", 0f);
- land.SetFloat("_SpecularHighlights", 1f); land.SetFloat("_EnvironmentReflections", 1f);
- EditorUtility.SetDirty(land);
+ // The frame round the map and the table beyond it (issue #36): Assets/Shaders/MapFrame.shader, its albedos in the
+ // mesh's vertex colours (MapBuilder.BuildFrame).
+ Make(FramePath, "Statecraft/MapFrame", null);
// Settlement kits and trees (art spike): Assets/Shaders/Kit.shader. Buildings are merged static meshes (no tint
// jitter: each building's colour is in its vertices); trees are GPU-instanced and get a per-instance tint.
var kit = Make(KitPath, "Statecraft/Kit", Color.white);
diff --git a/unity/Assets/Map.unity b/unity/Assets/Map.unity
index 5ca5daeaf..de3e40e38 100644
--- a/unity/Assets/Map.unity
+++ b/unity/Assets/Map.unity
@@ -383,7 +383,7 @@ MonoBehaviour:
markerMaterial: {fileID: 2100000, guid: 7c65bbd4355344f1990495c458323a4e, type: 2}
selectionMaterial: {fileID: 2100000, guid: 6116b1f8c72b244e0a9556c2cdb6b1c5, type: 2}
seaMaterial: {fileID: 2100000, guid: 5bb451931546c49d6b2fe35726d07cfd, type: 2}
- borderLandMaterial: {fileID: 2100000, guid: ed41bb6e0c8274066b408da9b1f5bef2, type: 2}
+ frameMaterial: {fileID: 2100000, guid: 556bff8d7fd140779e0903044df5cd10, type: 2}
kitMaterial: {fileID: 2100000, guid: 24c1cceae1b22492e9c9f2be7c1a6b5e, type: 2}
treeMaterial: {fileID: 2100000, guid: 2dd15539298814dafa803cdbc57e2426, type: 2}
terrainWaterMesh: {fileID: 4900000, guid: 51f85aaa1270842658cbc02738ff8df2, type: 3}
diff --git a/unity/Assets/Materials/BorderLand.mat b/unity/Assets/Materials/BorderLand.mat
deleted file mode 100644
index 117aa1628..000000000
--- a/unity/Assets/Materials/BorderLand.mat
+++ /dev/null
@@ -1,137 +0,0 @@
-%YAML 1.1
-%TAG !u! tag:unity3d.com,2011:
---- !u!114 &-4358778686204817034
-MonoBehaviour:
- m_ObjectHideFlags: 11
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 0}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
- m_Name:
- m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
- version: 10
---- !u!21 &2100000
-Material:
- serializedVersion: 8
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_Name: BorderLand
- m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
- m_Parent: {fileID: 0}
- m_ModifiedSerializedProperties: 0
- m_ValidKeywords: []
- m_InvalidKeywords: []
- m_LightmapFlags: 4
- m_EnableInstancingVariants: 1
- m_DoubleSidedGI: 0
- m_CustomRenderQueue: -1
- stringTagMap:
- RenderType: Opaque
- disabledShaderPasses:
- - MOTIONVECTORS
- m_LockedProperties:
- m_SavedProperties:
- serializedVersion: 3
- m_TexEnvs:
- - _BaseMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _BumpMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _DetailAlbedoMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _DetailMask:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _DetailNormalMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _EmissionMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _MainTex:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _MetallicGlossMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _OcclusionMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _ParallaxMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - _SpecGlossMap:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - unity_Lightmaps:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - unity_LightmapsInd:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- - unity_ShadowMasks:
- m_Texture: {fileID: 0}
- m_Scale: {x: 1, y: 1}
- m_Offset: {x: 0, y: 0}
- m_Ints: []
- m_Floats:
- - _AddPrecomputedVelocity: 0
- - _AlphaClip: 0
- - _AlphaToMask: 0
- - _Blend: 0
- - _BlendModePreserveSpecular: 1
- - _BumpScale: 1
- - _ClearCoatMask: 0
- - _ClearCoatSmoothness: 0
- - _Cull: 2
- - _Cutoff: 0.5
- - _DetailAlbedoMapScale: 1
- - _DetailNormalMapScale: 1
- - _DstBlend: 0
- - _DstBlendAlpha: 0
- - _EnvironmentReflections: 1
- - _GlossMapScale: 0
- - _Glossiness: 0
- - _GlossyReflections: 0
- - _Metallic: 0
- - _OcclusionStrength: 1
- - _Parallax: 0.005
- - _QueueOffset: 0
- - _ReceiveShadows: 1
- - _Smoothness: 0
- - _SmoothnessTextureChannel: 0
- - _SpecularHighlights: 1
- - _SrcBlend: 1
- - _SrcBlendAlpha: 1
- - _Surface: 0
- - _WorkflowMode: 1
- - _XRMotionVectorsPass: 1
- - _ZWrite: 1
- m_Colors:
- - _BaseColor: {r: 0.6, g: 0.56, b: 0.46, a: 1}
- - _Color: {r: 0.6, g: 0.56, b: 0.45999992, a: 1}
- - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- m_BuildTextureStacks: []
- m_AllowLocking: 1
diff --git a/unity/Assets/Materials/MapFrame.mat b/unity/Assets/Materials/MapFrame.mat
new file mode 100644
index 000000000..70de674b5
--- /dev/null
+++ b/unity/Assets/Materials/MapFrame.mat
@@ -0,0 +1,31 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+ serializedVersion: 8
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_Name: MapFrame
+ m_Shader: {fileID: 4800000, guid: b0a34f85aacb4ec1a2458fd21122e774, type: 3}
+ m_Parent: {fileID: 0}
+ m_ModifiedSerializedProperties: 0
+ m_ValidKeywords: []
+ m_InvalidKeywords: []
+ m_LightmapFlags: 4
+ m_EnableInstancingVariants: 1
+ m_DoubleSidedGI: 0
+ m_CustomRenderQueue: -1
+ stringTagMap: {}
+ disabledShaderPasses: []
+ m_LockedProperties:
+ m_SavedProperties:
+ serializedVersion: 3
+ m_TexEnvs: []
+ m_Ints: []
+ m_Floats:
+ - _Grain: 1
+ m_Colors: []
+ m_BuildTextureStacks: []
+ m_AllowLocking: 1
diff --git a/unity/Assets/Materials/BorderLand.mat.meta b/unity/Assets/Materials/MapFrame.mat.meta
similarity index 79%
rename from unity/Assets/Materials/BorderLand.mat.meta
rename to unity/Assets/Materials/MapFrame.mat.meta
index 8db72ce39..3f99d5c4c 100644
--- a/unity/Assets/Materials/BorderLand.mat.meta
+++ b/unity/Assets/Materials/MapFrame.mat.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: ed41bb6e0c8274066b408da9b1f5bef2
+guid: 556bff8d7fd140779e0903044df5cd10
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.cs
index 974a46def..2b4c71409 100644
--- a/unity/Assets/Scripts/Map/CameraController.cs
+++ b/unity/Assets/Scripts/Map/CameraController.cs
@@ -20,8 +20,9 @@ namespace Statecraft.Game.Map
/// While the pointer is over the UI (IsOverUi, wired by the scene) the wheel and the drag belong to the UI; keyboard pan
/// and orbit still move the camera (plan amendment A4). Pan speed scales with
/// distance, zoom is clamped to [MinDistance, MaxDistance], and the view stays on the map (issue #174): the look-at
- /// point is held far enough inside the map that the visible ground does not leave it, so the border skirt never fills
- /// the view at gameplay zoom. Where the view is wider than the map (the overview), it is centred on the map instead.
+ /// point is held far enough inside the map that the visible ground does not leave it, so the frame round the map (issue #36) shows
+ /// nowhere the view is no wider than the map. Where the view is wider than the map, it is centred on the map instead
+ /// and the frame shows at its sides: at 16:9 from about 106 km (yaw 0), at 32:9 from about 53 km, never in portrait.
/// Given the ground's height (Ground), the camera also never sinks into the terrain (MinClearanceShare).</summary>
[RequireComponent(typeof(CameraRig))]
public sealed class CameraController : MonoBehaviour
@@ -47,7 +48,7 @@ namespace Statecraft.Game.Map
public Rect Bounds = new Rect(0, 0, float.MaxValue, float.MaxValue);
/// <summary>The ground's world height at a point (x, z), or null for none (the camera then keeps to y = 0).</summary>
public Func<Vector2, float>? Ground;
- /// <summary>The highest the ground (and the border skirt, which holds the edge's height) reaches in world y: with it,
+ /// <summary>The highest the ground (and the frame round the map, which stays below it) reaches in world y: with it,
/// ViewFootprint bounds the near side of the view tightly. ShadowFit.GroundY (the default) means flat ground.</summary>
public float GroundTop = ShadowFit.GroundY;
@@ -79,7 +80,7 @@ namespace Statecraft.Game.Map
}
/// <summary>Fits the rig's current pose with no input (review B-m3: a minimap jump goes through the same view fit and
- /// ground clearance as panning, so no frame shows the skirt or the inside of a hill).</summary>
+ /// ground clearance as panning, so no frame shows the map's frame or the inside of a hill).</summary>
public void Settle() => Step(GetComponent<CameraRig>(), default, 0f, Bounds, Ground, GroundTop);
public static float ClampDt(float dt) => Mathf.Min(dt, MaxFrameSeconds);
@@ -137,8 +138,8 @@ namespace Statecraft.Game.Map
rig.Apply();
}
- /// <summary>The terrain's world height at (x, z), clamped to its edge outside it (the border skirt holds the edge's
- /// height near the map, so the camera keeps clear of it too).</summary>
+ /// <summary>The terrain's world height at (x, z), clamped to its edge outside it (the camera keeps clear of the
+ /// edge's height past the map too).</summary>
public static Func<Vector2, float> GroundOf(Terrain terrain)
{
var origin = terrain.transform.position; var size = terrain.terrainData.size;
@@ -159,8 +160,8 @@ namespace Statecraft.Game.Map
/// <summary>Corners of the visible map area in viewport units: the top inset's band is covered by the UI.</summary>
static readonly Vector2[] FootprintCorners = { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f) };
- /// <summary>The terrain's highest world y (TerrainData.bounds holds the heightmap's actual range); the border skirt
- /// never rises above its edge, so this bounds it too.</summary>
+ /// <summary>The terrain's highest world y (TerrainData.bounds holds the heightmap's actual range); the frame round
+ /// the map (issue #36) stays below it, so this bounds it too.</summary>
public static float GroundTopOf(Terrain terrain) => terrain.transform.position.y + terrain.terrainData.bounds.max.y;
/// <summary>The ground the rig's camera shows, as offsets (x, z) from the look-at point. Every ground point the view
diff --git a/unity/Assets/Scripts/Map/MapBuilder.cs b/unity/Assets/Scripts/Map/MapBuilder.cs
index 66580b4bd..2bc38edb6 100644
--- a/unity/Assets/Scripts/Map/MapBuilder.cs
+++ b/unity/Assets/Scripts/Map/MapBuilder.cs
@@ -25,8 +25,6 @@ namespace Statecraft.Game.Map
/// capture, the 90 km flythrough) a coarse surface that rises above the draped hex outlines in valleys (K2).</summary>
public const float TerrainPixelError = 1f;
- /// <summary>The muted land tone of neighbouring land past the map's edge (BorderLand.mat).</summary>
- public static readonly Color BorderLandColour = new Color(0.60f, 0.56f, 0.46f);
/// <summary>Biome colours of the terrain layers (the minimap uses the same ones).</summary>
public static IReadOnlyDictionary<string, Color> BiomeColours => Biome;
@@ -169,81 +167,48 @@ namespace Statecraft.Game.Map
return tex;
}
- /// <summary>Distances (m) of the border skirt's rings from the map's edge: land holds the edge's height across the
- /// first rings and reaches sea level only at the last, beyond anything the camera can see (SkirtFall).</summary>
- public static readonly float[] SkirtRings = { 0f, 4000f, 20000f, 60000f, 600000f };
- /// <summary>Share of the fall to sea level reached at each ring (land samples only). Visual v1 Task 7: the edge's height
- /// is held for 20 km (the Jordanian plateau, about 900 m, continues past the edge instead of sagging at once) and
- /// eases to sea level by the last ring, beyond anything the camera sees.</summary>
- public static readonly float[] SkirtFall = { 0f, 0.05f, 0.15f, 0.45f, 1f };
- /// <summary>Half-width (m) of the along-edge average the land skirt holds past its inner ring (Task 7): holding each
- /// edge vertex's own height for 20 km drew its ridges and gullies out as long stripes across the skirt, so the rings
- /// past the edge hold the edge's broad height (the plateau) and only ring 0 follows the terrain's edge exactly.</summary>
- public const float SkirtHoldSmoothingM = 8000f;
/// <summary>A heightmap sample this close to 0 m is sea (tools/dem_to_heightmap.py writes open sea as exactly 0 m).</summary>
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, 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)
+ /// <summary>The diorama's frame (issue #36, promo 02): the map is a relief board in a wooden picture frame on a dark
+ /// table. Horizontal run (m) of the bevel from the terrain's edge to the frame's top: where the edge stands higher than
+ /// the frame (the Jordanian plateau, the Lebanon hills) it is the board's cut earth falling to the frame; where it is
+ /// lower (the sea, the Sinai coast) it is the frame's inner lip rising from it.</summary>
+ public const float FrameBevelM = 1500f;
+ /// <summary>Width (m) of the frame's top, from the bevel's outer end to the frame's outer face.</summary>
+ public const float FrameWidthM = 6000f;
+ /// <summary>Height (world m, exaggerated like the relief) of the frame's top above sea level, and of its rounded
+ /// crown above that.</summary>
+ public const float FrameRiseM = 1500f, FrameCrownM = 300f;
+ /// <summary>How far (m) the table runs past the frame: beyond anything the camera sees at its farthest zoom.</summary>
+ public const float TableReachM = 600000f;
+ /// <summary>sRGB albedos: the frame's walnut, the table's darker wood, and the board's cut earth.</summary>
+ public static readonly Color FrameWood = new Color(0.44f, 0.26f, 0.15f), TableWood = new Color(0.21f, 0.14f, 0.10f),
+ CutEarth = new Color(0.64f, 0.49f, 0.33f);
+ /// <summary>Which surface a frame vertex belongs to, carried in its colour's alpha (MapFrame.shader picks the grain).</summary>
+ public static class FrameKind { public const float Earth = 0f, Wood = 0.5f, Table = 1f; }
+
+ /// <summary>The frame round the map (issue #36; it replaces the border skirt, whose flat land slab and sea ran 600 km
+ /// past the edge). Three parts, all outside the terrain's footprint and all at or below the terrain's highest point
+ /// and at or above its lowest (world y 0), so the camera's fit (CameraController.ViewFootprint, issue #174) keeps
+ /// every one of them off the screen wherever the view fits the map; they show only at the overview, where the view
+ /// is wider than the map:
+ /// - the bevel: one spoke per terrain vertex along each edge, from the edge's own height (ring 0 meets the terrain
+ /// exactly) to the frame's top FrameBevelM out (cut earth above the frame's top, the frame's inner lip below it);
+ /// - the frame: a mitred walnut moulding FrameWidthM wide with a rounded crown, and its outer face down to the table;
+ /// - the table: dark wood at world y 0 out to TableReachM (the shader darkens it next to the frame and away from it).
+ /// One submesh, one material (MapFrame.mat): vertex colour = sRGB albedo, alpha = FrameKind, uv0 = (along the side,
+ /// out from the frame's outer edge) in metres. The table and frame faces carry their own vertices, so their creases stay
+ /// sharp; the bevel is smooth along each edge.</summary>
+ public static Mesh BuildFrame(TerrainData data, float elevMinM, MapRuntimeAssets assets)
{
var size = data.size;
- float seaY = (0f - elevMinM) * VerticalExaggeration;
- // One spoke per terrain vertex along each edge (the heightmap's own resolution), so the skirt's inner edge follows
- // the terrain's edge exactly; sampling every second vertex left slivers up to 36 m (fix round 3, m-4).
+ float seaY = (0f - elevMinM) * VerticalExaggeration, topY = seaY + FrameRiseM, tableY = 0f;
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 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)
- {
- 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 (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)
- {
- int first = verts.Count;
- for (int k = 0; k < SkirtRings.Length; k++)
- {
- var q = p + (outward + (outward2 ?? Vector2.zero)) * SkirtRings[k];
- float y = isLand ? Mathf.Lerp(held, seaY, SkirtFall[k]) : seaY;
- if (k == 0) y = h; // meets the terrain's edge exactly
- verts.Add(new Vector3(q.x, y, q.y));
- }
- return first;
- }
- void Quad(List<int> into, int a0, int b0) // the band between two spokes
- {
- for (int k = 0; k + 1 < SkirtRings.Length; k++)
- {
- int a = a0 + k, a1 = a0 + k + 1, b = b0 + k, b1 = b0 + k + 1;
- Tri(into, a, b, b1); Tri(into, a, b1, a1);
- }
- }
- void Tri(List<int> into, int i, int j, int l) // wound to face up
- {
- var n = Vector3.Cross(verts[j] - verts[i], verts[l] - verts[i]);
- if (n.y < 0) { var t = j; j = l; l = t; }
- if (Mathf.Abs(n.y) > 1e-3f) { into.Add(i); into.Add(j); into.Add(l); } // drops the degenerate corner centre
- }
+ var verts = new List<Vector3>(); var colours = new List<Color>(); var uvs = new List<Vector2>(); var tris = new List<int>();
float Height(Vector2 p) => data.GetInterpolatedHeight(Mathf.Clamp01(p.x / size.x), Mathf.Clamp01(p.y / size.z));
- // The four edges, walked along: (start, end, outward).
+ Color Of(Color albedo, float kind) => new Color(albedo.r, albedo.g, albedo.b, kind);
+ // The four edges, walked along: (start, end, outward). Each corner's mitre runs along the sum of its two normals.
var edges = new (Vector2 a, Vector2 b, Vector2 n)[]
{
(new Vector2(0, 0), new Vector2(size.x, 0), Vector2.down), // south
@@ -251,35 +216,66 @@ 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
};
- 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]); }
+ // A quad (a, b, c, d in order round it), wound to face up, or outward where it is vertical.
+ void Quad(int a, int b, int c, int d, Vector2 outward)
+ {
+ var n = Vector3.Cross(verts[b] - verts[a], verts[c] - verts[a]);
+ bool flip = Mathf.Abs(n.y) > 1e-3f * n.magnitude ? n.y < 0 : n.x * outward.x + n.z * outward.y < 0;
+ if (flip) tris.AddRange(new[] { a, c, b, a, d, c });
+ else tris.AddRange(new[] { a, b, c, a, c, d });
+ }
+ int Add(Vector2 p, float y, Color colour, Vector2 uv) { verts.Add(new Vector3(p.x, y, p.y)); colours.Add(colour); uvs.Add(uv); return verts.Count - 1; }
+ // The frame's profile past the bevel: (offset from the map's edge, height). The crown sits a little nearer the map,
+ // as on a picture frame's moulding; the last ring drops the outer face to the table.
+ var profile = new (float o, float y)[]
+ {
+ (FrameBevelM, topY), (FrameBevelM + 0.3f * FrameWidthM, topY + FrameCrownM),
+ (FrameBevelM + 0.7f * FrameWidthM, topY + FrameCrownM), (FrameBevelM + FrameWidthM, topY), (FrameBevelM + FrameWidthM, tableY),
+ };
+ float outer = FrameBevelM + FrameWidthM;
for (int e = 0; e < edges.Length; e++)
{
var (a, b, n) = edges[e];
- int prev = -1; bool prevLand = false;
+ Vector2 ma = n + edges[(e + edges.Length - 1) % edges.Length].n, mb = n + edges[(e + 1) % edges.Length].n;
+ var dir = (b - a).normalized;
+ float Along(Vector2 p) => Vector2.Dot(p - a, dir);
+ // The bevel: inner vertex on the terrain's edge, outer on the frame's top inner edge (mitred at the corners).
+ int prev = -1;
for (int i = 0; i <= samples; i++)
{
- var p = Vector2.Lerp(a, b, (float)i / samples);
- 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;
+ float t = (float)i / samples;
+ Vector2 p = Vector2.Lerp(a, b, t), q = Vector2.Lerp(a + ma * FrameBevelM, b + mb * FrameBevelM, t);
+ float h = Height(p);
+ var colour = h > topY ? Of(CutEarth, FrameKind.Earth) : Of(FrameWood, FrameKind.Wood);
+ int inner = Add(p, h, colour, new Vector2(Along(p), -outer));
+ Add(q, topY, colour, new Vector2(Along(q), FrameBevelM - outer));
+ if (prev >= 0) Quad(prev, inner, inner + 1, prev + 1, n);
+ prev = inner;
+ }
+ // The frame's faces, each with its own four vertices (sharp creases).
+ for (int k = 0; k + 1 < profile.Length; k++)
+ {
+ var (o0, y0) = profile[k]; var (o1, y1) = profile[k + 1];
+ var colour = Of(FrameWood, FrameKind.Wood);
+ Vector2 a0 = a + ma * o0, b0 = b + mb * o0, a1 = a + ma * o1, b1 = b + mb * o1;
+ int v0 = Add(a0, y0, colour, new Vector2(Along(a0), o0 - outer)), v1 = Add(b0, y0, colour, new Vector2(Along(b0), o0 - outer));
+ int v2 = Add(b1, y1, colour, new Vector2(Along(b1), o1 - outer)), v3 = Add(a1, y1, colour, new Vector2(Along(a1), o1 - outer));
+ Quad(v0, v1, v2, v3, n);
+ }
+ // The table, out to the reach (uv.y = metres out from the frame).
+ {
+ var colour = Of(TableWood, FrameKind.Table);
+ float far = outer + TableReachM;
+ Vector2 a0 = a + ma * outer, b0 = b + mb * outer, a1 = a + ma * far, b1 = b + mb * far;
+ int v0 = Add(a0, tableY, colour, new Vector2(Along(a0), 0f)), v1 = Add(b0, tableY, colour, new Vector2(Along(b0), 0f));
+ int v2 = Add(b1, tableY, colour, new Vector2(Along(b1), TableReachM)), v3 = Add(a1, tableY, colour, new Vector2(Along(a1), TableReachM));
+ Quad(v0, v1, v2, v3, n);
}
}
- // Corners: a fan between the two edges' outward spokes and the diagonal, in the corner sample's kind.
- 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;
- 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 });
- mesh.SetVertices(verts);
- mesh.subMeshCount = 2;
- mesh.SetTriangles(sea, 0); mesh.SetTriangles(land, 1);
+ // About 16.5k vertices at the 2049 heightmap: 16-bit indices, unless a finer heightmap needs more.
+ var mesh = assets.Own(new Mesh { name = "MapFrame", indexFormat = verts.Count > 65535 ? UnityEngine.Rendering.IndexFormat.UInt32 : UnityEngine.Rendering.IndexFormat.UInt16 });
+ mesh.SetVertices(verts); mesh.SetColors(colours); mesh.SetUVs(0, uvs);
+ mesh.SetTriangles(tris, 0);
mesh.RecalculateNormals(); mesh.RecalculateBounds();
return mesh;
}
diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.cs
index 8d3b74b15..0e56869dc 100644
--- a/unity/Assets/Scripts/Map/MapScene.cs
+++ b/unity/Assets/Scripts/Map/MapScene.cs
@@ -12,7 +12,7 @@ namespace Statecraft.Game.Map
/// component calls Build(inputs) once the inputs are loaded (fetched on WebGL); editor tools call Build().</summary>
public sealed class MapScene : MonoBehaviour
{
- [SerializeField] Material terrainMaterial, markerMaterial, selectionMaterial, seaMaterial, borderLandMaterial;
+ [SerializeField] Material terrainMaterial, markerMaterial, selectionMaterial, seaMaterial, frameMaterial;
/// <summary>The art spike's procedural settlement kits and trees (Kit.mat, Tree.mat: Statecraft/Kit). Optional: without
/// them the map keeps the placeholder marker boxes.</summary>
[SerializeField] Material kitMaterial, treeMaterial;
@@ -41,8 +41,8 @@ namespace Statecraft.Game.Map
/// <summary>The selected hex's outline: a child of the terrain (so a rebuild destroys it).</summary>
public const string SelectionName = "HexSelection";
- /// <summary>The land and sea past the map's edge: a child of the terrain (so a rebuild destroys it).</summary>
- public const string BorderSkirtName = "BorderSkirt";
+ /// <summary>The frame round the map and the table beyond it (issue #36): a child of the terrain (so a rebuild destroys it).</summary>
+ public const string FrameName = "MapFrame";
/// <summary>The water inside the map: a mesh over the water and its shore, a child of the terrain (issue #195).</summary>
public const string TerrainWaterName = "TerrainWater";
/// <summary>The terrain water's render queue: after the terrain (Terrain.mat, one queue earlier: MapMaterials) and
@@ -118,10 +118,10 @@ namespace Statecraft.Game.Map
mr.enabled = true;
}
- public void Configure(Material terrain, Material marker, Material selection, Material sea, Material borderLand)
+ public void Configure(Material terrain, Material marker, Material selection, Material sea, Material frame)
{
terrainMaterial = terrain; markerMaterial = marker; selectionMaterial = selection;
- seaMaterial = sea; borderLandMaterial = borderLand;
+ seaMaterial = sea; frameMaterial = frame;
}
/// <summary>The settlement kits' and trees' materials (null, null: placeholder markers only).</summary>
@@ -170,7 +170,7 @@ namespace Statecraft.Game.Map
if (markerMaterial == null) throw new InvalidOperationException("MapScene: markerMaterial is not assigned");
if (selectionMaterial == null) throw new InvalidOperationException("MapScene: selectionMaterial is not assigned");
if (seaMaterial == null) throw new InvalidOperationException("MapScene: seaMaterial is not assigned");
- if (borderLandMaterial == null) throw new InvalidOperationException("MapScene: borderLandMaterial is not assigned");
+ if (frameMaterial == null) throw new InvalidOperationException("MapScene: frameMaterial is not assigned");
var cam = Camera.main;
if (cam == null) throw new InvalidOperationException("MapScene needs a camera tagged MainCamera");
@@ -235,8 +235,8 @@ namespace Statecraft.Game.Map
terrainGo.transform.SetParent(transform, true);
Terrain = terrainGo.GetComponent<Terrain>();
var size = Terrain.terrainData.size;
- AddBorderSkirt(terrainGo, meta.elev_min_m);
- DiagLog.BootPhase("border skirt");
+ AddFrame(terrainGo, meta.elev_min_m);
+ DiagLog.BootPhase("frame");
AddTerrainWater(terrainGo, heights, meta.elev_min_m);
DiagLog.BootPhase("terrain water");
Frame = new GeoFrame(meta.lon0, meta.lon1, meta.lat0, meta.lat1, size.x, size.z);
@@ -313,16 +313,17 @@ namespace Statecraft.Game.Map
rig.TeardownActions.Clear();
}
- /// <summary>The land and sea past the map's edge (MapBuilder.BuildBorderSkirt), drawn with the editor-made Sea.mat and
- /// BorderLand.mat; no collider, so clicks still pick only the terrain. It lies outside the terrain's footprint only.</summary>
- void AddBorderSkirt(GameObject terrainGo, float elevMinM)
+ /// <summary>The frame round the map and the table beyond it (MapBuilder.BuildFrame), drawn with the editor-made
+ /// MapFrame.mat; no collider, so clicks still pick only the terrain, and no shadow. It lies outside the terrain's
+ /// footprint only.</summary>
+ void AddFrame(GameObject terrainGo, float elevMinM)
{
- var skirt = new GameObject(BorderSkirtName);
- skirt.transform.SetParent(terrainGo.transform, false);
- skirt.AddComponent<MeshFilter>().sharedMesh =
- MapBuilder.BuildBorderSkirt(Terrain.terrainData, elevMinM, terrainGo.GetComponent<MapRuntimeAssets>());
- var renderer = skirt.AddComponent<MeshRenderer>();
- renderer.sharedMaterials = new[] { seaMaterial, borderLandMaterial };
+ var frame = new GameObject(FrameName);
+ frame.transform.SetParent(terrainGo.transform, false);
+ frame.AddComponent<MeshFilter>().sharedMesh =
+ MapBuilder.BuildFrame(Terrain.terrainData, elevMinM, terrainGo.GetComponent<MapRuntimeAssets>());
+ var renderer = frame.AddComponent<MeshRenderer>();
+ renderer.sharedMaterial = frameMaterial;
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
diff --git a/unity/Assets/Shaders/MapFrame.shader b/unity/Assets/Shaders/MapFrame.shader
new file mode 100644
index 000000000..1b7d3eae1
--- /dev/null
+++ b/unity/Assets/Shaders/MapFrame.shader
@@ -0,0 +1,144 @@
+// The diorama's frame round the map (issue #36, promo 02; MapBuilder.BuildFrame): the board's cut earth, the walnut frame
+// and the dark table it stands on. Vertex colour is the sRGB albedo and its alpha the surface (MapBuilder.FrameKind: 0 earth,
+// 0.5 frame, 1 table); uv0 is (along the side, out from the frame's outer edge) in metres. The grain is procedural and fades
+// to its mean once it is under about a pixel, so the overview shows no shimmer. Lit like the kits and the terrain (the sun
+// with its shadows, the trilight ambient through SH) and hazed with the terrain's own ScHazeAmount, so the frame sits in the
+// same air as the map. Casts no shadow (MapScene turns it off), like the border skirt it replaces.
+Shader "Statecraft/MapFrame"
+{
+ Properties
+ {
+ _Grain ("Grain strength", Range(0, 1)) = 1
+ }
+ SubShader
+ {
+ Tags { "RenderType" = "Opaque" "Queue" = "Geometry" "RenderPipeline" = "UniversalPipeline" }
+ HLSLINCLUDE
+ #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
+ CBUFFER_START(UnityPerMaterial)
+ half _Grain;
+ CBUFFER_END
+ ENDHLSL
+
+ Pass
+ {
+ Name "MapFrame"
+ Tags { "LightMode" = "UniversalForward" }
+ HLSLPROGRAM
+ #pragma vertex Vert
+ #pragma fragment Frag
+ #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
+ #pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
+ #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
+ #include "Assets/Shaders/StatecraftMap.hlsl"
+
+ struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; half4 color : COLOR; float2 uv : TEXCOORD0; };
+ struct Varyings
+ {
+ float4 positionCS : SV_POSITION; float3 positionWS : TEXCOORD0; float3 normalWS : TEXCOORD1;
+ half4 color : TEXCOORD2; float2 uv : TEXCOORD3;
+ };
+
+ // The frame's contact shadow on the table and the table's light falloff (m out from the frame: uv.y).
+ static const float ContactM = 8000.0, FalloffM = 160000.0;
+ // The table's planks (m wide, running north-south) and the grain's streaks (m across, m along).
+ static const float PlankM = 9000.0;
+ static const float TableHaze = 0.4;
+
+ Varyings Vert(Attributes v)
+ {
+ Varyings o;
+ VertexPositionInputs p = GetVertexPositionInputs(v.positionOS.xyz);
+ o.positionCS = p.positionCS; o.positionWS = p.positionWS;
+ o.normalWS = TransformObjectToWorldNormal(v.normalOS);
+ o.color = v.color; o.uv = v.uv;
+ return o;
+ }
+
+ // Streaky noise along `along`, fine across `across` (both in cells), faded to its mean (0.5) as a cell shrinks
+ // under about a pixel (fw: the pixel's footprint in cells across).
+ float Streaks(float across, float along, float fw)
+ {
+ return lerp(0.5, ScNoise(float2(across, along)), saturate(1.5 - fw));
+ }
+
+ half4 Frag(Varyings i) : SV_Target
+ {
+ float3 n = SafeNormalize(i.normalWS);
+ half3 albedo = SRGBToLinear(i.color.rgb);
+ float kind = i.color.a;
+ float2 mapM = i.positionWS.xz - _ScMapOrigin.xz;
+ // Every derivative in uniform control flow.
+ float fwX = fwidth(mapM.x), fwUv = fwidth(i.uv.y), fwY = fwidth(i.positionWS.y);
+ float shade = 1.0;
+ if (kind > 0.75)
+ {
+ // The table: planks running north-south with a faint seam, each a shade of its own, and a grain along them.
+ float plank = floor(mapM.x / PlankM);
+ shade *= 1.0 + 0.16 * (ScHash(float2(plank, 7.3)) - 0.5);
+ shade *= 1.0 + 0.30 * _Grain * (Streaks(mapM.x / 450.0, mapM.y / 14000.0 + plank * 3.1, fwX / 450.0) - 0.5);
+ float seam = frac(mapM.x / PlankM);
+ shade *= 1.0 - 0.35 * saturate(1.5 - fwX / 120.0) * (1.0 - smoothstep(0.0, 0.012, min(seam, 1.0 - seam)));
+ // The frame's contact shadow, and the light falling off away from the board, as under a lamp over it.
+ shade *= lerp(0.45, 1.0, smoothstep(0.0, 1.0, saturate(i.uv.y / ContactM)));
+ shade *= lerp(1.0, 0.55, saturate(i.uv.y / FalloffM));
+ }
+ else if (kind > 0.25)
+ {
+ // The frame: grain along the side, fine across it.
+ shade *= 1.0 + 0.28 * _Grain * (Streaks(i.uv.y / 160.0, i.uv.x / 9000.0, fwUv / 160.0) - 0.5);
+ }
+ else
+ {
+ // The board's cut earth: layers by height, wavering a little along the edge.
+ float layer = i.positionWS.y / 260.0 + 0.8 * ScNoise(float2(i.uv.x / 6000.0, 1.7));
+ shade *= 1.0 + 0.22 * _Grain * (Streaks(layer, 0.37, fwY / 260.0) - 0.5);
+ }
+ albedo *= shade;
+ Light sun = GetMainLight(TransformWorldToShadowCoord(i.positionWS));
+ float ndl = saturate(dot(n, sun.direction));
+ half3 lit = albedo * (SampleSH(n) + sun.color * ndl * sun.shadowAttenuation);
+ // The haze is the land's aerial haze, read at sea level or higher: the table lies at world y 0 (the Dead Sea's
+ // floor) and the frame's outer face runs down to it, and ScHazeAmount's rift boost (up to 1.6x below the
+ // rift's top) belongs to the Jordan rift, not to furniture past the map's edge (review S1). The table then
+ // takes TableHaze of that: it lies under the board's lamp, dark as in promo 02.
+ float3 hazeAt = float3(i.positionWS.x, max(i.positionWS.y, _ScMap.z), i.positionWS.z);
+ float h = _ScHaze.a * ScHazeAmount(hazeAt) * (kind > 0.75 ? TableHaze : 1.0);
+ return half4(lerp(lit, _ScHaze.rgb, h), 1.0);
+ }
+ ENDHLSL
+ }
+ Pass
+ {
+ Name "DepthOnly"
+ Tags { "LightMode" = "DepthOnly" }
+ ZWrite On
+ ColorMask R
+ HLSLPROGRAM
+ #pragma vertex Vert
+ #pragma fragment Frag
+ struct Attributes { float4 positionOS : POSITION; };
+ float4 Vert(Attributes v) : SV_POSITION { return TransformObjectToHClip(v.positionOS.xyz); }
+ half Frag() : SV_Target { return 0; }
+ ENDHLSL
+ }
+ Pass
+ {
+ Name "DepthNormals"
+ Tags { "LightMode" = "DepthNormals" }
+ ZWrite On
+ HLSLPROGRAM
+ #pragma vertex Vert
+ #pragma fragment Frag
+ struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; };
+ struct Varyings { float4 positionCS : SV_POSITION; float3 normalWS : TEXCOORD0; };
+ Varyings Vert(Attributes v)
+ {
+ Varyings o; o.positionCS = TransformObjectToHClip(v.positionOS.xyz); o.normalWS = TransformObjectToWorldNormal(v.normalOS);
+ return o;
+ }
+ half4 Frag(Varyings i) : SV_Target { return half4(normalize(i.normalWS), 0.0); }
+ ENDHLSL
+ }
+ }
+}
diff --git a/unity/Assets/Shaders/MapFrame.shader.meta b/unity/Assets/Shaders/MapFrame.shader.meta
new file mode 100644
index 000000000..0721f78bf
--- /dev/null
+++ b/unity/Assets/Shaders/MapFrame.shader.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: b0a34f85aacb4ec1a2458fd21122e774
+ShaderImporter:
+ externalObjects: {}
+ defaultTextures: []
+ nonModifiableTextures: []
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.cs
index 01a88f86c..2f6e6a1e0 100644
--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs
+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs
@@ -196,7 +196,7 @@ public class CameraInputTests
}
/// <summary>Issue #174: panning past a corner at gameplay zoom stops where the view's edges meet the map's, at every
- /// yaw and with the top bar's inset, so the border skirt never shows. (The look-at clamp alone left 3/4 of the view on it.)</summary>
+ /// yaw and with the top bar's inset, so nothing past the map's edge (since #36 the frame) shows. (The look-at clamp alone left 3/4 of the view on it.)</summary>
[Test]
public void PanningPastACornerKeepsTheViewOnTheMap()
{
diff --git a/unity/Assets/Tests/EditMode/MapActionUiTests.cs b/unity/Assets/Tests/EditMode/MapActionUiTests.cs
index 2f2093c26..909d06c77 100644
--- a/unity/Assets/Tests/EditMode/MapActionUiTests.cs
+++ b/unity/Assets/Tests/EditMode/MapActionUiTests.cs
@@ -115,7 +115,7 @@ public class MapActionUiTests
AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/SettlementMarker.mat"),
AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexSelection.mat"),
AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Sea.mat"),
- AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/BorderLand.mat"));
+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/MapFrame.mat"));
map.Build();
var layer = new GameObject("Placements").AddComponent<PlacementLayer>();
var tlv = C.SettlementHexes.Single(s => s.Id == "tel_aviv");
@@ -243,7 +243,7 @@ public class MapActionUiTests
AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/SettlementMarker.mat"),
AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexSelection.mat"),
AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Sea.mat"),
- AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/BorderLand.mat"));
+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/MapFrame.mat"));
map.Build();
Physics.SyncTransforms();
return map;
diff --git a/unity/Assets/Tests/EditMode/MapEdgeTests.cs b/unity/Assets/Tests/EditMode/MapEdgeTests.cs
index c67aedaae..387374573 100644
--- a/unity/Assets/Tests/EditMode/MapEdgeTests.cs
+++ b/unity/Assets/Tests/EditMode/MapEdgeTests.cs
@@ -7,7 +7,7 @@ using UnityEngine;
using UnityEngine.TestTools;
/// <summary>Issue #174 (integration bug B11): panning past the terrain's edge filled the view with flat fills and a hard
-/// seam. Two causes: the look-at clamp let the view run off the map onto the border skirt (a flat slab), and at the high
+/// seam. Two causes: the look-at clamp let the view run off the map onto the border skirt (a flat slab; since #36 the frame), and at the high
/// north-east corner (the ground about 6 km up at 3x relief) the hero-zoom camera, 4.6 km above the look-at plane y = 0,
/// sat inside the hills and showed only haze. Rendered at the worst pan pose: the hero zoom pushed into each corner of the
/// map, through the same CameraController.Step the game runs every frame, with the bounds and ground GameRoot gives it.</summary>
@@ -37,14 +37,14 @@ public class MapEdgeTests
var map = Object.FindFirstObjectByType<MapScene>();
map.Build();
var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
- var skirt = map.Terrain.transform.Find(MapScene.BorderSkirtName).GetComponent<MeshRenderer>();
+ var frame = map.Terrain.transform.Find(MapScene.FrameName).GetComponent<MeshRenderer>();
var bounds = Bounds(map); var ground = CameraController.GroundOf(map.Terrain); var top = CameraController.GroundTopOf(map.Terrain);
var rt = new RenderTexture(W, H, 24);
Directory.CreateDirectory(ShotDir);
RenderSample.TiltShift(false); // a colour test: the blur spreads pixels across the frame
// The water moves between the renders compared below (waves, breakers and, since sea round 2, the far sea's ripple),
// which changed a few pixels of the north-west corner's coast at random (0-14 a run, skirt or not): its clock is
- // pinned, so the comparison sees only the skirt.
+ // pinned, so the comparison sees only the frame.
MapShaderGlobals.PinWaterTime(100f);
try
{
@@ -60,29 +60,29 @@ public class MapEdgeTests
rig.LookAt = new Vector3(corner.x, 0, corner.y); rig.Distance = CameraController.MinDistance; rig.Yaw = 0; rig.TopInset = 0;
for (int i = 0; i < 20; i++) CameraController.Step(rig, new CameraInput { Pan = push }, CameraController.MaxFrameSeconds, bounds, ground, top);
var with = RenderSample.Render(cam, W, H);
- skirt.enabled = false;
+ frame.enabled = false;
var without = RenderSample.Render(cam, W, H);
- skirt.enabled = true;
+ frame.enabled = true;
map.Terrain.enabled = false;
var noTerrain = RenderSample.Render(cam, W, H);
map.Terrain.enabled = true;
File.WriteAllBytes(Path.Combine(ShotDir, $"edge-{name}.png"), Png(with));
- // 1. The skirt draws no pixel of the view: hiding it changes nothing.
+ // 1. The frame (and the table) draws no pixel of the view: hiding it changes nothing.
// 2. No flat fill: the terrain draws (nearly) every pixel, so hiding it changes them. Before the fix, at the
// north-east corner the camera sat inside the hills and nothing drew: 0% (haze over the clear colour). Kits
// and trees standing in front of the ground are the only pixels allowed to stay.
- int skirtPixels = 0, terrainPixels = 0;
+ int framePixels = 0, terrainPixels = 0;
for (int i = 0; i < with.Pixels.Length; i++)
{
- if (Differs(with.Pixels[i], without.Pixels[i])) skirtPixels++;
+ if (Differs(with.Pixels[i], without.Pixels[i])) framePixels++;
if (Differs(with.Pixels[i], noTerrain.Pixels[i])) terrainPixels++;
}
float terrainShare = (float)terrainPixels / with.Pixels.Length;
TestContext.WriteLine($"{name}: look-at ({rig.LookAt.x:0}, {rig.LookAt.y:0}, {rig.LookAt.z:0}) of ({bounds.xMax:0}, {bounds.yMax:0}); " +
$"camera {rig.transform.position.y:0} over ground {ground(new Vector2(rig.transform.position.x, rig.transform.position.z)):0}; " +
- $"skirt pixels {skirtPixels}; terrain {100f * terrainShare:0.00}% of the view");
- if (skirtPixels > 0) failures.Add($"{name} corner: the border skirt shows in {skirtPixels} pixels");
+ $"frame pixels {framePixels}; terrain {100f * terrainShare:0.00}% of the view");
+ if (framePixels > 0) failures.Add($"{name} corner: the frame shows in {framePixels} pixels");
if (terrainShare <= MinTerrainShare) failures.Add($"{name} corner: the terrain draws only {100f * terrainShare:0.0}% of the view (a flat fill)");
}
Assert.IsEmpty(failures, string.Join("; ", failures)); // every corner checked and written before failing
@@ -90,7 +90,59 @@ public class MapEdgeTests
finally
{
RenderSample.TiltShift(true); MapShaderGlobals.PinWaterTime(null);
- skirt.enabled = true; map.Terrain.enabled = true;
+ frame.enabled = true; map.Terrain.enabled = true;
+ cam.targetTexture = null; rt.Release(); Object.DestroyImmediate(rt);
+ }
+ }
+
+ /// <summary>Issue #36: the frame and table show at the overview, where the view is wider than the map (diorama02, fitted
+ /// by the same CameraController.Step the game runs), on both sides of the board; at gameplay03 they draw no pixel. The
+ /// render is 16:9 (W x H), which the split at 100 km assumes: wider windows show the frame from nearer (32:9 from about
+ /// 53 km). What each half covers: the overview half fails if the frame does not draw (renderer off, nothing written);
+ /// the gameplay half only shows that the frame stays out of gameplay03's view, about 17 km off every edge, so a frame
+ /// raised above the ground's top or reaching into the map is caught by PanningIntoACornerShowsNoSkirtSeamOrFlatFill and
+ /// MapSceneTests.TheFrameRimsTheMapAndTheTableLiesBeyond instead.</summary>
+ [UnityTest]
+ public IEnumerator TheFrameShowsAtTheOverviewOnly()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>();
+ map.Build();
+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
+ var frame = map.Terrain.transform.Find(MapScene.FrameName).GetComponent<MeshRenderer>();
+ var bounds = Bounds(map); var ground = CameraController.GroundOf(map.Terrain); var top = CameraController.GroundTopOf(map.Terrain);
+ var rt = new RenderTexture(W, H, 24);
+ RenderSample.TiltShift(false);
+ MapShaderGlobals.PinWaterTime(100f);
+ try
+ {
+ cam.targetTexture = rt;
+ yield return null;
+ foreach (var pose in PromoPose.All)
+ {
+ pose.Apply(rig, map.Frame); rig.TopInset = 0;
+ CameraController.Step(rig, new CameraInput(), 0f, bounds, ground, top);
+ var with = RenderSample.Render(cam, W, H);
+ frame.enabled = false;
+ var without = RenderSample.Render(cam, W, H);
+ frame.enabled = true;
+ int left = 0, right = 0;
+ for (int i = 0; i < with.Pixels.Length; i++)
+ if (Differs(with.Pixels[i], without.Pixels[i])) { if (i % W < W / 2) left++; else right++; }
+ float share = (float)(left + right) / with.Pixels.Length;
+ TestContext.WriteLine($"{pose.Name}: the frame draws {100f * share:0.00}% of the view ({left} px left, {right} px right)");
+ if (pose.Distance < 100000f) Assert.AreEqual(0, left + right, $"{pose.Name}: the frame stays off the screen");
+ else
+ {
+ Assert.Greater(left, with.Pixels.Length / 50, $"{pose.Name}: the frame shows west of the board");
+ Assert.Greater(right, with.Pixels.Length / 50, $"{pose.Name}: the frame shows east of the board");
+ }
+ }
+ }
+ finally
+ {
+ RenderSample.TiltShift(true); MapShaderGlobals.PinWaterTime(null);
+ frame.enabled = true;
cam.targetTexture = null; rt.Release(); Object.DestroyImmediate(rt);
}
}
diff --git a/unity/Assets/Tests/EditMode/RouteTests.cs b/unity/Assets/Tests/EditMode/RouteTests.cs
index 80f4ac235..1a4ce77ba 100644
--- a/unity/Assets/Tests/EditMode/RouteTests.cs
+++ b/unity/Assets/Tests/EditMode/RouteTests.cs
@@ -78,7 +78,7 @@ public class RouteTests
{
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("BorderLand"));
+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));
map.Build();
return map;
}
@@ -387,7 +387,7 @@ public class RouteTests
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("BorderLand"));
+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));
var inputs = Statecraft.Game.Boot.GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap);
inputs.RoutesYaml = "";
UnityEngine.TestTools.LogAssert.Expect(LogType.Warning, new System.Text.RegularExpressions.Regex("route_paths_1948.yaml: missing"));
@@ -420,7 +420,7 @@ public class RouteTests
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("BorderLand"));
+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));
var inputs = Statecraft.Game.Boot.GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap);
Assert.IsTrue(inputs.RoutesYaml.Contains("from: '1948-06-14'"));
inputs.RoutesYaml = inputs.RoutesYaml.Replace("from: '1948-06-14'", "from: '0000'");
diff --git a/unity/Assets/Tests/EditMode/SeaTests.cs b/unity/Assets/Tests/EditMode/SeaTests.cs
index 822d45076..fb7817c52 100644
--- a/unity/Assets/Tests/EditMode/SeaTests.cs
+++ b/unity/Assets/Tests/EditMode/SeaTests.cs
@@ -9,7 +9,7 @@ using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.TestTools;
-/// <summary>Plan Task 7: the water, inside the map and past its edge, and the plateau skirt.</summary>
+/// <summary>Plan Task 7: the water inside the map (since issue #36 a frame, not a skirt of sea, lies past its edge).</summary>
public class SeaTests
{
const string SeaMatPath = "Assets/Materials/Sea.mat";
@@ -139,55 +139,6 @@ public class SeaTests
StringAssert.DoesNotContain(call, src);
}
- /// <summary>The controller's known gap: at the Jordanian plateau the land skirt holds the edge's height for 20 km (at
- /// least 80% of its height above the sea) and reaches sea level only at the last ring.</summary>
- [Test]
- public void TheLandSkirtHoldsThePlateauThenEasesToSeaLevel()
- {
- var map = OpenMap();
- var size = map.Terrain.terrainData.size;
- var verts = map.Terrain.transform.Find(MapScene.BorderSkirtName).GetComponent<MeshFilter>().sharedMesh.vertices;
- var meta = HeightmapLoader.Load(Statecraft.Game.Paths.StreamingMap).meta;
- float seaY = (0f - meta.elev_min_m) * MapBuilder.VerticalExaggeration;
- float zAmman = map.Frame.ToWorld(35.9, 31.95, 0).z;
- int best = -1;
- for (int i = 0; i < verts.Length; i++)
- if (Mathf.Abs(verts[i].x - size.x) < 0.5f && (best < 0 || Mathf.Abs(verts[i].z - zAmman) < Mathf.Abs(verts[best].z - zAmman))) best = i;
- Assert.GreaterOrEqual(best, 0, "an east-edge spoke");
- float edge = verts[best].y - seaY;
- Assert.Greater(edge, 1500f, "the plateau stands well above the sea (about 900 m, exaggerated 3x)");
- Assert.AreEqual(size.x + MapBuilder.SkirtRings[2], verts[best + 2].x, 1f, "ring 2 of the same spoke");
- Assert.GreaterOrEqual(verts[best + 2].y - seaY, 0.8f * edge, "held 20 km out");
- Assert.AreEqual(seaY, verts[best + MapBuilder.SkirtRings.Length - 1].y, 1f, "at sea level at the last ring");
- }
-
- /// <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). 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()
- {
- var map = OpenMap();
- var size = map.Terrain.terrainData.size;
- var verts = map.Terrain.transform.Find(MapScene.BorderSkirtName).GetComponent<MeshFilter>().sharedMesh.vertices;
- int rings = MapBuilder.SkirtRings.Length;
- float edge = 0f, held = 0f; int pairs = 0, prev = -1;
- for (int i = 0; i + rings <= verts.Length; i += rings)
- {
- bool east = Mathf.Abs(verts[i].x - size.x) < 0.5f && verts[i].z > 0.3f * size.z && verts[i].z < 0.9f * size.z
- && Mathf.Abs(verts[i + 2].x - (size.x + MapBuilder.SkirtRings[2])) < 1f;
- if (!east) { prev = -1; continue; }
- if (prev >= 0) { edge += Mathf.Abs(verts[i].y - verts[prev].y); held += Mathf.Abs(verts[i + 2].y - verts[prev + 2].y); pairs++; }
- prev = i;
- }
- 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.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);
/// <summary>Rendered west of Tel Aviv: just offshore (about 120-200 m out, on the swash line: full to 180 m, gone by
@@ -458,78 +409,6 @@ public class SeaTests
finally { Object.DestroyImmediate(go); }
}
- /// <summary>Sea round 2 (#388): the far sea's texture (the "seatexture" toggle: StatecraftMap.hlsl's mottle, ripple and
- /// whitecaps) leaves no step where the terrain's water meets the skirt's sea at the map's west edge. The seam test
- /// (SettlementTests.TheSeaBeyondTheEdgeMatchesTheTerrainSea) compares points 5 km apart, across which a 2.5 km mottle
- /// varies by itself, so it pins the texture off; this one looks for a step, not a difference. Rendered straight down
- /// (orthographic) at the seam test's pixel size (110 m, so the ripple and whitecaps have faded and the mottle is what
- /// is on), over a 40 km strip of the edge with the water's clock pinned. Per row, the change between the two pixel
- /// columns either side of x = 0 is compared with the change between neighbouring columns elsewhere in the strip: the
- /// RMS across the edge may exceed the RMS elsewhere by at most the seam test's own pre-grade bound (0.012), which catches
- /// a texture that does not continue; and the mean change across the edge, summed over r, g and b, stays under the same
- /// bound, which catches a uniform step (an RMS adds a uniform step in quadrature with the texture's own change). (Fitting a
- /// line either side and extrapolating was tried: over the whole strip a mismatched texture's steps cancel, and per
- /// 880 m segment the texture's own variation swamped the fit, 0.049 with no seam against 0.059 with one.) The grade
- /// is a per-pixel LUT, so it can
- /// scale a step but not make one (the seam test's argument), and this test's own camera renders without it. The
- /// texture must be there to be tested: the strip's luma varies more with it on than off.</summary>
- [UnityTest]
- public IEnumerator TheFarSeaTextureHasNoStepAtTheMapEdge()
- {
- var map = OpenMap();
- yield return null;
- VisualToggles.Set("grid", false);
- MapShaderGlobals.PinWaterTime(100f);
- var size = map.Terrain.terrainData.size; var origin = map.Terrain.transform.position;
- const int w = 64, h = 364; const float metresPerPixel = 110f;
- var go = new GameObject("TopEdge"); var cam = go.AddComponent<Camera>();
- try
- {
- cam.orthographic = true; cam.orthographicSize = h * metresPerPixel / 2f; cam.aspect = (float)w / h;
- // Centred on the west edge (map x = 0), so the edge falls on the boundary between columns w/2 - 1 and w/2.
- cam.transform.position = new Vector3(origin.x, 20000f, origin.z + 0.55f * size.z); cam.transform.rotation = Quaternion.Euler(90, 0, 0);
- cam.nearClipPlane = 100f; cam.farClipPlane = 60000f;
- float Std(RenderSample r)
- {
- double sum = 0, sq = 0; int k = 0;
- for (int j = 0; j < h; j++) for (int i = 0; i < w; i++) { double l = Luma(r.At(i, j)); sum += l; sq += l * l; k++; }
- return (float)System.Math.Sqrt(sq / k - (sum / k) * (sum / k));
- }
- VisualToggles.Set("seatexture", false);
- float plain = Std(RenderSample.Render(cam, w, h));
- VisualToggles.Set("seatexture", true);
- var r = RenderSample.Render(cam, w, h);
- float textured = Std(r);
- // The change between neighbouring pixel columns, |dr| + |dg| + |db| per row: across the edge (columns w/2 - 1
- // and w/2, each 110 m wide, one either side of x = 0) and, as the control, between neighbours 4-12 columns out on
- // either side, inside one mesh. A continuous texture changes as little across the edge as anywhere else; a
- // mismatched one (or a step in the inputs) changes there by about its whole range. The RMS over the rows at the
- // edge may exceed the control's by at most the seam test's bound.
- double Pair(int i, int j) { var a = r.At(i, j); var b = r.At(i + 1, j); return Mathf.Abs(a.r - b.r) + Mathf.Abs(a.g - b.g) + Mathf.Abs(a.b - b.b); }
- double edgeSq = 0, controlSq = 0; int controlN = 0;
- var signedEdge = Vector3.zero; // the mean change across the edge per channel: a uniform step (an input mismatch)
- for (int j = 0; j < h; j++)
- {
- double e = Pair(w / 2 - 1, j); edgeSq += e * e;
- var ea = r.At(w / 2 - 1, j); var eb = r.At(w / 2, j); signedEdge += new Vector3(eb.r - ea.r, eb.g - ea.g, eb.b - ea.b) / h;
- for (int k = 4; k <= 12; k++)
- {
- double c1 = Pair(w / 2 - 1 - k, j), c2 = Pair(w / 2 - 1 + k, j);
- controlSq += c1 * c1 + c2 * c2; controlN += 2;
- }
- }
- float edgeRms = (float)System.Math.Sqrt(edgeSq / h), controlRms = (float)System.Math.Sqrt(controlSq / controlN);
- float step = edgeRms - controlRms;
- float offset = Mathf.Abs(signedEdge.x) + Mathf.Abs(signedEdge.y) + Mathf.Abs(signedEdge.z);
- const float bound = 0.012f;
- TestContext.WriteLine($"neighbour change: across the edge RMS {edgeRms:0.0000}, elsewhere {controlRms:0.0000}, excess {step:0.0000}; mean change across the edge {offset:0.0000} (bound {bound} each); strip luma std {textured:0.0000} with the texture, {plain:0.0000} without");
- Assert.Greater(textured, plain + 0.004f, "the far sea's texture shows at 110 m a pixel");
- Assert.Less(step, bound, "the texture does not continue across the edge (a mismatch between the terrain's water and the skirt's sea)");
- Assert.Less(offset, bound, "a uniform step where the terrain's water meets the skirt's sea");
- }
- finally { Object.DestroyImmediate(go); }
- }
-
/// <summary>Issue #195 review: the terrain water's depth pull follows an orthographic camera's parallel rays. Pulled
/// towards the camera's position instead, the water slid towards the view's axis, and the terrain's black water showed
/// between it and the shore. Straight down over the coast south of Tel Aviv, 30 km across with the axis 12 km offshore,
diff --git a/unity/Assets/Tests/EditMode/SettlementTests.cs b/unity/Assets/Tests/EditMode/SettlementTests.cs
index fe7f86a40..957398985 100644
--- a/unity/Assets/Tests/EditMode/SettlementTests.cs
+++ b/unity/Assets/Tests/EditMode/SettlementTests.cs
@@ -130,7 +130,7 @@ public class MapSceneTests
static string RealYamlPath => Path.Combine(Paths.Content, "map", "settlements_1948.yaml");
const string TerrainMatPath = "Assets/Materials/Terrain.mat",
- MarkerMatPath = "Assets/Materials/SettlementMarker.mat", SelectionMatPath = "Assets/Materials/HexSelection.mat", SeaMatPath = "Assets/Materials/Sea.mat", BorderLandMatPath = "Assets/Materials/BorderLand.mat";
+ MarkerMatPath = "Assets/Materials/SettlementMarker.mat", SelectionMatPath = "Assets/Materials/HexSelection.mat", SeaMatPath = "Assets/Materials/Sea.mat", FrameMatPath = "Assets/Materials/MapFrame.mat";
[SetUp] public void FreshScene() => EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
@@ -143,7 +143,7 @@ public class MapSceneTests
{
if (withCamera) new GameObject("TestMainCamera") { tag = "MainCamera" }.AddComponent<Camera>();
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load(TerrainMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), Load(BorderLandMatPath));
+ map.Configure(Load(TerrainMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), Load(FrameMatPath));
return map;
}
@@ -180,52 +180,73 @@ public class MapSceneTests
Assert.Less(cam.ViewportPointToRay(new Vector3(x, 1f, 0)).direction.y, 0f, $"top edge at x={x} looks down");
}
- /// <summary>Fix round 2 (R2-1, N1): outside the heightmap's bbox each side continues the terrain edge next to it: sea
- /// where the edge is sea (Sea.mat), muted land where it is land (BorderLand.mat), so Sinai, Jordan and Lebanon do not
- /// read as sea. The skirt lies entirely outside the terrain's footprint, so nothing covers land below sea level.</summary>
+ /// <summary>Issue #36 (it replaces fix round 2's skirt, R2-1 and N1): the map is a board in a wooden frame on a table.
+ /// The frame's mesh lies entirely outside the terrain's footprint (nothing covers land below sea level), its inner edge
+ /// meets the terrain's edge at every heightmap sample (no sliver), and all of it lies between the terrain's lowest
+ /// (world y 0) and highest points, where the camera's fit keeps it off the screen whenever the view fits the map (#174).
+ /// The bevel is cut earth where the edge stands above the frame (the Jordanian plateau) and the frame's lip where it lies
+ /// below (the sea); the table reaches TableReachM past the frame on every side. Every face is seen from above or, for
+ /// the frame's outer face, from outside.</summary>
[Test]
- public void TheBorderSkirtContinuesEachEdgeOutsideTheMap()
+ public void TheFrameRimsTheMapAndTheTableLiesBeyond()
{
var map = NewMap(); map.Build();
Assert.IsNull(map.Terrain.transform.Find("SeaPlane"), "no plane over the terrain (fix round 2, N1)");
- var skirt = map.Terrain.transform.Find(MapScene.BorderSkirtName);
- Assert.IsNotNull(skirt, "the border skirt exists");
- var mr = skirt.GetComponent<MeshRenderer>();
- CollectionAssert.AreEqual(new[] { Load(SeaMatPath), Load(BorderLandMatPath) }, mr.sharedMaterials, "sea, then land: editor-made");
- Assert.AreEqual("Universal Render Pipeline/Lit", Load(BorderLandMatPath).shader.name);
- var mesh = skirt.GetComponent<MeshFilter>().sharedMesh;
- var verts = mesh.vertices;
+ var frame = map.Terrain.transform.Find(MapScene.FrameName);
+ Assert.IsNotNull(frame, "the frame exists");
+ var mr = frame.GetComponent<MeshRenderer>();
+ CollectionAssert.AreEqual(new[] { Load(FrameMatPath) }, mr.sharedMaterials, "one editor-made material");
+ Assert.AreEqual("Statecraft/MapFrame", Load(FrameMatPath).shader.name);
+ Assert.IsFalse(ShaderUtil.ShaderHasError(Load(FrameMatPath).shader));
+ CollectionAssert.IsEmpty(ShaderChecks.Gles3Errors(Load(FrameMatPath).shader), "compiles for WebGL 2");
+ Assert.AreEqual(ShadowCastingMode.Off, mr.shadowCastingMode);
+ Assert.IsNull(frame.GetComponent<Collider>(), "clicks pick the terrain only");
+ var mesh = frame.GetComponent<MeshFilter>().sharedMesh;
+ Assert.AreEqual(1, mesh.subMeshCount);
+ var verts = mesh.vertices; var colours = mesh.colors; var tris = mesh.triangles;
var size = map.Terrain.terrainData.size;
- // Which submesh covers a point (world x, z) just outside the map, from lon/lat.
- int Cover(double lat, double lon)
+ // Nothing of the frame lies over the terrain (N1): every triangle is outside the footprint.
+ for (int k = 0; k < tris.Length; k += 3)
{
- var p = map.Frame.ToWorld(lon, lat, 0);
- for (int sm = 0; sm < mesh.subMeshCount; sm++)
- {
- var t = mesh.GetTriangles(sm);
- for (int k = 0; k < t.Length; k += 3)
- if (Inside(new Vector2(p.x, p.z), verts[t[k]], verts[t[k + 1]], verts[t[k + 2]])) return sm;
- }
- return -1;
+ var c = (verts[tris[k]] + verts[tris[k + 1]] + verts[tris[k + 2]]) / 3;
+ Assert.IsFalse(c.x > 1f && c.x < size.x - 1f && c.z > 1f && c.z < size.z - 1f, $"frame triangle over the terrain at {c}");
}
- Assert.AreEqual(1, Cover(31.95, 36.05), "east of the map at Amman's latitude: Jordan, land");
- Assert.AreEqual(1, Cover(29.30, 34.50), "south of the map: Sinai, land");
- Assert.AreEqual(0, Cover(32.00, 34.05), "west of the map off the coast: sea");
- Assert.AreEqual(1, Cover(33.50, 35.60), "north of the map inland: Lebanon, land");
- Assert.AreEqual(0, Cover(33.50, 34.50), "north-west of the map: sea");
- Assert.AreEqual(1, Cover(29.40, 34.30), "south-west corner: Sinai, land");
- // Nothing of the skirt lies over the terrain (N1): every triangle is outside the footprint.
- for (int sm = 0; sm < mesh.subMeshCount; sm++)
+ // Nor any vertex (review S3: a bevel inset 100 m into the map keeps every centroid outside the 1 m margin).
+ foreach (var v in verts)
+ Assert.IsFalse(v.x > 0.5f && v.x < size.x - 0.5f && v.z > 0.5f && v.z < size.z - 0.5f, $"frame vertex over the terrain at {v}");
+ // Inside the camera's fit (#174): between the terrain's lowest and highest points.
+ float top = CameraController.GroundTopOf(map.Terrain);
+ foreach (var v in verts)
{
- var t = mesh.GetTriangles(sm);
- for (int k = 0; k < t.Length; k += 3)
- {
- var c = (verts[t[k]] + verts[t[k + 1]] + verts[t[k + 2]]) / 3;
- Assert.IsFalse(c.x > 1f && c.x < size.x - 1f && c.z > 1f && c.z < size.z - 1f, $"skirt triangle over the terrain at {c}");
- }
+ var w = frame.TransformPoint(v);
+ Assert.That(w.y, Is.InRange(ShadowFit.GroundY - 0.01f, top), $"frame vertex {w} within the ground's height range");
+ }
+ // The table reaches TableReachM past the frame on every side.
+ var b = mesh.bounds; float reach = MapBuilder.FrameBevelM + MapBuilder.FrameWidthM + MapBuilder.TableReachM - 1f;
+ Assert.LessOrEqual(b.min.x, -reach); Assert.GreaterOrEqual(b.max.x, size.x + reach);
+ Assert.LessOrEqual(b.min.z, -reach); Assert.GreaterOrEqual(b.max.z, size.z + reach);
+ // Every face is seen from above, or (the frame's outer face, vertical) from outside: the winding Unity culls by.
+ var centre = new Vector3(size.x / 2, 0, size.z / 2);
+ for (int k = 0; k < tris.Length; k += 3)
+ {
+ Vector3 p0 = verts[tris[k]], p1 = verts[tris[k + 1]], p2 = verts[tris[k + 2]];
+ var n = Vector3.Cross(p1 - p0, p2 - p0);
+ var c = (p0 + p1 + p2) / 3 - centre;
+ bool up = n.y > 1e-3f * n.magnitude, outward = Mathf.Abs(n.y) <= 1e-3f * n.magnitude && n.x * c.x + n.z * c.z > 0;
+ Assert.IsTrue(up || outward, $"triangle {k / 3} at {c + centre} faces {n}");
+ }
+ // Cut earth above the frame's top (east, at Amman's latitude: the plateau), the frame's lip below it (west, the sea).
+ float KindAt(double lat, double lon)
+ {
+ var p = map.Frame.ToWorld(lon, lat, 0); int best = -1;
+ for (int i = 0; i < verts.Length; i++)
+ if (colours[i].a < 0.75f && (best < 0 || (new Vector2(verts[i].x - p.x, verts[i].z - p.z)).sqrMagnitude < (new Vector2(verts[best].x - p.x, verts[best].z - p.z)).sqrMagnitude)) best = i;
+ return colours[best].a;
}
- // Fix round 3 (m-4): on all four edges, at every heightmap sample (the terrain's own vertices), the skirt's inner edge
- // is at the terrain's height: no sliver between them. The skirt's inner height between its ring-0 vertices is linear.
+ Assert.AreEqual(MapBuilder.FrameKind.Earth, KindAt(31.95, 35.9), "the plateau's edge: cut earth");
+ Assert.AreEqual(MapBuilder.FrameKind.Wood, KindAt(32.0, 34.2), "the sea's edge: the frame's lip");
+ // Fix round 3 (m-4), kept: on all four edges, at every heightmap sample (the terrain's own vertices), the frame's
+ // inner edge is at the terrain's height: no sliver between them. Its height between its inner vertices is linear.
var data = map.Terrain.terrainData;
int res = data.heightmapResolution;
var ring0 = System.Array.FindAll(verts, v => v.x <= 0.5f || v.x >= size.x - 0.5f || v.z <= 0.5f || v.z >= size.z - 0.5f);
@@ -236,7 +257,10 @@ public class MapSceneTests
("east", v => Mathf.Abs(v.x - size.x) < 0.5f, v => v.z, t => new Vector2(size.x, t)) })
{
var line = System.Array.FindAll(ring0, v => onEdge(v)); System.Array.Sort(line, (p, q) => along(p).CompareTo(along(q)));
- float worst = 0; float worstAt = 0;
+ // Review S3: with no vertex on the edge line the loop below checked nothing and passed. One inner vertex per
+ // heightmap sample, and every sample but the last bracketed by two of them.
+ Assert.GreaterOrEqual(line.Length, res, $"{name} edge: the frame's inner vertices lie on the map's edge");
+ float worst = 0; float worstAt = 0; int checkedSamples = 0;
for (int i = 0; i < res; i++)
{
float t = (name == "south" || name == "north" ? size.x : size.z) * i / (res - 1);
@@ -248,27 +272,17 @@ public class MapSceneTests
float terrain = data.GetInterpolatedHeight(p2.x / size.x, p2.y / size.z);
float d = Mathf.Abs(Mathf.Lerp(a0.y, a1.y, f) - terrain);
if (d > worst) { worst = d; worstAt = t; }
+ checkedSamples++;
}
+ Assert.GreaterOrEqual(checkedSamples, res - 1, $"{name} edge: samples checked");
TestContext.WriteLine($"{name} edge: largest gap to the terrain {worst:0.00} m (at {worstAt:0} m)");
Assert.Less(worst, 0.5f, $"{name} edge: a sliver of {worst:0.00} m at {worstAt:0} m along it");
}
- // Facing up (seen from the camera's side).
- var used = new HashSet<int>();
- for (int sm = 0; sm < mesh.subMeshCount; sm++) used.UnionWith(mesh.GetTriangles(sm));
- var normals = mesh.normals;
- foreach (var i in used) Assert.Greater(normals[i].y, 0f, $"vertex {i} faces up");
- }
-
- static bool Inside(Vector2 p, Vector3 a, Vector3 b, Vector3 c)
- {
- float Side(Vector2 p1, Vector3 p2, Vector3 p3) => (p1.x - p3.x) * (p2.z - p3.z) - (p2.x - p3.x) * (p1.y - p3.z);
- float d1 = Side(p, a, b), d2 = Side(p, b, c), d3 = Side(p, c, a);
- bool neg = d1 < 0 || d2 < 0 || d3 < 0, pos = d1 > 0 || d2 > 0 || d3 > 0;
- return !(neg && pos);
}
/// <summary>Renders the real scene (Map.unity's light, rig and post-processing) looking at <paramref name="look"/> and
- /// returns the pixel colour of each world point.</summary>
+ /// returns the pixel colour of each world point: with <paramref name="radius"/> over 0, the darkest pixel of the
+ /// (2 radius + 1)-square around it when <paramref name="darkest"/>, else that square's mean.</summary>
static System.Collections.IEnumerator RenderAt(Vector3 look, float distance, Vector3[] points, Color[] colours, int radius = 0, bool darkest = false)
{
var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
@@ -285,14 +299,15 @@ public class MapSceneTests
for (int i = 0; i < points.Length; i++)
{
var p = cam.WorldToScreenPoint(points[i]); // while the camera still renders into the texture
- var best = tex.GetPixel((int)p.x, (int)p.y);
+ var best = tex.GetPixel((int)p.x, (int)p.y); var sum = Color.clear;
for (int dx = -radius; dx <= radius; dx++)
for (int dy = -radius; dy <= radius; dy++)
{
var c = tex.GetPixel((int)p.x + dx, (int)p.y + dy);
if (darkest && c.r + c.g + c.b < best.r + best.g + best.b) best = c;
+ sum += c;
}
- colours[i] = best;
+ colours[i] = darkest ? best : sum / ((2 * radius + 1) * (2 * radius + 1));
}
}
finally
@@ -305,23 +320,33 @@ public class MapSceneTests
static bool LandColour(Color c) => c.r > c.b + 0.05f;
static bool SeaColour(Color c) => c.b > c.r + 0.15f;
- /// <summary>Fix round 2 (R2-1), rendered: just past the east (Amman's latitude) and south (Sinai) edges the backdrop is
- /// land-coloured, past the west edge sea-coloured.</summary>
+ /// <summary>Issue #36, rendered (it replaces fix round 2's land-or-sea backdrop): 15 km past each edge the table shows,
+ /// dark warm wood (red over green over blue, darker than the board's sand next to it), and the frame's top between them is
+ /// lighter than the table.</summary>
[UnityTest]
- public System.Collections.IEnumerator TheBackdropIsLandWhereTheNeighboursAreLand()
+ public System.Collections.IEnumerator TheTableLiesBeyondTheFrameOnEverySide()
{
EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
var map = Object.FindFirstObjectByType<MapScene>();
map.Build();
- foreach (var (name, lat, lon, land) in new[] { ("east (Jordan)", 31.95, 36.0, true), ("south (Sinai)", 29.38, 34.5, true), ("west (sea)", 32.0, 34.12, false), ("north (Lebanon)", 33.42, 35.6, true) })
+ // The middle of the frame's crown (its rounded top's flat, 0.3-0.7 of its width: MapBuilder.BuildFrame's profile), at
+ // its own height (sea level in world y, plus the frame's rise and crown: review S2), and a point on the table 15 km
+ // out, at world y 0. Each is the mean of a 5 x 5 pixel patch (about 0.4 km at 90 km, well inside the crown's 2.4 km).
+ float seaY = (0f - Meta.elev_min_m) * MapBuilder.VerticalExaggeration;
+ float crown = MapBuilder.FrameBevelM + 0.5f * MapBuilder.FrameWidthM, past = 15000f;
+ float topY = seaY + MapBuilder.FrameRiseM + MapBuilder.FrameCrownM;
+ foreach (var (name, lat, lon, outward) in new[] { ("east", 31.95, 35.9, Vector3.right), ("south", 29.45, 34.6, Vector3.back), ("west", 32.0, 34.2, Vector3.left), ("north (the sea off Tyre)", 33.35, 34.9, Vector3.forward) })
{
- var at = map.Frame.ToWorld(lon, lat, 0);
- var edge = map.Frame.ToWorld(System.Math.Min(System.Math.Max(lon, 34.2), 35.9), System.Math.Min(System.Math.Max(lat, 29.45), 33.35), 0);
- at.y = edge.y = map.Terrain.SampleHeight(edge);
- var colours = new Color[1];
- yield return RenderAt(edge, 90000f, new[] { at }, colours);
- TestContext.WriteLine($"{name}: {colours[0]}");
- Assert.IsTrue(land ? LandColour(colours[0]) : SeaColour(colours[0]), $"{name}: {(land ? "land" : "sea")} expected, rendered {colours[0]}");
+ var edge = map.Frame.ToWorld(lon, lat, 0); edge.y = map.Terrain.SampleHeight(edge);
+ var table = edge + outward * past; table.y = 0f;
+ var top = edge + outward * crown; top.y = topY;
+ var colours = new Color[2];
+ yield return RenderAt(edge, 90000f, new[] { table, top }, colours, 2);
+ Color t = colours[0], f = colours[1];
+ TestContext.WriteLine($"{name}: table {t}, frame {f}");
+ Assert.IsTrue(t.r > t.g && t.g > t.b, $"{name}: warm wood, rendered {t}");
+ Assert.Less(RenderSample.Luma(t), 0.3f, $"{name}: a dark table, rendered {t}");
+ Assert.Greater(RenderSample.Luma(f), RenderSample.Luma(t) + 0.03f, $"{name}: the frame ({f}) reads against the table ({t})");
}
}
@@ -385,80 +410,6 @@ public class MapSceneTests
Assert.Greater(seen, 0, "the rift has settlement markers to check");
}
- /// <summary>Fix round 1 (the sea seam), rendered: at the west and north-west edges of the map, the sea on the terrain and
- /// the sea beyond it come out the same colour under the scene's own light and camera rig, measured before the grade
- /// (0.012): the grade is a per-pixel LUT (and a vignette that is flat this close to the centre), so it cannot open a
- /// seam, only scale one (Task 4). The shipped, graded frame is checked too, with the bound scaled by the grade's
- /// chroma gain of about 2 (0.024).</summary>
- [UnityTest]
- 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). 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();
- yield return null;
- 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. 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
- {
- // Visual v1 Task 4 (kept at the merge point): measured before the grade against 0.012 and on the shipped, graded
- // frame against 0.024 (the grade scales the sea's chroma by about 2). Tilt-shift off: a colour test whose close
- // strips lie in the blurred bands at some yaws (task-3 carry m6).
- RenderSample.TiltShift(false);
- // Sea round 2 (#388): the far sea's texture (a 2.5 km mottle) varies by itself between points 5 km apart, so it
- // is off here; SeaTests.TheFarSeaTextureHasNoStepAtTheMapEdge checks the edge with it on, as a step.
- VisualToggles.Set("seatexture", false);
- foreach (var graded in new[] { false, true })
- foreach (var grid in new[] { false, true })
- {
- VisualToggles.Set("grade", graded);
- VisualToggles.Set("grid", grid);
- 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, 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)
- {
- rig.LookAt = look; rig.Distance = 120000f; rig.Yaw = yaw; rig.TopInset = 0; rig.Apply();
- var y = map.Terrain.SampleHeight(inside);
- 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);
- float bound = graded ? 0.024f : 0.012f;
- TestContext.WriteLine($"seam graded={graded} grid={grid} at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}, difference {diff:0.000} (bound {bound})");
- Assert.Less(diff, bound, $"seam graded={graded} grid={grid} at {look}, x +-{inside.x:0} m, yaw {yaw}: terrain sea {a}, beyond {b}");
- }
- }
- }
- finally { VisualToggles.Set("grid", true); VisualToggles.Set("grade", true); VisualToggles.Set("seatexture", true); RenderSample.TiltShift(true); }
- }
-
/// <summary>Playtest 1, item 3: with the top bar covering the top <c>TopInset</c> of the screen, the look-at point is
/// framed in the middle of the map area below the bar, not in the middle of the whole screen.</summary>
[Test]
@@ -541,18 +492,18 @@ public class MapSceneTests
public void BuildWithoutMaterialsNamesTheMissingField()
{
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load(TerrainMatPath), null, Load(SelectionMatPath), Load(SeaMatPath), Load(BorderLandMatPath));
+ map.Configure(Load(TerrainMatPath), null, Load(SelectionMatPath), Load(SeaMatPath), Load(FrameMatPath));
var ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());
StringAssert.Contains("markerMaterial", ex.Message);
- map.Configure(Load(TerrainMatPath), Load(MarkerMatPath), null, Load(SeaMatPath), Load(BorderLandMatPath));
+ map.Configure(Load(TerrainMatPath), Load(MarkerMatPath), null, Load(SeaMatPath), Load(FrameMatPath));
ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());
StringAssert.Contains("selectionMaterial", ex.Message);
- map.Configure(Load(TerrainMatPath), Load(MarkerMatPath), Load(SelectionMatPath), null, Load(BorderLandMatPath));
+ map.Configure(Load(TerrainMatPath), Load(MarkerMatPath), Load(SelectionMatPath), null, Load(FrameMatPath));
ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());
StringAssert.Contains("seaMaterial", ex.Message);
map.Configure(Load(TerrainMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), null);
ex = Assert.Throws<System.InvalidOperationException>(() => map.Build());
- StringAssert.Contains("borderLandMaterial", ex.Message);
+ StringAssert.Contains("frameMaterial", ex.Message);
}
[Test]
@@ -579,7 +530,7 @@ public class MapSceneTests
var map = NewMap(); map.Build();
var go = map.gameObject; Object.DestroyImmediate(map);
var fresh = go.AddComponent<MapScene>();
- fresh.Configure(Load(TerrainMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), Load(BorderLandMatPath));
+ fresh.Configure(Load(TerrainMatPath), Load(MarkerMatPath), Load(SelectionMatPath), Load(SeaMatPath), Load(FrameMatPath));
fresh.Build();
AssertOneOfEach();
}
diff --git a/unity/Assets/Tests/EditMode/TerrainShaderTests.cs b/unity/Assets/Tests/EditMode/TerrainShaderTests.cs
index 1b90292e3..df39e5360 100644
--- a/unity/Assets/Tests/EditMode/TerrainShaderTests.cs
+++ b/unity/Assets/Tests/EditMode/TerrainShaderTests.cs
@@ -187,7 +187,10 @@ public class TerrainShaderTests
/// <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>
+ /// takes the water haze, so the full width is measured again (Task 7 fix round 1). Since issue #36 the outer columns
+ /// are the frame and the table, not the skirt, so the bands are the board's columns, 0.3-0.7 of the width, as in
+ /// TheHazeStartsBeyondTheNearestDioramaLandAndGrowsWithDistance (at this pose the far band's board edges lie at about
+ /// 0.28 and 0.72, a margin of 0.02).</summary>
[UnityTest]
public IEnumerator TheHazeThickensWithDistance()
{
@@ -197,7 +200,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 = 0f, x1 = 1f;
+ const float x0 = 0.3f, x1 = 0.7f;
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}");
@@ -206,7 +209,10 @@ 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. Full width, as in TheHazeThickensWithDistance (Task 7 fix round 1: the sea is hazed too).</summary>
+ /// more. Since issue #36 the outer columns of the view are the frame and the dark table, whose luma any haze moves
+ /// several times more than the sand's (full width, near band 0.024), so the bands are the board's columns, 0.3-0.7 of
+ /// the width, which hold the sea and the land in every band at this pose (the far band's board edges lie at about
+ /// 0.28 and 0.72: a pose change that narrows the board at the top must revisit these columns).</summary>
[UnityTest]
public IEnumerator TheHazeStartsBeyondTheNearestDioramaLandAndGrowsWithDistance()
{
@@ -216,7 +222,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(0f, y0, 1f, y1) - clear.MeanLuma(0f, y0, 1f, y1));
+ float Shift(float y0, float y1) => Mathf.Abs(hazy.MeanLuma(0.3f, y0, 0.7f, y1) - clear.MeanLuma(0.3f, y0, 0.7f, 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");
diff --git a/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs b/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs
index fec3e85fb..b10fcc561 100644
--- a/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitShowcaseTests.cs
@@ -167,7 +167,7 @@ public class UnitShowcaseTests
{
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("BorderLand"));
+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));
map.Build();
return map;
}
diff --git a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
index fcfa173a2..393cfc40b 100644
--- a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
@@ -246,7 +246,7 @@ public class UnitsInPlayTests
{
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var map = new GameObject("MapScene").AddComponent<MapScene>();
- map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("BorderLand"));
+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));
// The towns' footprints as the game sizes them (its kits read the 1945 populations), whatever an earlier test left.
Statecraft.Game.Map.Kits.KitPopulation.Use(Statecraft.Game.Map.Kits.KitPopulation.Parse(
File.ReadAllText(Path.Combine(Paths.Content, "map", Statecraft.Game.Map.Kits.KitPopulation.FileName))));