fix(models): tracked and emergency tints mix into aircraft paint instead of multiplying it

Aircraft models multiplied their tint into the shaded paint (HIGHLIGHT).
A saturated tint zeroes every channel it lacks: the tracked cyan (no red)
drew a red helicopter solid black, day or night, and a white Cessna one
flat cyan. Tinted models now mix the colour in at 30%
(AIRCRAFT_MODEL_TINT_MIX), so the paint stays readable and the colour
still marks them; untinted models still draw their own colours, and the
IR boost stays flat white.

Neither the multi-part models nor the part shader were involved: old and
new GLBs, with and without the shader, render the same pixels, and an
untinted model at night is lit by the default ambient term.

The new conformance check draw.models.paint draws a model painted with
COLOR_0 under a fixed sun and reads its colour by day, at night, and
under a tint mixed in. The parts test model can now carry vertex paint.
This commit is contained in:
Sameh Khamis committed 2026-11-17 16:50:52 -08:00
1 parent 953af60e1d
commit e83c1672dd
9 files changed
+221 -12

No files matched your search

+1 -1
View File
@@ -405,7 +405,7 @@ export function createAircraftModels({
tint: record.tint ?? WHITE,
// The mesh's own colours, tinted while tracked or in an emergency;
// the IR boost draws it flat white.
colorBlend: aircraftModelBlend(state._irBoost === true),
colorBlend: aircraftModelBlend(state._irBoost === true, record.tint),
environmentMap: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS.enabled,
...(record.parts ? { parts: record.parts } : {}),
show: record.show,
+21 -6
View File
@@ -17,15 +17,30 @@ export const AIRCRAFT_ENVIRONMENT_MAP_OPTIONS = Object.freeze({
const HIGHLIGHT = Object.freeze({ mode: 'highlight' });
const FLAT = Object.freeze({ mode: 'mix', amount: 1 });
/**
* How much of a tracked or emergency colour a model takes over its paint.
* Multiplying by a saturated tint zeroes every channel the tint lacks: the
* tracked cyan (no red) draws a red helicopter black and a white Cessna flat
* cyan. Mixed in at this share, the paint stays readable and the colour still
* marks the model.
*/
export const AIRCRAFT_MODEL_TINT_MIX = 0.3;
const TINTED = Object.freeze({ mode: 'mix', amount: AIRCRAFT_MODEL_TINT_MIX });
/**
* How an aircraft model's colour meets its mesh, as a draw item's
* `colorBlend`. `highlight` multiplies, so white draws the mesh's own
* colours as built, and the tracked or emergency colour tints the mesh
* without hiding its paint. The IR boost draws the model flat white instead
* (`mix` at 1, unlit).
* `colorBlend`. White (no tint) multiplies (`highlight`), which draws the
* mesh's own colours as built. A tracked or emergency colour is mixed in at
* `AIRCRAFT_MODEL_TINT_MIX`, so it tints the mesh without hiding its paint.
* The IR boost draws the model flat white instead (`mix` at 1, unlit).
* @param {boolean} irBoost
* @param {ArrayLike<number>|null} [tint] The model's RGBA tint, 0..1; white
* or none draws the mesh's own colours.
* @returns {{mode: 'highlight'|'mix', amount?: number}}
*/
export function aircraftModelBlend(irBoost) {
return irBoost ? FLAT : HIGHLIGHT;
export function aircraftModelBlend(irBoost, tint = null) {
if (irBoost) return FLAT;
const white = !tint || (tint[0] >= 1 && tint[1] >= 1 && tint[2] >= 1);
return white ? HIGHLIGHT : TINTED;
}
+66 -1
View File
@@ -2,7 +2,12 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { readLayerSource } from '../testSupport/readLayerSource.mjs';
import { AIRCRAFT_ENVIRONMENT_MAP_OPTIONS } from './aircraftModelLighting.js';
import {
AIRCRAFT_ENVIRONMENT_MAP_OPTIONS,
aircraftModelBlend,
} from './aircraftModelLighting.js';
import * as flightsPolicy from '../layers/flights/policy.js';
import * as militaryPolicy from '../layers/military/policy.js';
/**
* Every aircraft model drawn in the scene skips the renderer's dynamic
@@ -48,3 +53,63 @@ test('localAdsb: its draw-port models skip the dynamic environment map', () => {
/\benvironmentMap:\s*AIRCRAFT_ENVIRONMENT_MAP_OPTIONS\.enabled\b/,
);
});
/**
* The colour a model draws in, as the renderer blends its tint over the
* shaded paint (`ModelItem.colorBlend`, Cesium's model colour stage): `mix`
* moves the paint toward the tint by `amount`; `highlight` multiplies.
*/
function blended(paint, tint, blend) {
if (blend.mode === 'mix')
return paint.map((c, i) => c + (tint[i] - c) * blend.amount);
if (blend.mode === 'highlight') return paint.map((c, i) => c * tint[i]);
return tint.slice(0, 3);
}
/** Paints the fleet models carry: a red helicopter, a white airliner, a dark blue tail. */
const PAINTS = {
red: [0.8, 0.05, 0.05],
white: [0.9, 0.9, 0.9],
blue: [0.05, 0.1, 0.5],
};
test('an untinted model draws its mesh in its own colours', () => {
for (const tint of [null, [1, 1, 1, 1], flightsPolicy.MODEL_WHITE]) {
const blend = aircraftModelBlend(false, tint);
for (const paint of Object.values(PAINTS))
assert.deepEqual(blended(paint, [1, 1, 1], blend), paint);
}
});
test('the tracked and emergency tints keep every paint, never black or one flat colour', () => {
const tints = {
'tracked cyan': flightsPolicy.TRACKED_CYAN,
emergency: flightsPolicy.EMERGENCY_TINT,
'military tracked': militaryPolicy.TRACKED_ICON_COLOR,
'military emergency': militaryPolicy.EMERGENCY_ICON_COLOR,
};
for (const [tintName, tint] of Object.entries(tints)) {
const blend = aircraftModelBlend(false, tint);
const drawn = {};
for (const [paintName, paint] of Object.entries(PAINTS)) {
const out = blended(paint, tint, blend);
drawn[paintName] = out;
// Multiplying by the tracked cyan (no red) drew a red helicopter black.
paint.forEach((c, i) =>
assert.ok(
out[i] >= c * 0.6,
`${tintName} over ${paintName}: channel ${i} ${out[i].toFixed(2)} keeps most of ${c}`,
),
);
}
// Paints that differ still differ: the tint is not one flat colour.
const spread = (a, b) => Math.max(...a.map((c, i) => Math.abs(c - b[i])));
assert.ok(spread(drawn.red, drawn.white) > 0.4, `${tintName}: red and white apart`);
assert.ok(spread(drawn.blue, drawn.white) > 0.4, `${tintName}: blue and white apart`);
}
});
test('the IR boost draws every model flat white whatever its tint', () => {
for (const tint of [null, flightsPolicy.TRACKED_CYAN])
assert.deepEqual(aircraftModelBlend(true, tint), { mode: 'mix', amount: 1 });
});