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: kit faces in shadow keep their own colour, not blue-grey (refs #32) (#640)

Beri988279c37e55
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e2b054492..afd00fbba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -527,6 +527,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
message to the player: the note always gives the short reason "the file could not be read or replayed", in English and
Hebrew, and the full exception goes to the log. A replay that throws keeps that exception, with its stack, as the
SaveException's inner exception. No save format change.
+- Kit faces in shadow keep their own colour (refs #32): `Kit.shader`'s ambient takes the sun's warmth where the sun does
+ not reach (a bounce term, 0.6 of it in full shade, at the trilight's own brightness), so a shaded wall, roof flank or
+ tree crown reads as a darker version of itself and not blue-grey under the grade's teal shadows (Safed at 6 km, shaded
+ wall hue 100 to 44 degrees, saturation 0.09 to 0.27, same value). Terrain, water and every other shader are unchanged;
+ sunlit kit faces get a little warmer. `KitTests.AKitFaceInShadowKeepsItsOwnHue` pins it. No golden moves.
- UI text from Jeremy Hoover's review (refs #622): a refused order no longer shows a content id or an exception's
message after "Not done:" ("Unknown policy", "The turn could not run", in English and Hebrew); both stay in the log.
The six Title Case labels are in sentence case ("Public support", "International standing", "Foreign currency", "End
diff --git a/unity/Assets/Shaders/Kit.shader b/unity/Assets/Shaders/Kit.shader
index 1c6ae7fd7..15d621933 100644
--- a/unity/Assets/Shaders/Kit.shader
+++ b/unity/Assets/Shaders/Kit.shader
@@ -1,7 +1,8 @@
// Settlement kits and trees (art spike, issues #31 #32 #34 #37). Vertex colour is the sRGB albedo; its alpha picks a
// facade's window pattern (KitMesh.Facade), drawn from uv0 = the wall's (along, up) position in real metres, so storeys and
// windows keep real proportions on symbolic-size buildings, box-filtered so they fade to their mean instead of shimmering
-// when a storey is a pixel or two. Lit like the terrain (the sun with its shadows, the trilight ambient through SH) and
+// when a storey is a pixel or two. Lit like the terrain (the sun with its shadows, the trilight ambient through SH; in shade
+// the ambient also takes a sun-warm bounce, KitBounce, so a face keeps its own colour) and
// hazed with the terrain's own ScHazeAmount, so kits sit in the same air as the ground. GPU instancing for the trees, with a
// per-instance tint hashed from the instance's origin (no per-instance buffer: WebGL 2 has instanced arrays only).
// Shadows use the sun's own URP bias, unchanged (ApplyShadowBias): KitTests.AKitShadowStartsAtItsWalls finds no gap at
@@ -63,6 +64,9 @@ Shader "Statecraft/Kit"
return o;
}
+ // How much of the ambient in full shade is the sun's bounce (kit shadow colour, refs #32).
+ static const half KitBounce = 0.6;
+
// A 1D band [a, b] of a period-1 pattern, box-filtered over the pixel's footprint w (in periods).
float Band(float x, float a, float b, float w)
{
@@ -118,7 +122,13 @@ Shader "Statecraft/Kit"
}
Light sun = GetMainLight(TransformWorldToShadowCoord(i.positionWS));
float ndl = saturate(dot(n, sun.direction));
- half3 lit = albedo * (SampleSH(n) + sun.color * ndl * sun.shadowAttenuation);
+ // The ambient takes the sun's warmth where the sun does not reach (the bounce off the sunlit ground; same
+ // brightness, the trilight's luminance): with the trilight's own colour, near grey at a wall and sky blue on
+ // a roof, a pale face in shade had almost no colour left, and the grade's teal shadows turned it blue-grey.
+ float sunlit = ndl * sun.shadowAttenuation;
+ half3 sh = SampleSH(n);
+ half3 bounce = Luminance(sh) * sun.color / max(Luminance(sun.color), 1e-4);
+ half3 lit = albedo * (lerp(sh, bounce, KitBounce * (1.0 - sunlit)) + sun.color * sunlit);
float h = _ScHaze.a * ScHazeAmount(i.positionWS);
return half4(lerp(lit, _ScHaze.rgb, h), 1.0);
}
diff --git a/unity/Assets/Tests/EditMode/KitTests.cs b/unity/Assets/Tests/EditMode/KitTests.cs
index 45d0ea78b..1775f5ccd 100644
--- a/unity/Assets/Tests/EditMode/KitTests.cs
+++ b/unity/Assets/Tests/EditMode/KitTests.cs
@@ -1100,4 +1100,53 @@ public class KitTests
}
finally { Object.DestroyImmediate(go); Object.DestroyImmediate(mesh); }
}
+
+ /// <summary>A kit face in shadow is a darker version of its own colour, not blue-grey. A pale canvas kit box on the open
+ /// coastal plain at 12 km, web tier, seen from its shaded side: the wall facing away from the sun is lit by the ambient
+ /// alone, the roof by the sun. With the trilight's own colour (near grey at a wall) a pale face in shade kept almost no
+ /// colour, and the grade's teal shadows turned it green-grey: measured before the fix, hue 69 deg against the roof's
+ /// 38, green over red. Graded, as the player sees it (the other switches off): the shaded wall must keep its hue within
+ /// <see cref="ShadeHueDegrees"/> of the sunlit roof's, red its strongest channel, and at least 0.8 of its saturation.</summary>
+ public const float ShadeHueDegrees = 15f;
+
+ [UnityTest]
+ public IEnumerator AKitFaceInShadowKeepsItsOwnHue()
+ {
+ int previous = QualitySettings.GetQualityLevel();
+ QualitySettings.SetQualityLevel(0, false);
+ var map = OpenMap();
+ yield return null;
+ foreach (var n in VisualToggles.Names.Where(n => n != "shadows" && n != "grade")) VisualToggles.Set(n, false);
+ var g = Ground(map);
+ var at = map.Frame.ToWorld(34.70, 31.70, 0);
+ var sun = MapLighting.FindSun()!; var fall = sun.transform.forward; fall.y = 0f; fall.Normalize();
+ const float w = 300f;
+ float toWall = 0.5f * w / Mathf.Max(Mathf.Abs(fall.x), Mathf.Abs(fall.z));
+ var canvas = new Color32(229, 221, 198, 255); // a pale warm albedo: canvas, lime wash, the camps' tents
+ var km = new KitMesh();
+ float y = g.Y(at.x, at.z);
+ km.Box(at.x, at.z, 0f, w, w, y - 30f, y, w, canvas, canvas, Facade.Plain, 25f);
+ var mesh = km.ToMesh("ShadeProbe");
+ var go = new GameObject("ShadeProbe"); go.AddComponent<MeshFilter>().sharedMesh = mesh;
+ go.AddComponent<MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Kit.mat");
+ try
+ {
+ // Looking towards the sun, so the wall facing away from it (the fall crosses it) faces the camera.
+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
+ rig.LookAt = at; rig.Distance = 12000f; rig.Yaw = Mathf.Atan2(-fall.x, -fall.z) * Mathf.Rad2Deg; rig.TopInset = 0f; rig.Apply();
+ var pts = new[] { at + fall * (toWall * 0.98f) + Vector3.up * (y + 0.5f * w - at.y), new Vector3(at.x, y + w, at.z) };
+ var px = new Vector2[2];
+ var s = RenderSample.Render(cam, 1920, 1080, pts, px);
+ Color shade = s.Mean((int)px[0].x, (int)px[0].y, 2), lit = s.Mean((int)px[1].x, (int)px[1].y, 2);
+ Color.RGBToHSV(shade, out var hs, out var ss, out var vs); Color.RGBToHSV(lit, out var hl, out var sl, out var vl);
+ TestContext.WriteLine($"sunlit roof rgb ({lit.r:0.000}, {lit.g:0.000}, {lit.b:0.000}) hue {hl * 360f:0} deg sat {sl:0.00} val {vl:0.00}; " +
+ $"shaded wall rgb ({shade.r:0.000}, {shade.g:0.000}, {shade.b:0.000}) hue {hs * 360f:0} deg sat {ss:0.00} val {vs:0.00}");
+ Assert.Less(vs, 0.8f * vl, "the wall is in shade");
+ Assert.LessOrEqual(Mathf.Abs(Mathf.DeltaAngle(hs * 360f, hl * 360f)), ShadeHueDegrees, "the shaded face turns another hue");
+ Assert.Greater(shade.r, Mathf.Max(shade.g, shade.b), "the shaded face of a warm albedo goes green- or blue-grey");
+ // The hue alone stops failing once the grade's shadows turn slate (#519); the washed-out colour still shows here.
+ Assert.GreaterOrEqual(ss, 0.8f * sl, "the shaded face keeps its colour");
+ }
+ finally { Object.DestroyImmediate(go); Object.DestroyImmediate(mesh); QualitySettings.SetQualityLevel(previous, false); }
+ }
}