Classic icons: darken player color for icon glyph instead of black (#4246)

## Summary

The "classic icons" graphics setting currently renders structure icon
glyphs as flat black. In the v0.31 canvas renderer, classic icons used
`structureColors().dark` — a darkened version of the owning player's
territory color. This PR restores that look in the WebGL renderer.

- New `structure.iconDarken` render setting (HSV value multiplier on the
player fill color; `0` = off, default).
- New `uIconDarken` uniform in `structure.frag.glsl`: when > 0, the
glyph color is `darken(playerFill, uIconDarken)` instead of the flat
`uIconColor`.
- Classic mode (`classicIcons: true`) now sets `iconDarken = 0.45`
instead of `iconR/G/B = 0`. Border darken, fill, and the 0.75
translucency are unchanged.
- Default (non-classic) icons are unaffected (white glyph, `iconDarken =
0`).

Under-construction structures keep the gray fill, so their glyph darkens
to a darker gray — matching v31's construction styling.

## Verification

Drove a solo game headlessly with classic icons on and built structures:
glyphs render as darkened versions of each player's color (dark purple
on a purple player, per-bot hues on bot structures). Pixel-sampled the
screenshot: glyph measured `rgb(89,58,142)` vs `rgb(84,50,139)`
predicted for the 0.45-darkened player color at 0.75 alpha (flat black
would measure `rgb(38,26,60)`). Control run with classic off shows the
unchanged white glyph. `tests/GraphicsOverrides.test.ts` updated; all
pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Evan
2026-06-12 14:46:20 -07:00
committed by GitHub
parent 769d0c687f
commit 5648a37317
6 changed files with 25 additions and 17 deletions
+5 -6
View File
@@ -28,14 +28,13 @@ export function applyGraphicsOverrides(
settings.name.hoverGlowAlpha = overrides.name.hoverGlowAlpha;
}
if (overrides.structure?.classicIcons === true) {
// Classic look: lighter player-colored shape behind a dark icon glyph,
// with a touch of translucency.
// Classic look: lighter player-colored shape behind a darkened
// player-colored icon glyph (matching the old canvas renderer's
// structureColors().dark), with a touch of translucency.
settings.structure.borderDarken = 0.7;
settings.structure.fillDarken = 1.0;
settings.structure.iconR = 0;
settings.structure.iconG = 0;
settings.structure.iconB = 0;
settings.structure.iconAlpha = 0.75;
settings.structure.iconDarken = 0.3;
settings.structure.iconAlpha = 0.9;
}
if (overrides.mapOverlay?.highlightFillBrighten !== undefined) {
settings.mapOverlay.highlightFillBrighten =
+5
View File
@@ -182,6 +182,11 @@ export interface RenderSettings {
iconR: number;
iconG: number;
iconB: number;
/**
* When > 0, the icon glyph is a darkened version of the player color
* (HSV value multiplier) instead of the flat iconR/G/B color. 0 = off.
*/
iconDarken: number;
};
structureLevel: {
scale: number;
@@ -89,6 +89,7 @@ export class StructurePass {
private uBorderDarken: WebGLUniformLocation;
private uIconAlpha: WebGLUniformLocation;
private uIconColor: WebGLUniformLocation;
private uIconDarken: WebGLUniformLocation;
private vao: WebGLVertexArrayObject;
private instanceBuf: DynamicInstanceBuffer;
@@ -174,6 +175,7 @@ export class StructurePass {
this.uBorderDarken = gl.getUniformLocation(this.program, "uBorderDarken")!;
this.uIconAlpha = gl.getUniformLocation(this.program, "uIconAlpha")!;
this.uIconColor = gl.getUniformLocation(this.program, "uIconColor")!;
this.uIconDarken = gl.getUniformLocation(this.program, "uIconDarken")!;
// Texture unit bindings + ghost defaults
gl.useProgram(this.program);
@@ -370,6 +372,7 @@ export class StructurePass {
gl.uniform1f(this.uBorderDarken, ss.borderDarken);
gl.uniform1f(this.uIconAlpha, ss.iconAlpha);
gl.uniform3f(this.uIconColor, ss.iconR, ss.iconG, ss.iconB);
gl.uniform1f(this.uIconDarken, ss.iconDarken);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, this.paletteTex);
+2 -1
View File
@@ -149,7 +149,8 @@
"iconAlpha": 1.0,
"iconR": 1.0,
"iconG": 1.0,
"iconB": 1.0
"iconB": 1.0,
"iconDarken": 0
},
"structureLevel": {
"scale": 1.2,
@@ -15,6 +15,7 @@ uniform float uFillDarken; // HSV value multiplier on icon fill
uniform float uBorderDarken; // HSV value multiplier on icon border
uniform float uIconAlpha; // global multiplier on final icon alpha
uniform vec3 uIconColor; // color of the inner icon glyph (was white)
uniform float uIconDarken; // >0: glyph = darkened player color instead of uIconColor
in vec2 vLocalPos;
in vec2 vAtlasUV;
@@ -132,7 +133,8 @@ void main() {
}
// Composite: tinted icon over player-colored shape
vec3 finalRGB = mix(bgColor.rgb, uIconColor, iconAlpha);
vec3 glyphColor = uIconDarken > 0.0 ? darken(fillColor.rgb, uIconDarken) : uIconColor;
vec3 finalRGB = mix(bgColor.rgb, glyphColor, iconAlpha);
// Red X overlay for units marked for deletion
if (vMarkedForDeletion > 0.5) {
+7 -9
View File
@@ -211,19 +211,17 @@ describe("applyGraphicsOverrides", () => {
expect(s.structure).toEqual(defaults.structure);
});
test("classicIcons=true → light shape + dark icon + 0.75 alpha", () => {
test("classicIcons=true → light shape + dark icon + 0.9 alpha", () => {
const s = gen({
structure: { classicIcons: true },
}).structure;
// Shape (circle behind) is mostly player color, lightly darkened.
expect(s.fillDarken).toBe(1.0);
expect(s.borderDarken).toBe(0.7);
// Icon glyph itself is black.
expect(s.iconR).toBe(0);
expect(s.iconG).toBe(0);
expect(s.iconB).toBe(0);
// Icon glyph is a darkened version of the player color.
expect(s.iconDarken).toBe(0.3);
// Slightly translucent in classic mode.
expect(s.iconAlpha).toBe(0.75);
expect(s.iconAlpha).toBe(0.9);
});
test("classicIcons=false or absent → keeps render-settings.json defaults (fully opaque)", () => {
@@ -233,12 +231,12 @@ describe("applyGraphicsOverrides", () => {
}).structure;
expect(off.borderDarken).toBe(defaults.borderDarken);
expect(off.fillDarken).toBe(defaults.fillDarken);
expect(off.iconR).toBe(defaults.iconR);
expect(off.iconDarken).toBe(0);
expect(off.iconAlpha).toBe(1);
const absent = gen({ structure: {} }).structure;
expect(absent.borderDarken).toBe(defaults.borderDarken);
expect(absent.fillDarken).toBe(defaults.fillDarken);
expect(absent.iconR).toBe(defaults.iconR);
expect(absent.iconDarken).toBe(0);
expect(absent.iconAlpha).toBe(1);
});
@@ -303,6 +301,6 @@ describe("applyGraphicsOverrides", () => {
expect(s.name.nameScaleFactor).toBe(0.9);
expect(s.structure.borderDarken).toBe(0.7);
expect(s.structure.fillDarken).toBe(1.0);
expect(s.structure.iconAlpha).toBe(0.75);
expect(s.structure.iconAlpha).toBe(0.9);
});
});