Glow the Navara frame with the Display bloom behind an optional render.setBloom capability

postprocessing's BloomEffect runs after the overlays and before the visual styles, follows Cesium's eased strength and dead zone with its threshold set in display terms, and VisualEffects drives it when the engine has the bloom capability.
This commit is contained in:
German Khokhlov committed 2026-11-03 21:11:53 +04:00
1 parent 074f4af10e
commit c392d6fb50
15 files changed
+893 -178

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
// The app's Bloom control on Navara: postprocessing's BloomEffect (mipmap
// blur) as a Navara custom effect, with the settings of bloomSettings.js.
// Navara 0.2.1 has no bloom of its own. It runs just before the visual
// styles (stylePasses.js), after everything the scene and its overlays
// draw, as Cesium's bloom stage precedes the app's post stages and glows
// billboards too. A hidden pass is skipped: off costs nothing.
import { Effect as NavaraEffect, EffectDesc } from '@navaramap/three';
import { BloomEffect } from 'postprocessing';
import { createBloomPort } from './bloomSettings.js';
import { pipelinePassNames } from './internals.js';
export const BLOOM_EFFECT_KEY = 'gevBloom';
function apply(effect, settings) {
effect.luminanceMaterial.threshold = settings.luminanceThreshold;
effect.luminanceMaterial.smoothing = settings.luminanceSmoothing;
effect.mipmapBlurPass.radius = settings.radius;
effect.intensity = settings.intensity;
}
/** config.gevBloom: { settings } (bloomSettingsFromStrength). */
class BloomEffectDesc extends EffectDesc {
static key = BLOOM_EFFECT_KEY;
// Nothing anchors after it but the styles: before them, else before the
// final copy (the styles anchor after it).
static insertAfter = [];
static insertBefore = ['gevStyles', 'final'];
constructor(view, ctx, config) {
super(view, ctx, config);
this.settings = config[BLOOM_EFFECT_KEY].settings;
config[BLOOM_EFFECT_KEY].onContext?.(ctx);
}
createPass() {
const camera = this.view.camera.raw;
if (!camera) throw new Error('Camera not available for the bloom');
this.effect = new BloomEffect({ mipmapBlur: true, levels: 6 });
apply(this.effect, this.settings);
return new NavaraEffect(camera, this.effect);
}
onUpdateConfig(updates) {
super.onUpdateConfig(updates);
const settings = updates?.[BLOOM_EFFECT_KEY]?.settings;
if (!settings) return;
this.settings = settings;
if (this.effect) apply(this.effect, settings);
}
}
/**
* The bloom port createNavaraEngine takes (bloomSettings.js
* createBloomPort) on a view with the effect registered.
* @param {object} view an initialised ThreeView
*/
export function createNavaraBloom(view) {
view.registerEffect(BLOOM_EFFECT_KEY, BloomEffectDesc);
let context = null;
const port = createBloomPort((settings) => {
const handle = view.addEffect({
[BLOOM_EFFECT_KEY]: {
settings,
onContext: (ctx) => {
context = ctx;
},
},
visible: true,
});
return {
update: ({ settings: next, visible }) =>
handle.update({ [BLOOM_EFFECT_KEY]: { settings: next }, visible }),
delete: () => handle.delete(),
};
});
return {
...port,
/** Navara only (QA): whether bloom draws, and the pipeline order. */
diagnostics: () => ({
shown: port.shown(),
passes: pipelinePassNames(context),
}),
};
}