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

+26 -5
View File
@@ -53,7 +53,8 @@ export class VisualEffects {
/**
* @param {object} options - Viewer, render ownership callbacks and optional clocks.
* Without a viewer, `engine` (the globe engine) draws the sharpening
* through render.setSharpen. Construction is inert; initStyles and
* through render.setSharpen, and the styles and bloom through
* render.setStyle and render.setBloom when it has them. Construction is inert; initStyles and
* initPostProcess retain startup ordering.
*/
constructor({
@@ -76,8 +77,11 @@ export class VisualEffects {
typeof engine?.render?.setSharpen === 'function' ? engine.render : null;
// Without a viewer, an engine that draws the styles itself
// (render.setStyle) gets them through stand-in stages (initStyles).
const capabilities = engineCapabilities(engine);
this.engineStyles =
!viewer && engineCapabilities(engine).visualStyles ? engine.render : null;
!viewer && capabilities.visualStyles ? engine.render : null;
// Likewise the bloom (render.setBloom) for Cesium's bloom stage.
this.engineBloom = !viewer && capabilities.bloom ? engine.render : null;
this.requestRender = requestRender;
this.holdRender = holdRender;
this.releaseRender = releaseRender;
@@ -136,7 +140,16 @@ export class VisualEffects {
}
initPostProcess(sharpenIntensity = this.sharpenIntensity) {
if (!this.viewer || this.stopped || this.sharpenStage) return;
if (this.stopped || this.sharpenStage) return;
// An engine that blooms starts from this owner's bloom (off), whatever
// a previous owner left on it.
if (!this.viewer) {
this.engineBloom?.setBloom({
enabled: false,
strength: bloomStrengthFromIntensity(this.bloomIntensity),
});
return;
}
this.bloomStage = this.viewer.scene.postProcessStages.bloom;
const names = [
'glowOnly',
@@ -195,16 +208,24 @@ export class VisualEffects {
}
syncBloomEnabled() {
if (this.stopped || !this.bloomStage) return;
this.bloomStage.enabled =
if (this.stopped) return;
const enabled =
this.bloomEnabled &&
bloomStrengthFromIntensity(this.bloomIntensity) > 0.06;
if (this.bloomStage) this.bloomStage.enabled = enabled;
this.engineBloom?.setBloom({ enabled });
}
applyBloomIntensity(intensity) {
if (this.stopped) return;
this.bloomIntensity = clampBloomIntensity(intensity);
this.requestRender('bloom');
if (this.engineBloom) {
this.engineBloom.setBloom({
strength: bloomStrengthFromIntensity(this.bloomIntensity),
});
this.syncBloomEnabled();
}
if (!this.bloomStage) return;
const rawStrength = bloomStrengthFromIntensity(this.bloomIntensity);
const strength = rawStrength <= 0.06 ? 0.0 : (rawStrength - 0.06) / 0.94;
+27
View File
@@ -459,6 +459,33 @@ test('Anime on an engine without a viewer reaches no sky box', () => {
effects.destroy();
});
test('without a viewer an engine that blooms gets the slider strength and dead zone', () => {
const { engine, effects, requests } = engineFixture(
createFakeEngine({ kind: 'navara', bloom: true }),
);
engine.render.setBloom({ enabled: true, strength: 1 });
effects.initPostProcess(0.49);
assert.deepEqual(
engine.render.bloom(),
{ enabled: false, strength: 0 },
'a new owner starts the engine from its own bloom',
);
effects.applyBloomIntensity(150);
assert.deepEqual(engine.render.bloom(), { enabled: false, strength: 0.75 });
effects.setBloomEnabled(true);
assert.deepEqual(engine.render.bloom(), { enabled: true, strength: 0.75 });
// Cesium's dead zone: the toggle stays on, nothing glows.
effects.applyBloomIntensity(10);
assert.deepEqual(engine.render.bloom(), { enabled: false, strength: 0.05 });
effects.applyBloomIntensity(200);
assert.deepEqual(engine.render.bloom(), { enabled: true, strength: 1 });
effects.setBloomEnabled(false);
assert.equal(engine.render.bloom().enabled, false);
assert.ok(requests.includes('bloom'));
assert.equal(effects.bloomStage, null);
effects.destroy();
});
test('without the visualStyles capability an engine gets no stages', () => {
const { effects } = engineFixture(createFakeEngine({ kind: 'navara' }));
effects.initStyles();