feat(globe): Sharpen on Navara, on at 80 % by default

The contract gains render.setSharpen({ enabled, amount }) and
render.sharpen(). Navara draws it as a custom EffectDesc: Cesium's unsharp
mask (3x3 box blur, gamma 2.2 round trip so one amount matches Cesium)
right after tone mapping and before SMAA/FXAA, skipping sky and cloud
pixels by scene depth. The Cesium engine keeps the state only; Cesium mode
still sharpens with its own post stage, unchanged. The fake engine records
it and the contract suite checks it.

Without a viewer the Sharpen slider and toggle drive the engine with the
same slider-to-amount mapping. On Navara the defaults, presets and share
links read Cesium's 49 % as 80 %.
This commit is contained in:
German Khokhlov committed 2026-10-16 13:30:56 +04:00
1 parent ac081a008d
commit bb8c0b83c4
17 files changed
+521 -16

No files matched your search

+1
View File
@@ -170,6 +170,7 @@ export class StyleManager extends ShellFacade {
this._visualSettings = new VisualSettings({
viewer,
engine,
mapStackController,
services: {
setScopeTerminusOverride: services.setScopeTerminusOverride,
+56
View File
@@ -141,3 +141,59 @@ test('visual teardown restores owned fog and aircraft sensor state once', async
assert.equal(owner._irBoostActive, false);
owner.destroy();
});
test('on Navara, presets set the Sharpen slider to 80 % and the engine draws it', async (t) => {
const { VisualSettings } = await import('./visualSettings.js');
const priorDocument = globalThis.document;
globalThis.document = {
documentElement: { dataset: {} },
getElementById: () => null,
};
t.after(() => {
globalThis.document = priorDocument;
});
const sharpen = [];
const classList = { toggle() {} };
const element = (value) => ({ value, textContent: '', classList });
const elements = {
_bloomBtn: element(),
_bloomSlider: element('0'),
_bloomSliderRow: element(),
_bloomSliderValue: element(),
_sharpenBtn: element(),
_sharpenSlider: element('49'),
_sharpenSliderRow: element(),
_sharpenSliderValue: element(),
};
const owner = new VisualSettings({
viewer: null,
engine: {
kind: 'navara',
render: { setSharpen: (options) => sharpen.push(options) },
},
elements,
operations: {
_syncShareState() {},
_layoutRightPanels() {},
_setHudVariant() {},
_updateHudButtonState() {},
},
services: {
governorRequestRender() {},
holdContinuousRender() {},
releaseContinuousRender() {},
},
readHud: () => ({ getVariant: () => 'tactical', setMode() {} }),
});
owner._detectionUserOverridden = true;
owner._applyStylePresetDefaults('retro');
assert.equal(elements._sharpenSlider.value, '80');
assert.equal(elements._sharpenSliderValue.textContent, '80%');
// _setSharpenEnabled applies the slider again; the engine skips repeats.
assert.deepEqual(sharpen, [
{ amount: 1.7000000000000002 },
{ enabled: true },
{ amount: 1.7000000000000002 },
]);
owner.destroy();
});
+16 -3
View File
@@ -8,16 +8,20 @@ import {
STYLES,
SHARPEN_SHADER,
TRANSITION_DURATION_MS,
sharpenAmount,
} from './visualPresets.js';
/** Own the post-process stages and their animation, without DOM dependencies. */
export class VisualEffects {
/**
* @param {object} options - Viewer, render ownership callbacks and optional clocks.
* Construction is inert; initStyles/initPostProcess retain startup ordering.
* Without a viewer, `engine` (the globe engine) draws the sharpening
* through render.setSharpen. Construction is inert; initStyles and
* initPostProcess retain startup ordering.
*/
constructor({
viewer,
engine = null,
requestRender,
holdRender,
releaseRender,
@@ -28,6 +32,12 @@ export class VisualEffects {
createStage = (options) => new PostProcessStage(options),
}) {
this.viewer = viewer;
// Cesium sharpens with its own post stage below; an engine without a
// viewer (Navara) sharpens in its render pipeline.
this.engineRender =
!viewer && typeof engine?.render?.setSharpen === 'function'
? engine.render
: null;
this.requestRender = requestRender;
this.holdRender = holdRender;
this.releaseRender = releaseRender;
@@ -53,7 +63,8 @@ export class VisualEffects {
}
// Post-process stages are Cesium's: without a viewer (the Navara engine)
// there are none, and the style, bloom and sharpen controls change nothing.
// there are none, and the style and bloom controls change nothing (the
// engine sharpens, see engineRender).
initStyles() {
if (!this.viewer || this.stopped || this.stageEntries.length) return;
for (const [name, shader] of Object.entries(STYLES)) {
@@ -158,7 +169,8 @@ export class VisualEffects {
if (this.stopped) return;
this.sharpenIntensity = value;
if (this.sharpenStage)
this.sharpenStage.uniforms.amount = 0.1 + value * 2.0;
this.sharpenStage.uniforms.amount = sharpenAmount(value);
this.engineRender?.setSharpen({ amount: sharpenAmount(value) });
this.requestRender('sharpen');
}
@@ -166,6 +178,7 @@ export class VisualEffects {
if (this.stopped) return;
this.sharpenEnabled = !!enabled;
if (this.sharpenStage) this.sharpenStage.enabled = this.sharpenEnabled;
this.engineRender?.setSharpen({ enabled: this.sharpenEnabled });
this.requestRender('sharpen');
}
+57 -1
View File
@@ -5,9 +5,13 @@ import {
GLOBAL_POST_DEFAULTS,
STYLE_PRESET_DEFAULTS,
MILITARY_DETECTION_PRESET,
NAVARA_SHARPEN_INTENSITY_DEFAULT,
SHARPEN_INTENSITY_DEFAULT,
sharpenAmount,
sharpenIntensityForEngine,
} from './visualPresets.js';
function fixture() {
function fixture(engine = null) {
let time = 0;
let next = 0;
const frames = new Map();
@@ -37,6 +41,7 @@ function fixture() {
};
const effects = new VisualEffects({
viewer: { scene: { postProcessStages: pipeline } },
engine,
requestRender: (reason) => requests.push(reason),
holdRender: (reason) => holds.add(reason),
releaseRender: (reason) => holds.delete(reason),
@@ -189,6 +194,57 @@ test('sharpen uses the existing uniform scale and keeps values while disabled',
f.effects.destroy();
});
test('without a viewer the engine sharpens with the same amount scale', () => {
const sharpen = [];
const requests = [];
const engine = {
render: { setSharpen: (options) => sharpen.push(options) },
};
const effects = new VisualEffects({
viewer: null,
engine,
requestRender: (reason) => requests.push(reason),
holdRender() {},
releaseRender() {},
});
effects.initStyles();
effects.initPostProcess(0.49);
assert.equal(effects.sharpenStage, null);
effects.applySharpenIntensity(0.8);
effects.setSharpenEnabled(true);
effects.setSharpenEnabled(false);
assert.deepEqual(sharpen, [
{ amount: 1.7000000000000002 },
{ enabled: true },
{ enabled: false },
]);
assert.equal(sharpen[0].amount, sharpenAmount(0.8));
assert.deepEqual(requests, ['sharpen', 'sharpen', 'sharpen']);
effects.destroy();
});
test('with a viewer the Cesium stage sharpens and the engine is left alone', () => {
let calls = 0;
const f = fixture({ render: { setSharpen: () => calls++ } });
f.effects.initPostProcess(0.49);
f.effects.applySharpenIntensity(0.8);
f.effects.setSharpenEnabled(true);
assert.equal(calls, 0);
assert.equal(f.effects.sharpenStage.uniforms.amount, sharpenAmount(0.8));
f.effects.destroy();
});
test('Navara reads the Cesium sharpen default as 80 %, other values stay', () => {
assert.equal(SHARPEN_INTENSITY_DEFAULT, 49);
assert.equal(NAVARA_SHARPEN_INTENSITY_DEFAULT, 80);
assert.equal(sharpenIntensityForEngine(49, 'navara'), 80);
assert.equal(sharpenIntensityForEngine(49, 'cesium'), 49);
assert.equal(sharpenIntensityForEngine(65, 'navara'), 65);
assert.equal(sharpenIntensityForEngine(0, 'navara'), 0);
for (const preset of Object.values(STYLE_PRESET_DEFAULTS))
assert.equal(preset.sharpen.intensity, SHARPEN_INTENSITY_DEFAULT);
});
test('stop revokes pending work immediately but retains stages until final destruction', () => {
const f = fixture();
f.effects.initStyles();
+23 -4
View File
@@ -40,10 +40,29 @@ export const MILITARY_DETECTION_PRESET = Object.freeze({
densityPct: 75,
});
/** The Sharpen slider's default (%) on Cesium, in every preset. */
export const SHARPEN_INTENSITY_DEFAULT = 49;
/** The Sharpen slider's default (%) on the Navara engine. */
export const NAVARA_SHARPEN_INTENSITY_DEFAULT = 80;
/**
* The sharpen intensity (%) a default, a preset or a share link sets on an
* engine: Navara reads Cesium's default (49, every preset's value) as its own
* default (80); any other value, and everything on Cesium, stays as given.
*/
export function sharpenIntensityForEngine(pct, engineKind) {
return engineKind === 'navara' && pct === SHARPEN_INTENSITY_DEFAULT
? NAVARA_SHARPEN_INTENSITY_DEFAULT
: pct;
}
/** The unsharp mask's `amount` for a slider value normalized to 0..1. */
export const sharpenAmount = (value) => 0.1 + value * 2.0;
/** Baseline post-processing settings applied on first load (before share-link restore). */
export const GLOBAL_POST_DEFAULTS = {
bloom: { enabled: false, intensity: BLOOM_INTENSITY_DEFAULT },
sharpen: { enabled: true, intensity: 49 },
sharpen: { enabled: true, intensity: SHARPEN_INTENSITY_DEFAULT },
hudVariant: 'tactical',
hudVisible: true,
// Detection is ON for EVERY style on a first run, Normal included (owner
@@ -69,7 +88,7 @@ export const GLOBAL_POST_DEFAULTS = {
export const STYLE_PRESET_DEFAULTS = {
retro: {
bloom: { enabled: false, intensity: BLOOM_INTENSITY_DEFAULT },
sharpen: { enabled: true, intensity: 49 },
sharpen: { enabled: true, intensity: SHARPEN_INTENSITY_DEFAULT },
styleParams: {
retro: {
pixelation: 1.0,
@@ -83,7 +102,7 @@ export const STYLE_PRESET_DEFAULTS = {
},
surveillance: {
bloom: { enabled: false, intensity: BLOOM_INTENSITY_DEFAULT },
sharpen: { enabled: true, intensity: 49 },
sharpen: { enabled: true, intensity: SHARPEN_INTENSITY_DEFAULT },
styleParams: {
surveillance: {
gain: 0.18,
@@ -98,7 +117,7 @@ export const STYLE_PRESET_DEFAULTS = {
},
thermal: {
bloom: { enabled: false, intensity: BLOOM_INTENSITY_DEFAULT },
sharpen: { enabled: true, intensity: 49 },
sharpen: { enabled: true, intensity: SHARPEN_INTENSITY_DEFAULT },
styleParams: {
thermal: {
sensitivity: 0.85,
+33 -4
View File
@@ -1,4 +1,7 @@
import { STYLE_STATUS_LABELS } from './visualPresets.js';
import {
STYLE_STATUS_LABELS,
sharpenIntensityForEngine,
} from './visualPresets.js';
import { UiLifetime } from './uiLifetime.js';
import {
VisualEffects,
@@ -92,7 +95,15 @@ export class VisualSettings {
this._setBloomIntensity(intensity, { syncShare: false });
}
if (typeof sharpenIntensity === 'number' && this._sharpenSlider) {
const pct = Math.max(0, Math.min(100, Math.round(sharpenIntensity)));
const pct = Math.max(
0,
Math.min(
100,
Math.round(
sharpenIntensityForEngine(sharpenIntensity, this._engineKind),
),
),
);
this._sharpenSlider.value = String(pct);
this._sharpenSliderValue.textContent = `${pct}%`;
this._applySharpenIntensity(pct / 100);
@@ -162,6 +173,7 @@ export class VisualSettings {
constructor({
viewer,
engine = null,
services,
elements,
operations,
@@ -189,8 +201,12 @@ export class VisualSettings {
readDisplayPortalActive,
});
this._lifetime = new UiLifetime();
// Defaults, presets and share links read Cesium's sharpen default as the
// engine's own (sharpenIntensityForEngine).
this._engineKind = engine?.kind ?? 'cesium';
this._visualEffects = new VisualEffects({
viewer,
engine,
requestRender: services.governorRequestRender,
holdRender: services.holdContinuousRender,
releaseRender: services.releaseContinuousRender,
@@ -746,7 +762,12 @@ export class VisualSettings {
if (typeof sharpenInput.intensity === 'number' && this._sharpenSlider) {
const sharpenPct = Math.max(
0,
Math.min(100, Math.round(sharpenInput.intensity)),
Math.min(
100,
Math.round(
sharpenIntensityForEngine(sharpenInput.intensity, this._engineKind),
),
),
);
this._sharpenSlider.value = String(sharpenPct);
this._sharpenSliderValue.textContent = `${sharpenPct}%`;
@@ -804,7 +825,15 @@ export class VisualSettings {
) {
const sharpenPct = Math.max(
0,
Math.min(100, Math.round(defaults.sharpen.intensity)),
Math.min(
100,
Math.round(
sharpenIntensityForEngine(
defaults.sharpen.intensity,
this._engineKind,
),
),
),
);
this._sharpenSlider.value = String(sharpenPct);
this._sharpenSliderValue.textContent = `${sharpenPct}%`;