mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
fix(globe): a daylight sky and no daytime stars in the cinematic look
The atmosphere draws physical radiance scaled for an exposure near 10, while the baked Google tiles need exposure 1, so the noon sky came out dark navy with the stars showing through. The cinematic look now scales the atmosphere's radiance-to-luminance factors (sky, aerial perspective, clouds) by 3, leaving the tiles alone, and shows its stars only from space or with the sun below -6 degrees at the camera. Gallery regenerated.
This commit is contained in:
1 parent
bb8c0b83c4
commit
abf16ae8af
7 files changed
+430
-23
No files matched your search
+217
-10
@@ -6,7 +6,12 @@ import { navaraScenePlan } from './viewOptions.js';
|
||||
function fakeView(dateMs) {
|
||||
const added = [];
|
||||
const handle = (kind, desc) => {
|
||||
const entry = { kind, desc, updates: [], update: (u) => entry.updates.push(u) };
|
||||
const entry = {
|
||||
kind,
|
||||
desc,
|
||||
updates: [],
|
||||
update: (u) => entry.updates.push(u),
|
||||
};
|
||||
added.push(entry);
|
||||
return entry;
|
||||
};
|
||||
@@ -35,7 +40,12 @@ const plugin = (calls) => ({
|
||||
test('the photoreal look is the default plugin scene, untouched', () => {
|
||||
const calls = [];
|
||||
const view = fakeView(0);
|
||||
const look = buildNavaraLook(view, plugin(calls), navaraScenePlan('photoreal'), () => 0);
|
||||
const look = buildNavaraLook(
|
||||
view,
|
||||
plugin(calls),
|
||||
navaraScenePlan('photoreal'),
|
||||
() => 0,
|
||||
);
|
||||
assert.deepEqual(calls, [[]]);
|
||||
assert.deepEqual(look.handles, [{ id: 'sky' }]);
|
||||
assert.equal(look.frame(8_000_000), false, 'no globe lighting');
|
||||
@@ -58,8 +68,14 @@ 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 effect = (name) => view.added.find(({ desc }) => Object.hasOwn(desc, name));
|
||||
const look = buildNavaraLook(
|
||||
view,
|
||||
plugin([]),
|
||||
navaraScenePlan('cinematic'),
|
||||
() => 0,
|
||||
);
|
||||
const effect = (name) =>
|
||||
view.added.find(({ desc }) => Object.hasOwn(desc, name));
|
||||
assert.equal(look.frame(900), false, 'nothing changes at street level');
|
||||
assert.equal(look.frame(8_000_000), true);
|
||||
assert.equal(view.lit, true, 'no tile material recompiles');
|
||||
@@ -76,13 +92,22 @@ 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 = buildNavaraLook(
|
||||
view,
|
||||
plugin([]),
|
||||
navaraScenePlan('cinematic'),
|
||||
() => 0,
|
||||
);
|
||||
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);
|
||||
assert.deepEqual(clouds.updates, [{ visible: false }]);
|
||||
assert.equal(look.frame(3_800, true), false, 'hysteresis');
|
||||
assert.equal(view.atmosphere.overlay.value, null, 'no ghost of the last clouds');
|
||||
assert.equal(
|
||||
view.atmosphere.overlay.value,
|
||||
null,
|
||||
'no ghost of the last clouds',
|
||||
);
|
||||
assert.equal(view.atmosphere.shadowLength.value, null);
|
||||
assert.equal(look.frame(3_000, true), true);
|
||||
assert.deepEqual(clouds.updates.at(-1), { visible: true });
|
||||
@@ -94,20 +119,34 @@ 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 aerial = view.added.find(({ desc }) => Object.hasOwn(desc, 'aerialPerspective'));
|
||||
const look = buildNavaraLook(
|
||||
view,
|
||||
plugin([]),
|
||||
navaraScenePlan('cinematic'),
|
||||
() => 0,
|
||||
);
|
||||
const aerial = view.added.find(({ desc }) =>
|
||||
Object.hasOwn(desc, 'aerialPerspective'),
|
||||
);
|
||||
look.frame(20_000, true); // the clouds hide on the way up
|
||||
assert.equal(look.frame(2_300_000, true), false, 'a flight through space');
|
||||
assert.deepEqual(aerial.updates, []);
|
||||
assert.equal(look.frame(8_000_000, false), true, 'at rest');
|
||||
assert.equal(look.frame(500_000, true), true, 'coming down');
|
||||
assert.deepEqual(aerial.updates.at(-1), { aerialPerspective: { irradiance: false } });
|
||||
assert.deepEqual(aerial.updates.at(-1), {
|
||||
aerialPerspective: { irradiance: false },
|
||||
});
|
||||
});
|
||||
|
||||
test('the sun follows the wall clock, a minute at most behind, only on drawn frames', () => {
|
||||
let now = 1_000_000;
|
||||
const view = fakeView(now);
|
||||
const look = buildNavaraLook(view, plugin([]), navaraScenePlan('photoreal'), () => now);
|
||||
const look = buildNavaraLook(
|
||||
view,
|
||||
plugin([]),
|
||||
navaraScenePlan('photoreal'),
|
||||
() => now,
|
||||
);
|
||||
now += 30_000;
|
||||
assert.equal(look.frame(900), false);
|
||||
assert.equal(view.atmosphere.date.getTime(), 1_000_000);
|
||||
@@ -116,3 +155,171 @@ test('the sun follows the wall clock, a minute at most behind, only on drawn fra
|
||||
assert.equal(view.atmosphere.date.getTime(), now);
|
||||
assert.equal(look.frame(900), false);
|
||||
});
|
||||
|
||||
// A uniform as takram's materials hold it: { value: Vector3-like }.
|
||||
const vec = (x, y, z) => ({
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
copy(v) {
|
||||
Object.assign(this, { x: v.x, y: v.y, z: v.z });
|
||||
return this;
|
||||
},
|
||||
multiplyScalar(k) {
|
||||
this.x *= k;
|
||||
this.y *= k;
|
||||
this.z *= k;
|
||||
return this;
|
||||
},
|
||||
clone() {
|
||||
return vec(this.x, this.y, 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) },
|
||||
});
|
||||
|
||||
/** 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 } } },
|
||||
},
|
||||
};
|
||||
return { sky, aerial, clouds, stars };
|
||||
}
|
||||
|
||||
test('the cinematic atmosphere is brighter, the stars and tiles are not', () => {
|
||||
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,
|
||||
);
|
||||
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 };
|
||||
assert.equal(look.frame(900), true);
|
||||
assert.ok(Math.abs(sky(fresh).x - 1.5 * k) < 1e-12);
|
||||
});
|
||||
|
||||
test('a look without the scale and an atmosphere not built yet are left alone', () => {
|
||||
const view = fakeView(0);
|
||||
const look = buildNavaraLook(
|
||||
view,
|
||||
plugin([]),
|
||||
navaraScenePlan('minimal'),
|
||||
() => 0,
|
||||
);
|
||||
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,
|
||||
plugin([]),
|
||||
navaraScenePlan('cinematic'),
|
||||
() => 0,
|
||||
);
|
||||
assert.equal(other.frame(900), false, 'no raw objects yet: nothing to 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 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);
|
||||
assert.deepEqual(stars.updates.at(-1), { visible: true });
|
||||
elevation = 40;
|
||||
look.frame(900, false, 0, place);
|
||||
assert.equal(look.frame(8_000_000, false, 0, place), true, 'from space');
|
||||
assert.deepEqual(stars.updates.at(-1), { visible: true });
|
||||
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');
|
||||
assert.deepEqual(stars.updates.at(-1), { visible: false });
|
||||
});
|
||||
|
||||
test('the minimal look keeps its stars whatever the sun', () => {
|
||||
const view = fakeView(0);
|
||||
view.atmosphere.getSunElevation = () => 40;
|
||||
const look = buildNavaraLook(
|
||||
view,
|
||||
plugin([]),
|
||||
navaraScenePlan('minimal'),
|
||||
() => 0,
|
||||
);
|
||||
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,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user