A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
feat(visual): coast-graded water with foam and salt rims on both sides of the map's edge; the plateau skirt holds its height
eyalgolan67571684a4df
diff --git a/docs/visual-v1.md b/docs/visual-v1.mdindex 0e3317765..a91aa5dd0 100644--- a/docs/visual-v1.md+++ b/docs/visual-v1.md@@ -120,9 +120,48 @@ x 0.45-0.6) R-B 0.158 -> 0.229, saturation 0.254 -> 0.363, luma 0.576 -> 0.572.-> 0.040, contrast 0.163 -> 0.173, palette distance 0.69 -> 0.66. The checkpoint also shoots the 6 km hero zoom over theJudean slopes and the Negev (`PromoPose.CloseChecks`, haze off): no AO steps.+## Task 7: sea+One water function (`StatecraftMap.hlsl` `ScWaterShade`) on both sides of the map's edge: the terrain graph outputs it as+emission on a black, fully metallic, fully occluded surface, and the border skirt's `Sea.mat` (`Statecraft/Sea`, passes+`Sea`, `DepthOnly`, `DepthNormals`) returns it directly. It is driven by Task 5's coast distance: a turquoise -> teal -> navy+ramp over 12 km, foam within 350 m, the Dead Sea pale turquoise with a white salt rim. It samples the main light's shadows+itself, takes the cooler water haze (`ScHazeWater`), and falls back to the flat sea colour under the `water` toggle. WebGL+build: 77.1 MB, no `Shader error`. GLES3: `ShaderChecks.Gles3Errors` is empty for `Statecraft/Sea` and the terrain (no+`require`).++Deviations from the plan:+- **Glint 0.06, not 0.25.** With `Map.unity`'s default 50-degree sun, the camera's 50-degree pitch at 120 km meets the+ reflection at yaw 180. There the 0.25 lobe lit a warm patch rising 0.08 in sRGB red over 6 km of open sea, and the seam+ test (samples 5 km apart) read it as a 0.031 seam. A profile across the edge showed no step at the edge itself, and the+ difference scaled with the glint. At 0.06, every seam line is <= 0.004.+- **The held skirt is averaged along the edge.** Holding each edge vertex's own height for 20 km+ (`SkirtFall = {0, 0.05, 0.15, 0.45, 1}`) drew the edge's ridges out as long stripes across the Jordan skirt (checkpoint+ t07-sea, first run). Rings 1-4 now hold the edge height averaged over +-8 km (`MapBuilder.SkirtHoldSmoothingM`). Ring 0+ still meets the terrain exactly. New test `TheHeldSkirtCarriesThePlateauNotTheEdgesRidges`: the mean spoke-to-spoke step+ 20 km out is 8.5 m against 36.7 m at the edge (31.2 m before).++| Run | Lines |+|---|---|+| headless | `PROFILE summary visual=all pose=gameplay03 runs=3 median_avg_ms=2.38 spread_ms=0.42 median_p95_ms=4.00`<br>`PROFILE summary visual=-haze pose=gameplay03 runs=3 median_avg_ms=2.35 spread_ms=0.08 median_p95_ms=4.00`<br>`PROFILE summary visual=-water pose=gameplay03 runs=3 median_avg_ms=1.70 spread_ms=0.61 median_p95_ms=3.00`<br>`PROFILE summary visual=none pose=gameplay03 runs=3 median_avg_ms=1.72 spread_ms=0.27 median_p95_ms=2.00`<br>`PROFILE summary visual=all pose=diorama02 runs=3 median_avg_ms=7.64 spread_ms=1.56 median_p95_ms=9.00`<br>`PROFILE summary visual=-haze pose=diorama02 runs=3 median_avg_ms=7.67 spread_ms=0.29 median_p95_ms=8.00`<br>`PROFILE summary visual=-water pose=diorama02 runs=3 median_avg_ms=7.78 spread_ms=0.35 median_p95_ms=9.00`<br>`PROFILE summary visual=none pose=diorama02 runs=3 median_avg_ms=7.48 spread_ms=0.02 median_p95_ms=8.00` |+| boot, `--cpu 1` | `BOOT map_build_ms median=472 runs=3 cpu=1`<br>`BOOT first_frame_ms median=3592 runs=3 cpu=1` (budgets 743 / 5321 ms: within) |++Against Task 6 fix round 1 (`all`): gameplay03 2.41 -> 2.38 ms, diorama02 7.29 -> 7.64 ms (+0.35 ms, inside 2.5 ms plus the+spread). Water costs 0.68 ms at gameplay03 (`all` - `-water`, against a 0.61 ms spread) and nothing measurable at+diorama02 (-0.14 ms), well inside 2.5 ms. The profile ran on the build before the skirt averaging, which changes no+shader. The boot lines are from the final build.++Art (WebGL): diorama02 saturation 0.41 -> 0.39, contrast 0.173 -> 0.186, warmth 0.038 -> 0.058, palette distance 0.78 ->+0.76. gameplay03 contrast 0.173 -> 0.194, palette distance 0.66 -> 0.65. The sea grades from turquoise shallows with a+foam line to navy, and the Dead Sea is pale turquoise with white salt rims. Coast streaks: none visible. A 12x high-pass of+the gameplay03 coast shows only the foam band's waves and single-level output steps in the deep water, so the bake's+distance needs no smoothing (Task 5 carry). Plateau edge (diorama02): the Jordanian plateau now continues past the east+edge at the edge's broad height instead of sagging at once, as a flat muted band level with the map's eastern rim. A+faint low-contrast banding remains there at grazing angles.+## Checkpoints| Task | Name | Images | Owner verdict ||---|---|---|---|| 1 | t01-before | captures/visual/t01-before/*-compare*.png | (owner) || 6 | t06-terrain | captures/visual/t06-terrain/*-compare*.png, editor/*-compare*.png | (owner) || 6 (fix 1) | t06-terrain-r1 | captures/visual/t06-terrain-r1/*-compare*.png, hero06judea.png, hero06negev.png, editor/*-compare*.png | (owner) |+| 7 | t07-sea | captures/visual/t07-sea/*-compare*.png, hero06judea.png, hero06negev.png, editor/*-compare*.png | (owner) |diff --git a/unity/Assets/Editor/MapMaterials.cs b/unity/Assets/Editor/MapMaterials.csindex 8e76e7dbb..badadfb14 100644--- a/unity/Assets/Editor/MapMaterials.cs+++ b/unity/Assets/Editor/MapMaterials.cs@@ -33,13 +33,9 @@ namespace Statecraft.Game.EditorToolsEditorUtility.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 sea past the map's edge: URP Lit in the sea biome colour, matte like the terrain's layers, so it is lit as the- // terrain's sea is and no seam shows at the edge (fix round 1).- var sea = Make(SeaPath, "Universal Render Pipeline/Lit", Statecraft.Game.Map.MapBuilder.BiomeColours["sea"]);- // Terrain/Lit keeps its specular and environment reflections at smoothness 0, so the plane keeps them too.- sea.SetFloat("_Smoothness", 0f); sea.SetFloat("_Metallic", 0f);- sea.SetFloat("_SpecularHighlights", 1f); sea.SetFloat("_EnvironmentReflections", 1f);- sea.DisableKeyword("_SPECULARHIGHLIGHTS_OFF"); sea.DisableKeyword("_ENVIRONMENTREFLECTIONS_OFF");+ // The skirt's sea past the map's edge: the terrain's own water shading (StatecraftMap.hlsl ScWaterShade), so no seam.+ 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).diff --git a/unity/Assets/Materials/Sea.mat b/unity/Assets/Materials/Sea.matindex eb7326bed..5190bb119 100644--- a/unity/Assets/Materials/Sea.mat+++ b/unity/Assets/Materials/Sea.mat@@ -8,7 +8,7 @@ Material:m_PrefabInstance: {fileID: 0}m_PrefabAsset: {fileID: 0}m_Name: Sea- m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}+ m_Shader: {fileID: 4800000, guid: 2b62f1bce4cbb49d593755018e02974e, type: 3}m_Parent: {fileID: 0}m_ModifiedSerializedProperties: 0m_ValidKeywords: []@@ -17,8 +17,7 @@ Material:m_EnableInstancingVariants: 1m_DoubleSidedGI: 0m_CustomRenderQueue: -1- stringTagMap:- RenderType: Opaque+ stringTagMap: {}disabledShaderPasses:- MOTIONVECTORSm_LockedProperties:@@ -65,6 +64,10 @@ Material:m_Texture: {fileID: 0}m_Scale: {x: 1, y: 1}m_Offset: {x: 0, y: 0}+ - _ScCoastTex:+ m_Texture: {fileID: 2800000, guid: ac04311e70bde4db0a5e4129f5d58af1, type: 3}+ m_Scale: {x: 1, y: 1}+ m_Offset: {x: 0, y: 0}- _SpecGlossMap:m_Texture: {fileID: 0}m_Scale: {x: 1, y: 1}diff --git a/unity/Assets/Scripts/Map/MapBuilder.cs b/unity/Assets/Scripts/Map/MapBuilder.csindex fbd752ea4..0e4774f7b 100644--- a/unity/Assets/Scripts/Map/MapBuilder.cs+++ b/unity/Assets/Scripts/Map/MapBuilder.cs@@ -167,11 +167,17 @@ namespace Statecraft.Game.Mapreturn tex;}- /// <summary>Distances (m) of the border skirt's rings from the map's edge: land falls from the edge's height to sea- /// level across the first rings, then stays flat to the last, beyond anything the camera can see.</summary>+ /// <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).</summary>- static readonly float[] SkirtFall = { 0f, 0.4f, 0.85f, 1f, 1f };+ /// <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;@@ -189,15 +195,23 @@ namespace Statecraft.Game.Mapint samples = data.heightmapResolution - 1;var verts = new List<Vector3>(); var sea = new List<int>(); var land = new List<int>();bool IsLand(float h) => Mathf.Abs(h / VerticalExaggeration + elevMinM) > SeaToleranceM;+ // The edge's height averaged along the edge over +-SkirtHoldSmoothingM (17 samples, clamped to the map).+ float Held(Vector2 p, Vector2 outward)+ {+ var along = new Vector2(outward.y, -outward.x);+ float sum = 0f;+ for (int j = -8; j <= 8; j++) sum += Height(p + along * (SkirtHoldSmoothingM * j / 8f));+ return sum / 17f;+ }// One ring of vertices outward from an edge point; returns the index of its first vertex.int Spoke(Vector2 p, Vector2 outward, bool isLand, Vector2? outward2 = null){- float h = data.GetInterpolatedHeight(Mathf.Clamp01(p.x / size.x), Mathf.Clamp01(p.y / size.z));+ float h = Height(p), held = isLand ? Held(p, outward) : seaY;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(h, seaY, SkirtFall[k]) : seaY;+ float y = isLand ? Mathf.Lerp(held, seaY, SkirtFall[k]) : seaY;if (k == 0) y = h; // meets the terrain's edge exactlyverts.Add(new Vector3(q.x, y, q.y));}diff --git a/unity/Assets/Scripts/Map/MapShaderGlobals.cs b/unity/Assets/Scripts/Map/MapShaderGlobals.csindex 97c4760bd..340a18e7a 100644--- a/unity/Assets/Scripts/Map/MapShaderGlobals.cs+++ b/unity/Assets/Scripts/Map/MapShaderGlobals.cs@@ -10,7 +10,7 @@ namespace Statecraft.Game.Map{public static readonly int Map = Shader.PropertyToID("_ScMap"), MapOrigin = Shader.PropertyToID("_ScMapOrigin"),Biome = Shader.PropertyToID("_ScBiomeTex"), Haze = Shader.PropertyToID("_ScHaze"), HazeWater = Shader.PropertyToID("_ScHazeWater"),- HazeRange = Shader.PropertyToID("_ScHazeRange");+ HazeRange = Shader.PropertyToID("_ScHazeRange"), WaterOn = Shader.PropertyToID("_ScWaterOn");/// <summary>A warm, dusty haze over land (sRGB): warmer than the ground it covers (R - B 0.26), so the far land reads/// as dust, not as a cool milky veil (Task 6 review I1).</summary>@@ -43,6 +43,8 @@ namespace Statecraft.Game.MapShader.SetGlobalVector(Haze, haze);Shader.SetGlobalVector(HazeWater, hazeWater);Shader.SetGlobalVector(HazeRange, new Vector4(Y(RiftHazeTopM), Y(RiftHazeFullM), HazeDistanceM, HazeStartM));+ Shader.SetGlobalFloat(WaterOn, 1f);+ assets.OnTeardown(VisualToggles.Register("water", on => Shader.SetGlobalFloat(WaterOn, on ? 1f : 0f)));assets.OnTeardown(VisualToggles.Register("haze", on =>{Shader.SetGlobalVector(Haze, on ? haze : new Vector4(haze.x, haze.y, haze.z, 0f));diff --git a/unity/Assets/Shaders/Sea.shader b/unity/Assets/Shaders/Sea.shadernew file mode 100644index 000000000..7edfedbf4--- /dev/null+++ b/unity/Assets/Shaders/Sea.shader@@ -0,0 +1,77 @@+// The border skirt's sea past the map's edge (plan Task 7): the same water as the terrain's own sea, from the same function+// (StatecraftMap.hlsl ScWaterShade) and coast texture (clamped at the edge), with the same water haze, so no seam shows. Unlit:+// the function lights itself, as the terrain graph's water (emission only) does. DepthOnly and DepthNormals passes keep it+// in the depth prepass on tiers that make one.+Shader "Statecraft/Sea"+{+ Properties+ {+ [NoScaleOffset] _ScCoastTex ("Coast distance (R)", 2D) = "black" {}+ }+ SubShader+ {+ Tags { "RenderType" = "Opaque" "Queue" = "Geometry" "RenderPipeline" = "UniversalPipeline" }+ HLSLINCLUDE+ #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"+ CBUFFER_START(UnityPerMaterial)+ float _ScSeaUnused; // the SRP Batcher needs a UnityPerMaterial buffer; the sea has no per-material numbers+ CBUFFER_END+ struct Attributes { float4 positionOS : POSITION; };+ ENDHLSL++ Pass+ {+ Name "Sea"+ Tags { "LightMode" = "UniversalForward" }+ HLSLPROGRAM+ #pragma vertex Vert+ #pragma fragment Frag+ // The main light's shadows, as the terrain graph's forward pass has them (ScWaterShade samples them).+ #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"+ TEXTURE2D(_ScCoastTex); SAMPLER(sampler_ScCoastTex);+ struct Varyings { float4 positionCS : SV_POSITION; float3 positionWS : TEXCOORD0; };+ Varyings Vert(Attributes input)+ {+ Varyings o;+ VertexPositionInputs p = GetVertexPositionInputs(input.positionOS.xyz);+ o.positionCS = p.positionCS; o.positionWS = p.positionWS;+ return o;+ }+ half4 Frag(Varyings input) : SV_Target+ {+ float2 mapM = input.positionWS.xz - _ScMapOrigin.xz;+ float coast = SAMPLE_TEXTURE2D(_ScCoastTex, sampler_ScCoastTex, saturate(mapM / _ScMap.xy)).r;+ return half4(ScHazeWater(ScWaterShade(coast, 0.0, input.positionWS, mapM), input.positionWS), 1.0);+ }+ ENDHLSL+ }+ Pass+ {+ Name "DepthOnly"+ Tags { "LightMode" = "DepthOnly" }+ ZWrite On+ ColorMask R+ HLSLPROGRAM+ #pragma vertex Vert+ #pragma fragment Frag+ float4 Vert(Attributes input) : SV_POSITION { return TransformObjectToHClip(input.positionOS.xyz); }+ half Frag() : SV_Target { return 0; }+ ENDHLSL+ }+ Pass+ {+ Name "DepthNormals"+ Tags { "LightMode" = "DepthNormals" }+ ZWrite On+ HLSLPROGRAM+ #pragma vertex Vert+ #pragma fragment Frag+ float4 Vert(Attributes input) : SV_POSITION { return TransformObjectToHClip(input.positionOS.xyz); }+ half4 Frag() : SV_Target { return half4(0.0, 1.0, 0.0, 0.0); } // the sea faces up+ ENDHLSL+ }+ }+}diff --git a/unity/Assets/Shaders/Sea.shader.meta b/unity/Assets/Shaders/Sea.shader.metanew file mode 100644index 000000000..36718ec8c--- /dev/null+++ b/unity/Assets/Shaders/Sea.shader.meta@@ -0,0 +1,9 @@+fileFormatVersion: 2+guid: 2b62f1bce4cbb49d593755018e02974e+ShaderImporter:+ externalObjects: {}+ defaultTextures: []+ nonModifiableTextures: []+ userData:+ assetBundleName:+ assetBundleVariant:diff --git a/unity/Assets/Shaders/StatecraftMap.hlsl b/unity/Assets/Shaders/StatecraftMap.hlslindex 4602e5768..28e3f2ed2 100644--- a/unity/Assets/Shaders/StatecraftMap.hlsl+++ b/unity/Assets/Shaders/StatecraftMap.hlsl@@ -46,6 +46,55 @@ float3 ScHazeWater(float3 colour, float3 positionWS)// 1 in water, 0 on land; coast is the signed distance texture (0.5 at the shore, tools/terrain_bake.py).float ScWater(float coast) { return 1.0 - smoothstep(0.497, 0.503, coast); }+static const float ScCoastRangeM = 12000.0; // tools/terrain_bake.py COAST_RANGE_M+float _ScWaterOn; // 1 = shaded water, 0 = the flat sea colour (the "water" toggle)++// The water's lit colour before haze (callers apply ScHazeWater and output it as is): a turquoise -> teal -> navy ramp with+// distance from the shore; the Dead Sea (below -300 m) pale turquoise with a white salt rim, the Sea of Galilee a fresher+// teal; two scrolling noise layers tilt a wave normal for Lambert from the sun (with its shadows: cliffs shade the water)+// plus sky fill and a small glint; animated foam bands within 350 m of the shore. elevM is the real elevation of the water+// surface; mapM metres east and north of the map's south-west corner.+float3 ScWaterShade(float coast, float elevM, float3 positionWS, float2 mapM)+{+ if (_ScWaterOn < 0.5) return SRGBToLinear(float3(0.16, 0.42, 0.55)) * 0.8;+ float offshoreM = saturate(0.5 - coast) * 2.0 * ScCoastRangeM;+ float t = pow(saturate(offshoreM / ScCoastRangeM), 0.55);+ float3 shallow = SRGBToLinear(float3(0.38, 0.74, 0.72));+ float3 mid = SRGBToLinear(float3(0.13, 0.47, 0.58));+ float3 deep = SRGBToLinear(float3(0.06, 0.24, 0.40));+ float3 c = t < 0.5 ? lerp(shallow, mid, t * 2.0) : lerp(mid, deep, t * 2.0 - 1.0);+ float salt = step(elevM, -300.0);+ float fresh = step(elevM, -100.0) * (1.0 - salt);+ c = lerp(c, SRGBToLinear(float3(0.45, 0.78, 0.78)), salt * 0.8);+ c = lerp(c, SRGBToLinear(float3(0.15, 0.48, 0.60)), fresh * 0.7);++ float time = _Time.y;+ float2 p = mapM / 700.0;+ float2 g = float2(ScNoise(p + float2(time * 0.05, 0.0)) - ScNoise(p + float2(0.37 + time * 0.05, 0.0)),+ ScNoise(p.yx + float2(0.0, time * 0.04)) - ScNoise(p.yx + float2(0.0, 0.41 + time * 0.04)));+ float3 n = normalize(float3(g.x * 0.15, 1.0, g.y * 0.15));+#if defined(UNIVERSAL_REALTIME_LIGHTS_INCLUDED) && !defined(SHADERGRAPH_PREVIEW)+ Light sun = GetMainLight(TransformWorldToShadowCoord(positionWS)); // review I6: the water receives the sun's shadows+ float3 l = sun.direction, lc = sun.color;+ float shadow = sun.shadowAttenuation;+#else+ float3 l = normalize(float3(-0.83, 0.5, 0.22)), lc = float3(1.0, 0.84, 0.64); // passes without lights (depth, preview)+ float shadow = 1.0;+#endif+ float3 v = normalize(_WorldSpaceCameraPos - positionWS);+ float3 lit = c * (0.55 + 0.45 * saturate(dot(n, l)) * lc * shadow);+ // A small glint (Task 7: 0.06, not the plan's 0.25). Where the camera's pitch meets the sun's height (50 deg each with+ // Map.unity's default sun, at yaw 180) the 0.25 lobe lit a warm patch rising 0.08 in sRGB red over 6 km of open sea, a+ // view-dependent gradient that read as a seam between samples 5 km apart either side of the map's edge.+ lit += pow(saturate(dot(reflect(-l, n), v)), 80.0) * 0.06 * lc * shadow;++ float band = 1.0 - smoothstep(0.0, 350.0, offshoreM);+ float waves = 0.7 + 0.3 * sin(offshoreM / 90.0 - time * 1.3);+ float rim = salt * (1.0 - smoothstep(0.0, 900.0, offshoreM));+ float foam = saturate(band * waves * (1.0 - salt) + rim);+ return lerp(lit, SRGBToLinear(float3(0.93, 0.95, 0.94)), foam * 0.85);+}+// The painted ground: biome colour, warmer stone high up, a dusty rift floor, rock on steep slopes, two octaves of// breakup, curvature (ridges light, hollows dark) and the baked occlusion (bake: r AO from ao.png, g curvature, b sky-view).float3 ScGround(float2 uv, float2 mapM, float3 n, float3 positionWS, float4 bake)diff --git a/unity/Assets/Shaders/StatecraftTerrain.hlsl b/unity/Assets/Shaders/StatecraftTerrain.hlslindex 70b8a326e..ab4264211 100644--- a/unity/Assets/Shaders/StatecraftTerrain.hlsl+++ b/unity/Assets/Shaders/StatecraftTerrain.hlsl@@ -18,14 +18,17 @@ void StatecraftTerrain_float(float2 UV, float3 PositionWS, float3 NormalWS, Unitfloat h = _ScHaze.a * ScHazeAmount(PositionWS); // land haze, applied after lighting via Emissionfloat ao = bake.r * lerp(0.6, 1.0, bake.b);float water = ScWater(coast);- // Water: the flat sea colour, lit like the skirt's URP Lit Sea.mat so the map's edge shows no seam (Task 7 replaces- // both sides with ScWaterShade together). No haze on water yet: the skirt's URP Lit sea has none either.- BaseColor = lerp(ground * (1.0 - h), SRGBToLinear(float3(0.16, 0.42, 0.55)), water);+ // Water: ScWaterShade's colour (sunlit with its shadows, then the cool water haze) as emission on a black, fully metallic,+ // fully occluded surface, so Lit adds nothing (no diffuse, specular colour 0, indirect light times occlusion 0): exactly+ // what Sea.shader returns past the edge. Land keeps its after-lighting haze through the same Emission.+ float elevM = (PositionWS.y - _ScMap.z) / _ScMap.w;+ float3 waterColour = ScHazeWater(ScWaterShade(coast, elevM, PositionWS, mapM), PositionWS);+ BaseColor = ground * (1.0 - h) * (1.0 - water);NormalOut = normalize(lerp(n, float3(0, 1, 0), water));- Occlusion = lerp(lerp(1.0, ao, 0.8), 1.0, water);+ Occlusion = lerp(lerp(1.0, ao, 0.8), 0.0, water);Smoothness = 0.0;- Metallic = 0.0;- Emission = _ScHaze.rgb * h * (1.0 - water);+ Metallic = water;+ Emission = lerp(_ScHaze.rgb * h, waterColour, water);}#endifdiff --git a/unity/Assets/Tests/EditMode/SeaTests.cs b/unity/Assets/Tests/EditMode/SeaTests.csnew file mode 100644index 000000000..e12aa9c2f--- /dev/null+++ b/unity/Assets/Tests/EditMode/SeaTests.cs@@ -0,0 +1,162 @@+#nullable enable+using System.Collections;+using System.IO;+using NUnit.Framework;+using Statecraft.Game.Map;+using UnityEditor;+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>+public class SeaTests+{+ const string SeaMatPath = "Assets/Materials/Sea.mat";++ [TearDown]+ public void Reset() { EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear(); }++ static MapScene OpenMap()+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build();+ return map;+ }++ [Test]+ public void TheSkirtSeaUsesTheWaterShaderWithTheCoastTexture()+ {+ var sea = AssetDatabase.LoadAssetAtPath<Material>(SeaMatPath);+ Assert.AreEqual("Statecraft/Sea", sea.shader.name);+ Assert.IsFalse(ShaderUtil.ShaderHasError(sea.shader));+ Assert.AreEqual(AssetDatabase.LoadAssetAtPath<Texture2D>(MapTexturePaths.Coast), sea.GetTexture("_ScCoastTex"));+ Assert.GreaterOrEqual(sea.FindPass("DepthOnly"), 0, "in the depth prepass, like the selection band (m3-fix N6)");+ Assert.GreaterOrEqual(sea.FindPass("DepthNormals"), 0);+ }++ [Test]+ public void TheWaterShadersCompileForWebGL2()+ {+ CollectionAssert.IsEmpty(ShaderChecks.Gles3Errors(Shader.Find("Statecraft/Sea")));+ CollectionAssert.IsEmpty(ShaderChecks.Gles3Errors(AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Terrain.mat").shader));+ }++ /// <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).</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.25f * edge, "the held rings carry the plateau's broad height, not the edge's ridges");+ }++ static float Luma(Color c) => RenderSample.Luma(c);++ /// <summary>Rendered west of Tel Aviv: just offshore (inside the 350 m foam band) is brighter than 1.2 km out, which is+ /// lighter and greener than the open sea 24 km out. The shore is found in coast.png itself.</summary>+ [UnityTest]+ public IEnumerator ShallowsAreLighterThanTheOpenSeaAndFoamLinesTheShore()+ {+ var map = OpenMap();+ yield return null;+ var coast = new Texture2D(2, 2);+ coast.LoadImage(File.ReadAllBytes(MapTexturePaths.Coast)); // readable copy; row 0 = south+ int row = Mathf.FloorToInt((32.08f - 29.45f) / (33.35f - 29.45f) * coast.height);+ int col = Mathf.FloorToInt((34.95f - 34.2f) / (35.9f - 34.2f) * coast.width);+ while (col > 0 && coast.GetPixel(col, row).r >= 0.5f) col--; // walk west to the first water texel+ Object.DestroyImmediate(coast);+ Vector3 At(int c)+ {+ double lon = 34.2 + (c + 0.5) / 2048.0 * (35.9 - 34.2), lat = 29.45 + (row + 0.5) / 2048.0 * (33.35 - 29.45);+ var w = map.Frame.ToWorld(lon, lat, 0); w.y = map.Terrain.SampleHeight(w); return w;+ }+ Vector3 foam = At(col - 2), shallow = At(col - 15), deep = At(col - 300);+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();+ rig.LookAt = shallow; rig.Distance = 30000f; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();+ var px = new Vector2[2];+ var near = RenderSample.Render(cam, 960, 540, new[] { foam, shallow }, px);+ Color f = near.Mean((int)px[0].x, (int)px[0].y, 1), s = near.Mean((int)px[1].x, (int)px[1].y, 1);+ rig.LookAt = deep; rig.Apply();+ var far = RenderSample.Render(cam, 960, 540, new[] { deep }, px);+ Color d = far.Mean((int)px[0].x, (int)px[0].y, 2);+ TestContext.WriteLine($"foam {f}, shallow {s}, deep {d}");+ Assert.Greater(Luma(f), Luma(s) + 0.02f, "foam at the shore");+ Assert.Greater(Luma(s), Luma(d) + 0.05f, "shallows lighter");+ Assert.Greater(s.g / s.b, d.g / d.b, "shallows greener");+ }++ /// <summary>Rendered: the Dead Sea is pale turquoise, much lighter than the open Mediterranean.</summary>+ [UnityTest]+ public IEnumerator TheDeadSeaIsPalerThanTheOpenSea()+ {+ var map = OpenMap();+ yield return null;+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();+ Color Sample(double lon, double lat)+ {+ var w = map.Frame.ToWorld(lon, lat, 0); w.y = map.Terrain.SampleHeight(w);+ rig.LookAt = w; rig.Distance = 40000f; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();+ var px = new Vector2[1];+ var r = RenderSample.Render(cam, 480, 270, new[] { w }, px);+ return r.Mean((int)px[0].x, (int)px[0].y, 2);+ }+ Color dead = Sample(35.50, 31.50), med = Sample(34.40, 32.00);+ TestContext.WriteLine($"Dead Sea {dead}, Mediterranean {med}");+ Assert.Greater(Luma(dead), Luma(med) + 0.1f);+ }++ /// <summary>Review I2: at the country-wide pose (about 300 km from the camera) the open sea stays saturated blue under the+ /// water haze: b > r + 0.15 (worked out in Step 4: about 0.21 before the grade). And the water toggle exists.</summary>+ [UnityTest]+ public IEnumerator TheOpenSeaStaysBlueUnderTheHaze()+ {+ var map = OpenMap();+ yield return null;+ CollectionAssert.Contains(VisualToggles.Names, "water");+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();+ PromoPose.Diorama02.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();+ var sea = map.Frame.ToWorld(34.40, 31.80, 0); sea.y = map.Terrain.SampleHeight(sea);+ var px = new Vector2[1];+ var s = RenderSample.Render(cam, 960, 540, new[] { sea }, px);+ var c = s.Mean((int)px[0].x, (int)px[0].y, 2);+ TestContext.WriteLine($"open sea at the diorama pose {c}, b - r = {c.b - c.r:0.000}");+ Assert.Greater(c.b, c.r + 0.15f);+ }+}diff --git a/unity/Assets/Tests/EditMode/SeaTests.cs.meta b/unity/Assets/Tests/EditMode/SeaTests.cs.metanew file mode 100644index 000000000..5cf06df1a--- /dev/null+++ b/unity/Assets/Tests/EditMode/SeaTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 4c84bcd8ef6354304adc6bbfee1037c5\ No newline at end of filediff --git a/unity/Assets/Tests/EditMode/SettlementTests.cs b/unity/Assets/Tests/EditMode/SettlementTests.csindex 470e9ed0f..3a70edc16 100644--- a/unity/Assets/Tests/EditMode/SettlementTests.cs+++ b/unity/Assets/Tests/EditMode/SettlementTests.cs@@ -376,36 +376,28 @@ public class MapSceneTests[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).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;- var rt = new RenderTexture(1600, 900, 24);- var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);- try- {+ foreach (var yaw in new[] { 0f, 90f, 180f, 270f })foreach (var (look, inside, beyond) in new[] {(new Vector3(3000, 0, size.z * 0.55f), new Vector3(2500, 0, size.z * 0.55f), new Vector3(-2500, 0, size.z * 0.55f)),(new Vector3(3000, 0, size.z - 3000), new Vector3(2500, 0, size.z - 2500), new Vector3(-2500, 0, size.z + 2500)) }){- rig.LookAt = look; rig.Distance = 120000f; rig.Yaw = 0; rig.Apply();- cam.targetTexture = rt;- yield return null;- cam.Render();- RenderTexture.active = rt;- tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply();- // Project while the camera still renders into the texture, so the points are in its pixels.- Color Px(Vector3 w) { var p = cam.WorldToScreenPoint(w); return tex.GetPixel((int)p.x, (int)p.y); }- var a = Px(new Vector3(inside.x, map.Terrain.SampleHeight(inside), inside.z));- var b = Px(new Vector3(beyond.x, map.Terrain.SampleHeight(inside), beyond.z));- RenderTexture.active = null; cam.targetTexture = null;+ rig.LookAt = look; rig.Distance = 120000f; rig.Yaw = yaw; rig.TopInset = 0; rig.Apply();+ var y = map.Terrain.SampleHeight(inside);+ var px = new Vector2[2];+ var s = RenderSample.Render(cam, 1600, 900, new[] { new Vector3(inside.x, y, inside.z), new Vector3(beyond.x, y, beyond.z) }, px);+ Color a = s.Mean((int)px[0].x, (int)px[0].y, 3), b = s.Mean((int)px[1].x, (int)px[1].y, 3);var diff = Mathf.Abs(a.r - b.r) + Mathf.Abs(a.g - b.g) + Mathf.Abs(a.b - b.b);- TestContext.WriteLine($"seam at {look}: terrain sea {a}, beyond {b}, difference {diff:0.000}");- Assert.Less(diff, 0.012f, $"seam at {look}: terrain sea {a}, beyond {b}");+ TestContext.WriteLine($"seam at {look}, yaw {yaw}: terrain sea {a}, beyond {b}, difference {diff:0.000}");+ Assert.Less(diff, 0.012f, $"seam at {look}, yaw {yaw}: terrain sea {a}, beyond {b}");}- }- finally { rt.Release(); Object.DestroyImmediate(rt); Object.DestroyImmediate(tex); }}/// <summary>Playtest 1, item 3: with the top bar covering the top <c>TopInset</c> of the screen, the look-at point is