Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

fix(build): strip three URP utility shaders WebGL 2 cannot run (playtest 1, item 12)

eyalgolanebff99e5c5e6
diff --git a/docs/m3-release.md b/docs/m3-release.md
index ea6b20733..a3f91496b 100644
--- a/docs/m3-release.md
+++ b/docs/m3-release.md
@@ -39,7 +39,7 @@ These were run with a small Chrome DevTools Protocol driver: `uv run --with webs
### Rendering
- The terrain, hex overlay, settlement markers and labels, all UI Toolkit panels and the minimap render. Nothing is magenta.
- WebGL reports `ANGLE (Apple, ANGLE Metal Renderer: Apple M5 Pro)`.
-- Three hidden URP utility shaders report "not supported on this GPU": `Hidden/CoreSRP/CoreCopy`, `Hidden/Universal Render Pipeline/StencilDitherMaskSeed` and `Hidden/Universal/HDRDebugView`. They report the same in headless Chrome. They serve features this build does not use (HDR debug view, LOD cross-fade dither, a render-graph copy path), and the frame renders correctly without them.
+- Three hidden URP utility shaders (`Hidden/CoreSRP/CoreCopy`, `Hidden/Universal Render Pipeline/StencilDitherMaskSeed`, `Hidden/Universal/HDRDebugView`) need shader target 4.5, which WebGL 2 (ES 3.0) lacks, so the browser reported them "not supported on this GPU". URP loads them up front (Blitter, UniversalRenderer, DebugHandler), but this build never draws with them: the render-graph copy needs framebuffer-fetch emulation, which Core RP disables on WebGL; stencil LOD cross-fade is off (Blue Noise, no LOD groups); the HDR debug view belongs to the Rendering Debugger. `Assets/Editor/WebShaderStripping.cs` strips them from WebGL builds only (playtest 1, item 12). The console no longer shows the three errors, and the goldens and the 5-turn smoke give the same hashes as before.
- The only 404 is `/favicon.ico`.
### Wheel zoom
@@ -105,6 +105,5 @@ Result: (owner fills in)
- No Diplomacy screen or legacy report (M4).
- English only.
- The headless smoke plays five turns; a full-slice smoke is M4.
-- Three hidden URP utility shaders are unsupported on WebGL 2 (see above).
- The wheel-zoom step (one notch = 10%) was measured in Chrome on macOS only. Firefox reports wheel deltas in lines and
Windows at 125% scaling reports 125 px per notch, so re-check the step in the owner's itch.io check.
diff --git a/unity/Assets/Editor/WebShaderStripping.cs b/unity/Assets/Editor/WebShaderStripping.cs
new file mode 100644
index 000000000..466411a6e
--- /dev/null
+++ b/unity/Assets/Editor/WebShaderStripping.cs
@@ -0,0 +1,43 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEditor.Build;
+using UnityEditor.Rendering;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+namespace Statecraft.Game.EditorTools
+{
+ /// <summary>Strips, from WebGL builds only, three hidden URP utility shaders that need shader target 4.5 (WebGL 2 is
+ /// ES 3.0) and that this build never draws with. Without them the browser console no longer reports them as "not
+ /// supported on this GPU" (playtest 1, item 12). Why each is unused on WebGL (URP 17.3 / Core RP 17.3 sources):
+ /// - Hidden/CoreSRP/CoreCopy: Blitter.Initialize creates its material unconditionally, but the render-graph copy
+ /// pass that draws with it needs framebuffer-fetch emulation, which RenderGraphUtils reports unsupported on WebGL
+ /// (IsFramebufferFetchEmulationSupportedOnCurrentPlatform), so URP blits instead.
+ /// - Hidden/Universal Render Pipeline/StencilDitherMaskSeed: UniversalRenderer always creates the
+ /// StencilCrossFadeRenderPass's materials, but the pass only runs for LOD cross-fade dithering type Stencil; the
+ /// URP assets use Blue Noise, and the map has no LOD groups.
+ /// - Hidden/Universal/HDRDebugView: the Rendering Debugger's HDR view (DebugHandler); release builds have no
+ /// Rendering Debugger and the project's HDR output is off.</summary>
+ public sealed class WebShaderStripping : IPreprocessShaders
+ {
+ public static readonly string[] Unused =
+ {
+ "Hidden/CoreSRP/CoreCopy",
+ "Hidden/Universal Render Pipeline/StencilDitherMaskSeed",
+ "Hidden/Universal/HDRDebugView",
+ };
+
+ public int callbackOrder => 0;
+
+ /// <summary>True when every variant of <paramref name="shaderName"/> is dropped for <paramref name="target"/>.</summary>
+ public static bool Strips(BuildTarget target, string shaderName) =>
+ target == BuildTarget.WebGL && Array.IndexOf(Unused, shaderName) >= 0;
+
+ public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
+ {
+ if (Strips(EditorUserBuildSettings.activeBuildTarget, shader.name)) data.Clear();
+ }
+ }
+}
diff --git a/unity/Assets/Editor/WebShaderStripping.cs.meta b/unity/Assets/Editor/WebShaderStripping.cs.meta
new file mode 100644
index 000000000..6dfa549d6
--- /dev/null
+++ b/unity/Assets/Editor/WebShaderStripping.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: ccace2da26943465caa5add2a488fa7a
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs b/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs
new file mode 100644
index 000000000..3be745307
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs
@@ -0,0 +1,45 @@
+#nullable enable
+using NUnit.Framework;
+using System;
+using System.Reflection;
+using UnityEditor.Build;
+using UnityEditor;
+using UnityEngine;
+
+/// <summary>Playtest 1, item 12: the three hidden URP utility shaders that WebGL 2 cannot run, and that this build never
+/// draws with, are stripped from WebGL builds only; every other shader and every other platform is left alone.</summary>
+public class WebShaderStrippingTests
+{
+ // Editor code lives in Assembly-CSharp-Editor, which a test assembly cannot reference (as in PortraitImportTests).
+ static Type Stripper
+ {
+ get
+ {
+ var t = Type.GetType("Statecraft.Game.EditorTools.WebShaderStripping, Assembly-CSharp-Editor");
+ Assert.IsNotNull(t, "WebShaderStripping exists");
+ return t!;
+ }
+ }
+
+ static bool Strips(BuildTarget target, string name) =>
+ (bool)Stripper.GetMethod("Strips", BindingFlags.Public | BindingFlags.Static)!.Invoke(null, new object[] { target, name })!;
+
+ [Test]
+ public void ItIsAShaderPreprocessor() => Assert.IsTrue(typeof(IPreprocessShaders).IsAssignableFrom(Stripper));
+
+ [TestCase("Hidden/CoreSRP/CoreCopy")]
+ [TestCase("Hidden/Universal Render Pipeline/StencilDitherMaskSeed")]
+ [TestCase("Hidden/Universal/HDRDebugView")]
+ public void TheUnsupportedUtilityShadersAreStrippedForWebGLOnly(string name)
+ {
+ Assert.IsNotNull(Shader.Find(name), name + " exists (URP renamed it?)");
+ Assert.IsTrue(Strips(BuildTarget.WebGL, name));
+ Assert.IsFalse(Strips(BuildTarget.StandaloneOSX, name));
+ }
+
+ [TestCase("Hidden/Universal Render Pipeline/Blit")]
+ [TestCase("Hidden/Universal/CoreBlit")]
+ [TestCase("Universal Render Pipeline/Unlit")]
+ [TestCase("Universal Render Pipeline/Terrain/Lit")]
+ public void EveryOtherShaderIsKept(string name) => Assert.IsFalse(Strips(BuildTarget.WebGL, name));
+}
diff --git a/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs.meta b/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs.meta
new file mode 100644
index 000000000..676d140f1
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 5e1eda6fcbc7746ed838c10dfc5d2589
\ No newline at end of file