mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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:
1 parent
26968f4903
commit
5188e8869d
9 files changed
+410
-228
No files matched your search
+118
-25
@@ -2,12 +2,14 @@
|
||||
// view and keeps it current while the view renders: the sun follows the wall
|
||||
// clock as the HUD's SUN elevation does; 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,
|
||||
@@ -23,9 +25,20 @@ 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 wall clock (ms), a test seam
|
||||
* @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();
|
||||
@@ -48,28 +61,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)) {
|
||||
@@ -77,30 +109,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;
|
||||
}
|
||||
}
|
||||
@@ -109,6 +139,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