mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Merge migration/phase2-engine (4aaf9746) into migration/phase3-layers
The phase-2 review fixes: look internals in internals.js, the groundFloor resample throttle, tile height selection, the sharpen mirror, QA tile cache limits, engine.groundFloor diagnostics. In navara/index.js both sides are kept: the look gets internals.js's luminance uniforms and reads the sun's time from the engine clock's frame time, so engine.clock stays the one time source for the sun.
This commit is contained in:
commit
7c7422e281
21 files changed
+692
-291
No files matched your search
+119
-25
@@ -4,12 +4,14 @@
|
||||
// clock the HUD's SUN elevation reads unless QA moves it); the cinematic look
|
||||
// lights the globe
|
||||
// from the atmosphere when seen from space, shows its clouds only for low
|
||||
// views over low ground, brightens the atmosphere (atmosphereLuminance.js)
|
||||
// and shows its stars only at night or from space. All of it runs only on frames the view draws
|
||||
// anyway, so an idle view stays idle.
|
||||
// views over low ground and while the sun is up, brightens the atmosphere
|
||||
// (createLuminanceScaler, uniforms from internals.js), compiles both
|
||||
// night-side shader variants at startup and shows its stars only at night
|
||||
// or from space. All of it runs only on frames the view draws anyway, so an
|
||||
// idle view stays idle.
|
||||
|
||||
import { createAtmosphereLuminance } from './atmosphereLuminance.js';
|
||||
import {
|
||||
cloudsSunlitAt,
|
||||
cloudsVisibleAt,
|
||||
globeLightingAt,
|
||||
starsVisibleAt,
|
||||
@@ -25,9 +27,21 @@ import {
|
||||
* camera is moving, the height of the ground in view (metres above the
|
||||
* ellipsoid, NaN when unknown) and the camera's place (degrees, for the
|
||||
* sun's elevation there); it returns true when it changed the scene, so
|
||||
* the caller draws one more frame.
|
||||
* the caller draws one more frame. It allocates nothing on a frame that
|
||||
* changes nothing.
|
||||
* @param {() => number} [now] the sun's time (ms); the app passes the engine
|
||||
* clock's frame time (index.js), the wall clock by default and in tests
|
||||
* @param {{ forEachLuminanceUniform?: (handles: object, visit: (key: string, uniform: { value: object }, scaled: boolean) => void) => void }} [internals]
|
||||
* the takram uniforms behind the atmosphere scale (internals.js); without
|
||||
* it the scale does nothing.
|
||||
*/
|
||||
export function buildNavaraLook(view, plugin, plan, now = () => Date.now()) {
|
||||
export function buildNavaraLook(
|
||||
view,
|
||||
plugin,
|
||||
plan,
|
||||
now = () => Date.now(),
|
||||
{ forEachLuminanceUniform = null } = {},
|
||||
) {
|
||||
const handles = [];
|
||||
if (plan.pluginDefault) {
|
||||
const scene = plugin.addDefaultPhotorealScene();
|
||||
@@ -50,28 +64,47 @@ export function buildNavaraLook(view, plugin, plan, now = () => Date.now()) {
|
||||
const aerial = plan.globeLighting ? effect('aerialPerspective') : null;
|
||||
const clouds = effect('clouds');
|
||||
const stars = plan.daylightHidesStars ? mesh('stars') : null;
|
||||
const atmosphereHandles = {
|
||||
sky: mesh('sky'),
|
||||
aerialPerspective: effect('aerialPerspective'),
|
||||
clouds,
|
||||
};
|
||||
const brighten = createAtmosphereLuminance(plan.atmosphereLuminance ?? 1);
|
||||
const brighten = createLuminanceScaler(
|
||||
plan.atmosphereLuminance ?? 1,
|
||||
forEachLuminanceUniform,
|
||||
{
|
||||
sky: mesh('sky'),
|
||||
stars: mesh('stars'),
|
||||
aerialPerspective: effect('aerialPerspective'),
|
||||
clouds,
|
||||
},
|
||||
);
|
||||
let globeLit = false;
|
||||
// Both aerial-perspective variants (with and without the night side) are
|
||||
// compiled on the first two frames, during startup, so a later switch
|
||||
// finds its shader compiled (a cold switch stalled a frame for up to
|
||||
// 0.8 s, mid-flight on the way down from space).
|
||||
let warmUp = aerial ? 2 : 0;
|
||||
let cloudsShown = true;
|
||||
let cloudsSunlit = true;
|
||||
let starsShown = true;
|
||||
|
||||
const frame = (height, moving = false, ground = Number.NaN, place = null) => {
|
||||
// Every drawn frame: a material Navara rebuilds comes back unscaled.
|
||||
let changed = brighten(atmosphereHandles);
|
||||
let changed = brighten();
|
||||
const atmosphere = view.atmosphere;
|
||||
if (atmosphere && sunDateStale(atmosphere.date.getTime(), now())) {
|
||||
atmosphere.date = new Date(now());
|
||||
changed = true;
|
||||
}
|
||||
const elevation =
|
||||
place && typeof atmosphere?.getSunElevation === 'function'
|
||||
? atmosphere.getSunElevation(place)
|
||||
: Number.NaN;
|
||||
if (warmUp) {
|
||||
warmUp -= 1;
|
||||
aerial.update(warmUp ? IRRADIANCE_ON : IRRADIANCE_OFF);
|
||||
return true;
|
||||
}
|
||||
if (aerial) {
|
||||
const next = globeLightingAt(height, globeLit);
|
||||
// Switching recompiles the aerial perspective, a frame of about 0.8 s
|
||||
// headless: it switches on only at rest (a flight from city to city
|
||||
// Switching rebuilds the aerial perspective's shader (warmed up
|
||||
// above): it switches on only at rest (a flight from city to city
|
||||
// through space never switches) and off as soon as the camera comes
|
||||
// down, before the tiles would show relit.
|
||||
if (next !== globeLit && !(next && moving)) {
|
||||
@@ -79,30 +112,28 @@ export function buildNavaraLook(view, plugin, plan, now = () => Date.now()) {
|
||||
// Only the aerial perspective changes: the tiles already draw plain
|
||||
// albedo, so view.lit stays (toggling it recompiles every tile
|
||||
// material, a frame of about 0.8 s mid-flight).
|
||||
aerial.update({ aerialPerspective: { irradiance: next } });
|
||||
aerial.update(next ? IRRADIANCE_ON : IRRADIANCE_OFF);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
// Clouds only for a camera below them over low ground; switching them
|
||||
// costs no recompile, so it follows the camera in motion too.
|
||||
// Clouds only for a camera below them over low ground, and while the
|
||||
// sun is up at the camera (after sunset they read as dark puffs);
|
||||
// switching them costs no recompile, so it follows the camera in motion.
|
||||
if (clouds) {
|
||||
const next = cloudsVisibleAt(height, ground, cloudsShown);
|
||||
cloudsSunlit = cloudsSunlitAt(elevation, cloudsSunlit);
|
||||
const next = cloudsSunlit && cloudsVisibleAt(height, ground, cloudsShown);
|
||||
if (next !== cloudsShown) {
|
||||
cloudsShown = next;
|
||||
clouds.update({ visible: next });
|
||||
clouds.update(next ? VISIBLE : HIDDEN);
|
||||
parkCloudLayers(view.atmosphere, next);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (stars) {
|
||||
const elevation =
|
||||
place && typeof atmosphere?.getSunElevation === 'function'
|
||||
? atmosphere.getSunElevation(place)
|
||||
: Number.NaN;
|
||||
const next = starsVisibleAt(height, elevation, starsShown);
|
||||
if (next !== starsShown) {
|
||||
starsShown = next;
|
||||
stars.update({ visible: next });
|
||||
stars.update(next ? VISIBLE : HIDDEN);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@@ -111,6 +142,69 @@ export function buildNavaraLook(view, plugin, plan, now = () => Date.now()) {
|
||||
return { handles, frame };
|
||||
}
|
||||
|
||||
const IRRADIANCE_ON = Object.freeze({
|
||||
aerialPerspective: Object.freeze({ irradiance: true }),
|
||||
});
|
||||
const IRRADIANCE_OFF = Object.freeze({
|
||||
aerialPerspective: Object.freeze({ irradiance: false }),
|
||||
});
|
||||
const VISIBLE = Object.freeze({ visible: true });
|
||||
const HIDDEN = Object.freeze({ visible: false });
|
||||
|
||||
/**
|
||||
* The atmosphere scale (viewOptions.js ATMOSPHERE_LUMINANCE_SCALE): each
|
||||
* luminance factor is set to `scale` times the base value recorded the
|
||||
* first time it is seen, never multiplied in place, so a vector Navara
|
||||
* shares between materials, or copies into a rebuilt one, is never scaled
|
||||
* twice. The stars keep the base value: when they share the sky's vector,
|
||||
* they get their own. Returns `apply()`, true when it changed a uniform.
|
||||
*/
|
||||
export function createLuminanceScaler(scale, forEachUniform, handles) {
|
||||
if (scale === 1 || !forEachUniform) return () => false;
|
||||
const bases = new Map(); // key -> { base, target }
|
||||
const scaledVectors = new WeakSet();
|
||||
let changed = false;
|
||||
const entry = (key, value) => {
|
||||
let found = bases.get(key);
|
||||
if (!found) {
|
||||
found = {
|
||||
base: value.clone(),
|
||||
target: value.clone().multiplyScalar(scale),
|
||||
};
|
||||
bases.set(key, found);
|
||||
}
|
||||
return found;
|
||||
};
|
||||
const record = (key, uniform) => entry(key, uniform.value);
|
||||
const scaleOne = (key, uniform, scaled) => {
|
||||
if (!scaled) return;
|
||||
const { target } = entry(key, uniform.value);
|
||||
scaledVectors.add(uniform.value);
|
||||
if (uniform.value.equals(target)) return;
|
||||
uniform.value.copy(target);
|
||||
changed = true;
|
||||
};
|
||||
const keepBase = (key, uniform, scaled) => {
|
||||
if (scaled) return;
|
||||
const { base } = entry(key, uniform.value);
|
||||
if (scaledVectors.has(uniform.value)) {
|
||||
uniform.value = base.clone();
|
||||
changed = true;
|
||||
} else if (!uniform.value.equals(base)) {
|
||||
uniform.value.copy(base);
|
||||
changed = true;
|
||||
}
|
||||
};
|
||||
return () => {
|
||||
changed = false;
|
||||
// Bases first, from the values as Navara built them.
|
||||
forEachUniform(handles, record);
|
||||
forEachUniform(handles, scaleOne);
|
||||
forEachUniform(handles, keepBase);
|
||||
return changed;
|
||||
};
|
||||
}
|
||||
|
||||
// The clouds hand the aerial perspective their last output through the
|
||||
// atmosphere (overlay, shadow, shadow length) once, when they first draw.
|
||||
// A hidden clouds pass leaves those in place, and the aerial perspective
|
||||
|
||||
Reference in new issue
Block a user