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.

feat(visual): a low warm sun, a cool fill, shadows fitted to the camera, a 6 km hero zoom

eyalgolan8b20507aa819
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index 4c4928f1e..315217a58 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -65,7 +65,23 @@ Notes:
- Superseded first recording (commit `33fb072`, before the CDP viewport): headless ran at `res=1920x937` and headed at
`res=1728x860`, with a first-pose spread of 0.68 ms (headless) and one headed run that stalled; do not compare with it.
+## Task 2: sun and shadows
+Headless, viewport 1920x1080 at DPR 1 (`res=1920x1080 scale=0.80`), web tier (shadow map 2048, shadow distance fitted to
+1.75 x the rig distance); build from the Task 2 tree on `vis-light`.
+
+| Run | Lines |
+|---|---|
+| headless | `PROFILE summary visual=all pose=gameplay03 runs=3 median_avg_ms=2.11 spread_ms=0.10 median_p95_ms=3.00`<br>`PROFILE summary visual=-shadows pose=gameplay03 runs=3 median_avg_ms=2.43 spread_ms=0.11 median_p95_ms=4.00`<br>`PROFILE summary visual=all pose=diorama02 runs=3 median_avg_ms=10.12 spread_ms=0.43 median_p95_ms=11.00`<br>`PROFILE summary visual=-shadows pose=diorama02 runs=3 median_avg_ms=7.39 spread_ms=0.17 median_p95_ms=8.00` |
+
+Budget check (`median(all) - median(-shadows) <= 2.5 ms + the larger spread`):
+- gameplay03: -0.32 ms (within noise; the 6-60 km view casts few shadows) against 2.61 ms: within.
+- diorama02: 2.73 ms against 2.93 ms (2.5 + 0.43): within, with 0.20 ms to spare. The country-wide pose fits the shadow
+ map over about 400 km of relief; Task 10 should re-check this pose (cascades or a lower cover factor at the far zoom are
+ the levers if the tier review needs headroom).
+- Edit-mode `ReliefCastsShadowsAtMapScale`: shadowed share 3.1 % (floor 2 %) over the Dead Sea escarpment at 60 km.
+
## Checkpoints
| Task | Name | Images | Owner verdict |
|---|---|---|---|
| 1 | t01-before | captures/visual/t01-before/*-compare*.png | (owner) |
+| 2 | t02-light | captures/visual/t02-light/*-compare*.png | (owner) Note: at the new 6 km hero zoom the view is filled by the 600-1,800 m placeholder marker cubes, so judge the zoom range, not the close-up art, until the settlement art track replaces them. |
diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.cs
index 9431b094a..185ab3006 100644
--- a/unity/Assets/Scripts/Map/CameraController.cs
+++ b/unity/Assets/Scripts/Map/CameraController.cs
@@ -23,7 +23,9 @@ namespace Statecraft.Game.Map
[RequireComponent(typeof(CameraRig))]
public sealed class CameraController : MonoBehaviour
{
- public const float MinDistance = 20000f, MaxDistance = 250000f;
+ /// <summary>6 km is the hero zoom (owner ruling 2026-10-11: symbolic-scale settlements need a closer view); 250 km
+ /// shows the country.</summary>
+ public const float MinDistance = 6000f, MaxDistance = 250000f;
public const float PanPerSecond = 0.8f; // distances per second at full key press
public const float DragPanPerPixel = 0.0012f; // distances per pixel of drag
public const float ZoomPerStep = 0.1f; // fraction of the distance per wheel notch
diff --git a/unity/Assets/Scripts/Map/CameraRig.cs b/unity/Assets/Scripts/Map/CameraRig.cs
index 951e24b7f..44aa61e18 100644
--- a/unity/Assets/Scripts/Map/CameraRig.cs
+++ b/unity/Assets/Scripts/Map/CameraRig.cs
@@ -24,6 +24,7 @@ namespace Statecraft.Game.Map
/// <summary>Undo actions for state Init changes outside the rig (the URP asset's shadow distance...). MapScene.Build hands
/// them to the map's MapRuntimeAssets right after Init, so destroying the map undoes them.</summary>
public readonly List<Action> TeardownActions = new List<Action>();
+ bool initialised; // only a rig the map set up fits the shadow distance (bare rigs in tests must not touch the URP asset)
/// <summary>The global post-processing volume Init creates. Its runtime VolumeProfile must be owned by the caller
/// (MapScene registers it with MapRuntimeAssets).</summary>
@@ -45,6 +46,10 @@ namespace Statecraft.Game.Map
_dof = vol.profile.Add<DepthOfField>(true); _dof.mode.Override(DepthOfFieldMode.Gaussian);
_dof.gaussianMaxRadius.Override(1.5f);
Volume = vol;
+ MapLighting.Apply(MapLighting.FindSun());
+ TeardownActions.Add(VisualToggles.Register("shadows", on => { var sun = MapLighting.FindSun(); if (sun != null) sun.shadows = on ? LightShadows.Soft : LightShadows.None; }));
+ TeardownActions.Add(ShadowFit.Restore);
+ initialised = true;
Apply();
}
@@ -53,6 +58,7 @@ namespace Statecraft.Game.Map
transform.rotation = Quaternion.Euler(Pitch, Yaw, 0);
transform.position = LookAt - transform.forward * Distance;
if (_dof != null) { _dof.gaussianStart.Override(Distance * 1.05f); _dof.gaussianEnd.Override(Distance * 1.8f); }
+ if (initialised) ShadowFit.Apply(Distance);
ApplyProjection();
}
diff --git a/unity/Assets/Scripts/Map/MapLighting.cs b/unity/Assets/Scripts/Map/MapLighting.cs
new file mode 100644
index 000000000..7eab35f51
--- /dev/null
+++ b/unity/Assets/Scripts/Map/MapLighting.cs
@@ -0,0 +1,56 @@
+#nullable enable
+using UnityEngine;
+using UnityEngine.Rendering;
+
+namespace Statecraft.Game.Map
+{
+ /// <summary>The map's light (research notes §1 "Lighting", promo 03): a low, warm late-afternoon sun from the
+ /// west-north-west, whose long shadows fall to the right of the default view, and a cool sky fill that keeps the shadow
+ /// side readable. The sun is fixed in the world, so orbiting the camera moves the light across the screen.</summary>
+ public static class MapLighting
+ {
+ public const float SunElevation = 30f; // degrees above the horizon
+ public const float SunAzimuth = 285f; // degrees clockwise from north: west-north-west
+ public const float SunIntensity = 1.6f;
+ public static readonly Color SunColour = new Color(1.00f, 0.84f, 0.64f);
+ public static readonly Color AmbientSky = new Color(0.52f, 0.60f, 0.72f);
+ public static readonly Color AmbientEquator = new Color(0.48f, 0.46f, 0.42f);
+ public static readonly Color AmbientGround = new Color(0.26f, 0.22f, 0.17f);
+
+ /// <summary>The scene's first directional light, or null.</summary>
+ public static Light? FindSun()
+ {
+ foreach (var l in Object.FindObjectsByType<Light>(FindObjectsSortMode.InstanceID))
+ if (l.type == LightType.Directional) return l;
+ return null;
+ }
+
+ /// <summary>Points, colours and enables shadows on <paramref name="sun"/> (when there is one) and sets the trilight
+ /// ambient and its probe.</summary>
+ public static void Apply(Light? sun)
+ {
+ if (sun != null)
+ {
+ // A light shines along its forward axis: towards the azimuth opposite the sun, tilted down by the elevation.
+ sun.transform.rotation = Quaternion.Euler(SunElevation, SunAzimuth - 180f, 0f);
+ sun.color = SunColour; sun.intensity = SunIntensity;
+ sun.shadows = LightShadows.Soft; sun.shadowStrength = 0.85f;
+ RenderSettings.sun = sun;
+ }
+ RenderSettings.ambientMode = AmbientMode.Trilight;
+ RenderSettings.ambientSkyColor = AmbientSky; RenderSettings.ambientEquatorColor = AmbientEquator; RenderSettings.ambientGroundColor = AmbientGround;
+ RenderSettings.ambientProbe = AmbientProbe();
+ }
+
+ /// <summary>The trilight ambient as spherical harmonics (set explicitly: a runtime change of the trilight colours does
+ /// not rebuild the probe the shaders read).</summary>
+ public static SphericalHarmonicsL2 AmbientProbe()
+ {
+ var sh = new SphericalHarmonicsL2();
+ sh.AddAmbientLight(AmbientEquator);
+ sh.AddDirectionalLight(Vector3.up, AmbientSky - AmbientEquator, 1f);
+ sh.AddDirectionalLight(Vector3.down, AmbientGround - AmbientEquator, 1f);
+ return sh;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/MapLighting.cs.meta b/unity/Assets/Scripts/Map/MapLighting.cs.meta
new file mode 100644
index 000000000..c91809017
--- /dev/null
+++ b/unity/Assets/Scripts/Map/MapLighting.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 53319566bdbf54082b6c9724a514e061
\ No newline at end of file
diff --git a/unity/Assets/Scripts/Map/ShadowFit.cs b/unity/Assets/Scripts/Map/ShadowFit.cs
new file mode 100644
index 000000000..041702381
--- /dev/null
+++ b/unity/Assets/Scripts/Map/ShadowFit.cs
@@ -0,0 +1,35 @@
+#nullable enable
+using UnityEngine;
+using UnityEngine.Rendering.Universal;
+
+namespace Statecraft.Game.Map
+{
+ /// <summary>Shadows at map scale (research notes §0.2): URP has no per-camera shadow distance, so the active URP asset's
+ /// shadowDistance follows the rig's distance, and Restore puts the asset's own value back (the map registers Restore as a
+ /// teardown action, so destroying the map, a rebuild or the end of a test leaves the asset as it was).</summary>
+ public static class ShadowFit
+ {
+ /// <summary>View depth of the top screen row is 1.66 x the rig distance at the largest top inset (LightingTests).</summary>
+ public const float CoverFactor = 1.75f;
+ public const float MinDistanceM = 3000f, MaxDistanceM = 450000f;
+
+ static UniversalRenderPipelineAsset? touched;
+ static float original;
+
+ public static float Distance(float cameraDistance) => Mathf.Clamp(cameraDistance * CoverFactor, MinDistanceM, MaxDistanceM);
+
+ public static void Apply(float cameraDistance)
+ {
+ var asset = UniversalRenderPipeline.asset;
+ if (asset == null) return;
+ if (touched != asset) { Restore(); touched = asset; original = asset.shadowDistance; } // a quality-level switch
+ asset.shadowDistance = Distance(cameraDistance);
+ }
+
+ public static void Restore()
+ {
+ if (touched != null) touched.shadowDistance = original;
+ touched = null;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/ShadowFit.cs.meta b/unity/Assets/Scripts/Map/ShadowFit.cs.meta
new file mode 100644
index 000000000..8c6cde147
--- /dev/null
+++ b/unity/Assets/Scripts/Map/ShadowFit.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 2b2a7c576495c4a2da48176fe5fc527d
\ No newline at end of file
diff --git a/unity/Assets/Settings/Mobile_RPAsset.asset b/unity/Assets/Settings/Mobile_RPAsset.asset
index fedee0759..b25386f21 100644
--- a/unity/Assets/Settings/Mobile_RPAsset.asset
+++ b/unity/Assets/Settings/Mobile_RPAsset.asset
@@ -43,7 +43,7 @@ MonoBehaviour:
m_ProbeVolumeSHBands: 1
m_MainLightRenderingMode: 1
m_MainLightShadowsSupported: 1
- m_MainLightShadowmapResolution: 1024
+ m_MainLightShadowmapResolution: 2048
m_AdditionalLightsRenderingMode: 1
m_AdditionalLightsPerObjectLimit: 4
m_AdditionalLightShadowsSupported: 0
diff --git a/unity/Assets/Tests/EditMode/LightingTests.cs b/unity/Assets/Tests/EditMode/LightingTests.cs
new file mode 100644
index 000000000..7f51fa858
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/LightingTests.cs
@@ -0,0 +1,138 @@
+#nullable enable
+using System.Collections;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+using UnityEditor;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.Rendering;
+using UnityEngine.Rendering.Universal;
+using UnityEngine.TestTools;
+
+/// <summary>Plan Task 2: the sun, the ambient fill, shadows at map scale and the hero zoom.</summary>
+public class LightingTests
+{
+ [TearDown]
+ public void Restore()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); // destroys any map: its teardown restores
+ ShadowFit.Restore();
+ VisualToggles.Clear();
+ }
+
+ [Test]
+ public void TheSunIsLowWarmAndFromTheWestNorthWest()
+ {
+ var go = new GameObject("Sun"); var sun = go.AddComponent<Light>(); sun.type = LightType.Directional;
+ try
+ {
+ MapLighting.Apply(sun);
+ var travel = sun.transform.forward;
+ Assert.AreEqual(-Mathf.Sin(MapLighting.SunElevation * Mathf.Deg2Rad), travel.y, 1e-4f, "elevation");
+ Assert.That(MapLighting.SunElevation, Is.InRange(25f, 35f), "late afternoon: long shadows");
+ Assert.Greater(travel.x, 0f, "the light travels east: the sun is in the west");
+ Assert.Less(travel.z, 0f, "and a little south: the sun is north of west");
+ Assert.Greater(sun.color.r, sun.color.b + 0.2f, "warm");
+ Assert.AreEqual(LightShadows.Soft, sun.shadows);
+ Assert.AreSame(sun, RenderSettings.sun);
+ }
+ finally { Object.DestroyImmediate(go); }
+ }
+
+ [Test]
+ public void TheAmbientFillIsCoolFromTheSkyAndDarkFromTheGround()
+ {
+ MapLighting.Apply(null);
+ var c = new Color[2];
+ RenderSettings.ambientProbe.Evaluate(new[] { Vector3.up, Vector3.down }, c);
+ Assert.Greater(c[0].b, c[0].r, "sky fill is cool");
+ Assert.Greater(c[0].grayscale, c[1].grayscale + 0.05f, "brighter from above");
+ Assert.AreEqual(AmbientMode.Trilight, RenderSettings.ambientMode);
+ }
+
+ [TestCase(6000f)]
+ [TestCase(45000f)]
+ [TestCase(120000f)]
+ [TestCase(250000f)]
+ public void TheShadowDistanceCoversTheWholeView(float distance)
+ {
+ var go = new GameObject("Cam"); var cam = go.AddComponent<Camera>(); var rig = go.AddComponent<CameraRig>();
+ try
+ {
+ cam.fieldOfView = CameraRig.Fov;
+ foreach (var aspect in new[] { 16f / 9f, 21f / 9f })
+ {
+ cam.aspect = aspect;
+ rig.LookAt = Vector3.zero; rig.Distance = distance; rig.TopInset = CameraRig.MaxTopInset; rig.Apply();
+ foreach (var v in new[] { new Vector2(0f, 1f), new Vector2(0.5f, 1f), new Vector2(1f, 1f) })
+ {
+ var ray = cam.ViewportPointToRay(new Vector3(v.x, v.y, 0));
+ var hit = ray.origin + ray.direction * (-ray.origin.y / ray.direction.y);
+ var depth = Vector3.Dot(hit - cam.transform.position, cam.transform.forward);
+ Assert.LessOrEqual(depth, ShadowFit.Distance(distance), $"{distance} m, aspect {aspect:0.00}, viewport {v}");
+ }
+ }
+ }
+ finally { Object.DestroyImmediate(go); }
+ }
+
+ [Test]
+ public void FittingFollowsTheCameraAndRestoringPutsTheAssetBack()
+ {
+ var asset = UniversalRenderPipeline.asset; Assert.IsNotNull(asset);
+ var before = asset!.shadowDistance;
+ ShadowFit.Apply(60000f); Assert.AreEqual(ShadowFit.Distance(60000f), asset.shadowDistance, 1e-3f);
+ ShadowFit.Apply(10000f); Assert.AreEqual(ShadowFit.Distance(10000f), asset.shadowDistance, 1e-3f);
+ Assert.AreEqual(ShadowFit.MinDistanceM, ShadowFit.Distance(100f));
+ ShadowFit.Restore(); Assert.AreEqual(before, asset.shadowDistance);
+ ShadowFit.Restore(); Assert.AreEqual(before, asset.shadowDistance, "restoring twice is harmless");
+ }
+
+ [Test]
+ public void DestroyingTheMapRestoresTheShadowDistance()
+ {
+ var asset = UniversalRenderPipeline.asset!; var before = asset.shadowDistance;
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ Object.FindFirstObjectByType<MapScene>().Build();
+ Assert.AreNotEqual(before, asset.shadowDistance, "fitted to the camera by Build");
+ CollectionAssert.Contains(VisualToggles.Names, "shadows");
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ Assert.AreEqual(before, asset.shadowDistance, "restored with the map");
+ }
+
+ [Test]
+ public void TheHeroZoomComesInToSixKilometres()
+ {
+ Assert.AreEqual(6000f, CameraController.MinDistance);
+ Assert.AreEqual(250000f, CameraController.MaxDistance);
+ }
+
+ [Test]
+ public void TheWebTierShadowMapIs2048()
+ {
+ var web = AssetDatabase.LoadAssetAtPath<UniversalRenderPipelineAsset>("Assets/Settings/Mobile_RPAsset.asset");
+ Assert.AreEqual(2048, web.mainLightShadowmapResolution);
+ }
+
+ /// <summary>Rendered: over the Dead Sea escarpment (the steepest relief on the map) the sun now casts shadows. Without
+ /// the fit (the asset's 50 m) nothing would. Much of the escarpment's shadow at 30 degrees falls east onto the Dead Sea;
+ /// in Track A alone that water is URP-lit terrain and darkens; after the merge the water is ScWaterShade, which samples
+ /// the main light's shadow attenuation (Task 7, review I6), so the shadow still lands on it and the 2% floor holds.</summary>
+ [UnityTest]
+ public IEnumerator ReliefCastsShadowsAtMapScale()
+ {
+ 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 sun = MapLighting.FindSun();
+ Assert.IsNotNull(sun, "Map.unity has a directional light");
+ rig.LookAt = map.Frame.ToWorld(35.38, 31.45, 0); rig.Distance = 60000f; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();
+ var lit = RenderSample.Render(cam, 480, 270);
+ VisualToggles.Set("shadows", false);
+ var flat = RenderSample.Render(cam, 480, 270);
+ VisualToggles.Set("shadows", true);
+ float shadowed = RenderSample.FractionDarker(lit, flat, 0.04f);
+ TestContext.WriteLine($"shadowed share {shadowed:P1}");
+ Assert.Greater(shadowed, 0.02f, "at least 2% of the view is in a cast shadow");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/LightingTests.cs.meta b/unity/Assets/Tests/EditMode/LightingTests.cs.meta
new file mode 100644
index 000000000..05fe9d29a
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/LightingTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 87b12aa6621bf42e19bee3c8aa9669cb
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/VisualHarnessTests.cs b/unity/Assets/Tests/EditMode/VisualHarnessTests.cs
index 1882285fa..d4566e13e 100644
--- a/unity/Assets/Tests/EditMode/VisualHarnessTests.cs
+++ b/unity/Assets/Tests/EditMode/VisualHarnessTests.cs
@@ -170,21 +170,24 @@ public class VisualHarnessTests
}
/// <summary>Review M8: undo actions an earlier Init left behind (Init called outside MapScene.Build) run on the next
- /// Init instead of piling up.</summary>
+ /// Init instead of piling up. (From Task 2 on, Init registers its own undo actions: the shadow fit and the toggle.)</summary>
[Test]
public void InitRunsAndClearsUndoActionsLeftByAnEarlierInit()
{
var go = new GameObject("cam", typeof(Camera)); var rig = go.AddComponent<CameraRig>();
int ran = 0;
- rig.TeardownActions.Add(() => ran++);
+ System.Action stale = () => ran++;
+ rig.TeardownActions.Add(stale);
try
{
rig.Init();
Assert.AreEqual(1, ran);
- CollectionAssert.IsEmpty(rig.TeardownActions);
+ CollectionAssert.DoesNotContain(rig.TeardownActions, stale);
}
finally
{
+ for (int i = rig.TeardownActions.Count - 1; i >= 0; i--) rig.TeardownActions[i](); // the shadow fit, the toggle
+ rig.TeardownActions.Clear();
if (rig.Volume != null) { Object.DestroyImmediate(rig.Volume.profile); Object.DestroyImmediate(rig.Volume.gameObject); }
Object.DestroyImmediate(go);
}