fix(globe): the cinematic look's atmosphere scale, warm-up and sunset clouds

- The takram uniform paths move to internals.js (forEachLuminanceUniform,
  loud in dev when a path is gone); look.js sets each factor to scale x
  the recorded base value, so shared or copied vectors are never scaled
  twice, and the stars keep the base value (own vector when shared).
  Stars at intensity 120: a starfield shows from space.
- Both night-side shader variants compile on the first two frames.
- The clouds hide once the sun sets at the camera (dark puffs at dusk).
- No allocation on look frames that change nothing (frozen updates, a
  scratch camera place from livePosition).
Gallery regenerated.
This commit is contained in:
German Khokhlov committed 2026-10-16 15:06:15 +04:00
1 parent 26968f4903
commit 5188e8869d
9 files changed
+410 -228

No files matched your search

+171 -110
View File
@@ -37,6 +37,49 @@ const plugin = (calls) => ({
},
});
/** A cinematic look past its two warm-up frames (updates cleared). */
function warmCinematic(view, internals) {
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
internals,
);
look.frame(900);
look.frame(900);
for (const entry of view.added) entry.updates.length = 0;
return look;
}
test('the night-side shader variants are both compiled on the first two frames', () => {
const view = fakeView(0);
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
);
const aerial = view.added.find(({ desc }) =>
Object.hasOwn(desc, 'aerialPerspective'),
);
assert.equal(look.frame(900), true);
assert.equal(look.frame(900), true);
assert.deepEqual(aerial.updates, [
{ aerialPerspective: { irradiance: true } },
{ aerialPerspective: { irradiance: false } },
]);
assert.equal(look.frame(900), false, 'then the usual rules');
const minimal = fakeView(0);
const plain = buildNavaraLook(
minimal,
plugin([]),
navaraScenePlan('minimal'),
() => 0,
);
assert.equal(plain.frame(900), false, 'no aerial perspective: no warm-up');
});
test('the photoreal look is the default plugin scene, untouched', () => {
const calls = [];
const view = fakeView(0);
@@ -68,12 +111,7 @@ test('the cinematic look adds its descriptors in order', () => {
test('from space the globe is lit by the atmosphere; near the ground the tiles keep their own light', () => {
const view = fakeView(0);
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
);
const look = warmCinematic(view);
const effect = (name) =>
view.added.find(({ desc }) => Object.hasOwn(desc, name));
assert.equal(look.frame(900), false, 'nothing changes at street level');
@@ -92,12 +130,7 @@ test('from space the globe is lit by the atmosphere; near the ground the tiles k
test('the clouds show only below their tops, switching in motion too', () => {
const view = fakeView(0);
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
);
const look = warmCinematic(view);
const clouds = view.added.find(({ desc }) => Object.hasOwn(desc, 'clouds'));
assert.equal(look.frame(900, true), false, 'shown at street level');
assert.equal(look.frame(20_000, true), true);
@@ -119,12 +152,7 @@ test('the clouds show only below their tops, switching in motion too', () => {
test('globe lighting switches on only at rest, and off even in motion', () => {
const view = fakeView(0);
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
);
const look = warmCinematic(view);
const aerial = view.added.find(({ desc }) =>
Object.hasOwn(desc, 'aerialPerspective'),
);
@@ -162,7 +190,9 @@ const vec = (x, y, z) => ({
y,
z,
copy(v) {
Object.assign(this, { x: v.x, y: v.y, z: v.z });
this.x = v.x;
this.y = v.y;
this.z = v.z;
return this;
},
multiplyScalar(k) {
@@ -174,103 +204,142 @@ const vec = (x, y, z) => ({
clone() {
return vec(this.x, this.y, this.z);
},
equals(v) {
return v.x === this.x && v.y === this.y && v.z === this.z;
},
});
const luminanceUniforms = () => ({
SUN_SPECTRAL_RADIANCE_TO_LUMINANCE: { value: vec(1.3, 0.9, 0.9) },
SKY_SPECTRAL_RADIANCE_TO_LUMINANCE: { value: vec(1.5, 0.9, 0.8) },
const SUN = 'SUN_SPECTRAL_RADIANCE_TO_LUMINANCE';
const SKY = 'SKY_SPECTRAL_RADIANCE_TO_LUMINANCE';
const factors = () => ({
[SUN]: { value: vec(1.3, 0.9, 0.9) },
[SKY]: { value: vec(1.5, 0.9, 0.8) },
});
/** Gives the cinematic handles the raw objects Navara 0.2.1 builds. */
function withRawAtmosphere(view) {
const find = (name) =>
view.added.find(({ desc }) => Object.hasOwn(desc, name));
const sky = luminanceUniforms();
const aerial = new Map(Object.entries(luminanceUniforms()));
const clouds = luminanceUniforms();
const stars = luminanceUniforms();
find('sky').ref = { raw: { material: { uniforms: sky } } };
find('stars').ref = { raw: { material: { uniforms: stars } } };
find('aerialPerspective').ref = { raw: { rawEffect: { uniforms: aerial } } };
find('clouds').ref = {
raw: {
rawEffect: { cloudsPass: { currentMaterial: { uniforms: clouds } } },
/** A stand-in for internals.js forEachLuminanceUniform over fake materials. */
function fakeInternals(materials) {
return {
forEachLuminanceUniform(handles, visit) {
for (const [name, scaled] of [
['sky', true],
['stars', false],
['aerialPerspective', true],
['clouds', true],
]) {
if (!handles[name]) continue;
const uniforms = materials[name];
if (!uniforms) continue;
for (const key of [SUN, SKY]) visit(key, uniforms[key], scaled);
}
},
};
return { sky, aerial, clouds, stars };
}
test('the cinematic atmosphere is brighter, the stars and tiles are not', () => {
const k = navaraScenePlan('cinematic').atmosphereLuminance;
const near = (a, b) => assert.ok(Math.abs(a - b) < 1e-12, `${a} vs ${b}`);
test('the atmosphere factors are set to scale × base, never compounded', () => {
const materials = {
sky: factors(),
stars: factors(),
aerialPerspective: factors(),
clouds: factors(),
};
const view = fakeView(0);
const plan = navaraScenePlan('cinematic');
const look = buildNavaraLook(view, plugin([]), plan, () => 0);
const raw = withRawAtmosphere(view);
assert.equal(look.frame(900), true, 'the first frame applies the scale');
const k = plan.atmosphereLuminance;
const sky = (u) => u.SKY_SPECTRAL_RADIANCE_TO_LUMINANCE.value;
const sun = (u) => u.SUN_SPECTRAL_RADIANCE_TO_LUMINANCE.value;
assert.ok(Math.abs(sky(raw.sky).x - 1.5 * k) < 1e-12);
assert.ok(Math.abs(sun(raw.sky).x - 1.3 * k) < 1e-12);
assert.ok(
Math.abs(
raw.aerial.get('SKY_SPECTRAL_RADIANCE_TO_LUMINANCE').value.x - 1.5 * k,
) < 1e-12,
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
fakeInternals(materials),
);
assert.ok(Math.abs(sky(raw.clouds).z - 0.8 * k) < 1e-12);
assert.equal(
sky(raw.stars).x,
1.5,
'only the sky, aerial perspective and clouds are walked',
);
assert.equal(look.frame(900), false, 'applied once, not compounded');
assert.ok(Math.abs(sky(raw.sky).x - 1.5 * k) < 1e-12);
// Navara rebuilds a material (a cloud quality change): the new one is scaled.
const fresh = luminanceUniforms();
view.added.find(({ desc }) =>
Object.hasOwn(desc, 'clouds'),
).ref.raw.rawEffect.cloudsPass.currentMaterial = { uniforms: fresh };
look.frame(900);
near(materials.sky[SKY].value.x, 1.5 * k);
near(materials.sky[SUN].value.x, 1.3 * k);
near(materials.aerialPerspective[SKY].value.z, 0.8 * k);
near(materials.clouds[SKY].value.x, 1.5 * k);
assert.equal(materials.stars[SKY].value.x, 1.5, 'the stars keep the base');
look.frame(900);
look.frame(900);
assert.equal(look.frame(900), false, 'nothing to change once applied');
near(materials.sky[SKY].value.x, 1.5 * k);
// A rebuilt material copying the scaled vector is not scaled again.
materials.clouds = {
[SUN]: { value: materials.sky[SUN].value.clone() },
[SKY]: { value: materials.sky[SKY].value.clone() },
};
assert.equal(look.frame(900), false);
near(materials.clouds[SKY].value.x, 1.5 * k);
// One built from scratch is.
materials.clouds = factors();
assert.equal(look.frame(900), true);
assert.ok(Math.abs(sky(fresh).x - 1.5 * k) < 1e-12);
near(materials.clouds[SKY].value.x, 1.5 * k);
});
test('a look without the scale and an atmosphere not built yet are left alone', () => {
test('vectors shared between materials are scaled once; stars sharing them get their own', () => {
// Separate uniforms holding one vector each, as Navara 0.2.1 builds them.
const shared = factors();
const sharing = () => ({
[SUN]: { value: shared[SUN].value },
[SKY]: { value: shared[SKY].value },
});
const materials = {
sky: shared,
stars: sharing(),
aerialPerspective: sharing(),
clouds: sharing(),
};
const view = fakeView(0);
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
fakeInternals(materials),
);
look.frame(900);
look.frame(900);
near(shared[SKY].value.x, 1.5 * k);
assert.notEqual(materials.stars[SKY].value, shared[SKY].value);
assert.equal(materials.stars[SKY].value.x, 1.5);
assert.equal(materials.stars[SUN].value.x, 1.3);
});
test('a look without the scale, or without internals, leaves the factors alone', () => {
const materials = { sky: factors(), stars: factors() };
const view = fakeView(0);
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('minimal'),
() => 0,
fakeInternals(materials),
);
const sky = luminanceUniforms();
view.added[0].ref = { raw: { material: { uniforms: sky } } };
assert.equal(look.frame(900), false);
assert.equal(sky.SKY_SPECTRAL_RADIANCE_TO_LUMINANCE.value.x, 1.5);
const cinematic = fakeView(0);
const other = buildNavaraLook(
cinematic,
assert.equal(materials.sky[SKY].value.x, 1.5);
const other = fakeView(0);
const cinematic = buildNavaraLook(
other,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
);
assert.equal(other.frame(900), false, 'no raw objects yet: nothing to scale');
cinematic.frame(900);
cinematic.frame(900);
assert.equal(cinematic.frame(900), false, 'no internals: no scale');
});
test('the cinematic stars hide in a daylit sky and show at night and from space', () => {
const view = fakeView(0);
let elevation = 40;
view.atmosphere.getSunElevation = () => elevation;
const look = buildNavaraLook(
view,
plugin([]),
navaraScenePlan('cinematic'),
() => 0,
);
const look = warmCinematic(view);
const stars = view.added.find(({ desc }) => Object.hasOwn(desc, 'stars'));
const place = { lat: 40.7, lng: -74 };
assert.equal(look.frame(900, false, 0, place), true);
assert.deepEqual(stars.updates, [{ visible: false }]);
assert.equal(look.frame(900, false, 0, place), false);
elevation = -10;
assert.equal(look.frame(900, false, 0, place), true);
look.frame(900, false, 0, place);
assert.deepEqual(stars.updates.at(-1), { visible: true });
elevation = 40;
look.frame(900, false, 0, place);
@@ -279,11 +348,31 @@ test('the cinematic stars hide in a daylit sky and show at night and from space'
const count = stars.updates.length;
look.frame(900, false, 0);
assert.equal(stars.updates.length, count, 'no place keeps them');
assert.equal(look.frame(900, false, 0, place), true, 'back down by day');
look.frame(900, false, 0, place);
assert.deepEqual(stars.updates.at(-1), { visible: false });
});
test('the minimal look keeps its stars whatever the sun', () => {
test('the cinematic clouds hide after sunset at the camera', () => {
const view = fakeView(0);
let elevation = 20;
view.atmosphere.getSunElevation = () => elevation;
const look = warmCinematic(view);
const clouds = view.added.find(({ desc }) => Object.hasOwn(desc, 'clouds'));
const place = { lat: 40.7, lng: -74 };
assert.equal(look.frame(900, false, 0, place), true, 'the stars hide');
assert.deepEqual(clouds.updates, []);
elevation = -1;
assert.equal(look.frame(900, false, 0, place), true);
assert.deepEqual(clouds.updates, [{ visible: false }]);
elevation = 1;
look.frame(900, false, 0, place);
assert.deepEqual(clouds.updates, [{ visible: false }], 'hysteresis');
elevation = 3;
look.frame(900, false, 0, place);
assert.deepEqual(clouds.updates.at(-1), { visible: true });
});
test('the minimal look keeps its stars and clouds whatever the sun', () => {
const view = fakeView(0);
view.atmosphere.getSunElevation = () => 40;
const look = buildNavaraLook(
@@ -295,31 +384,3 @@ test('the minimal look keeps its stars whatever the sun', () => {
look.frame(900, false, 0, { lat: 0, lng: 0 });
assert.deepEqual(view.added[1].updates, []);
});
test('a factor vector the materials share is scaled once', () => {
const view = fakeView(0);
const plan = navaraScenePlan('cinematic');
const look = buildNavaraLook(view, plugin([]), plan, () => 0);
const shared = luminanceUniforms();
const find = (name) =>
view.added.find(({ desc }) => Object.hasOwn(desc, name));
find('sky').ref = { raw: { material: { uniforms: shared } } };
find('aerialPerspective').ref = {
raw: { rawEffect: { uniforms: new Map(Object.entries(shared)) } },
};
find('clouds').ref = {
raw: {
rawEffect: {
cloudsPass: { currentMaterial: { uniforms: { ...shared } } },
},
},
};
look.frame(900);
look.frame(900);
assert.ok(
Math.abs(
shared.SKY_SPECTRAL_RADIANCE_TO_LUMINANCE.value.x -
1.5 * plan.atmosphereLuminance,
) < 1e-12,
);
});