ridge: delete the noise ridges and the Vienna horizon bake; the scene is sky, stars and rain
Cuts ridgeWorld, ridgeBake, horizon.ts, viennaHorizon.json, bake-horizon.py and the layer/rig/drift half of Ridge.ts, the HORIZON_CREDIT line, onBake, and the dead SkyColours fields (ground, sunAzimuth, band). Rollback is the tag parked/ratatoskr-noise-ridge (ruling ridge-ad-rollback-tag). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
97be0f8086
commit
d03b0b1cac
18 changed files with 61 additions and 2328 deletions
|
|
@ -1,6 +1,5 @@
|
|||
// Standalone page for the ridge scene: full window, no host app. `?tier=still|low|full` picks the
|
||||
// tier, `?probe=1` shows the rAF median/p95 readout. The bake record (each chunk's cost, from
|
||||
// the scene's `onBake`) and the long tasks the page saw are on `window.bakes` and `window.longTasks`
|
||||
// tier, `?probe=1` shows the rAF median/p95 readout. The long tasks the page saw are on `window.longTasks`
|
||||
// for a driver to read. Not shipped.
|
||||
import { startBackgroundScene } from '../../src/app/features/scene';
|
||||
import type { SceneTier } from '../../src/app/features/scene';
|
||||
|
|
@ -8,8 +7,7 @@ import type { SceneTier } from '../../src/app/features/scene';
|
|||
const q = new URLSearchParams(location.search);
|
||||
const tier = (q.get('tier') ?? 'full') as SceneTier;
|
||||
const canvas = document.getElementById('c') as HTMLCanvasElement;
|
||||
const w = window as unknown as { scene: unknown; bakes: unknown[]; longTasks: number[]; firstViewMs: number };
|
||||
w.bakes = [];
|
||||
const w = window as unknown as { scene: unknown; longTasks: number[]; firstViewMs: number };
|
||||
w.longTasks = [];
|
||||
try {
|
||||
new PerformanceObserver((l) => l.getEntries().forEach((e) => w.longTasks.push(e.duration))).observe({
|
||||
|
|
@ -21,7 +19,6 @@ try {
|
|||
const t0 = performance.now();
|
||||
startBackgroundScene({ tier }, {}, {
|
||||
canvas,
|
||||
onBake: (b: unknown) => w.bakes.push(b),
|
||||
} as never).then((scene) => {
|
||||
w.firstViewMs = performance.now() - t0;
|
||||
w.scene = scene;
|
||||
|
|
|
|||
|
|
@ -1,123 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Bake the 360 degree horizon seen from the ridge viewpoint (src/app/features/scene/ridge/vienna.ts: VIENNA) into
|
||||
src/app/features/scene/ridge/viennaHorizon.json: per azimuth, the highest elevation angle the terrain subtends, the distance and
|
||||
height of the point that sets it, and the surface slope there (the normal). The source is Copernicus DEM GLO-30, a DSM (it
|
||||
includes buildings and trees, which is what a horizon is made of). Source, licence and attribution go beside the bake, in its
|
||||
`source` block, so the file cannot travel without them.
|
||||
|
||||
python3 scripts/bake-horizon.py <dir with the nine Copernicus_DSM_COG_10_N{47..49}_00_E{015..017}_00_DEM.tif> [out.json]
|
||||
|
||||
Needs numpy, tifffile, imagecodecs (pip, in a venv: this is a build-time tool, the bake is committed).
|
||||
"""
|
||||
import json
|
||||
import math
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import tifffile
|
||||
|
||||
LAT, LON = 48.1929826, 16.3534237 # the server location Meta gave, 2026-11-11; keep equal to VIENNA in vienna.ts
|
||||
STEP_DEG = 0.5
|
||||
RADIUS_KM = 60.0
|
||||
EARTH_R = 6_371_000.0
|
||||
REFRACTION_K = 0.13 # standard terrestrial refraction: effective radius R / (1 - k)
|
||||
EYE_ABOVE_GROUND = 0.0 # the viewpoint is the DSM surface at the point (a roof, in a city); the page lifts it with VIENNA.altitudeKm
|
||||
MIN_KM = 1.0 # the DSM at 30 m cannot resolve neighbouring buildings as a horizon; nearer than this is not ridge
|
||||
|
||||
|
||||
class Mosaic:
|
||||
def __init__(self, folder: Path):
|
||||
self.tiles = {}
|
||||
for p in sorted(folder.glob("Copernicus_DSM_COG_10_N*_E*_DEM.tif")):
|
||||
lat0 = int(p.name.split("_N")[1][:2])
|
||||
lon0 = int(p.name.split("_E")[1][:3])
|
||||
with tifffile.TiffFile(p) as t:
|
||||
self.tiles[(lat0, lon0)] = t.pages[0].asarray()
|
||||
|
||||
def height(self, lat: float, lon: float) -> float:
|
||||
key = (math.floor(lat), math.floor(lon))
|
||||
a = self.tiles.get(key)
|
||||
if a is None:
|
||||
return float("nan")
|
||||
n = a.shape[0]
|
||||
# Tile origin is the north-west corner; pixels are 1/n degree, pixel-is-area (centre at +0.5).
|
||||
y = (key[0] + 1 - lat) * n - 0.5
|
||||
x = (lon - key[1]) * n - 0.5
|
||||
y0, x0 = int(math.floor(y)), int(math.floor(x))
|
||||
y0 = min(max(y0, 0), n - 2)
|
||||
x0 = min(max(x0, 0), n - 2)
|
||||
fy, fx = min(max(y - y0, 0), 1), min(max(x - x0, 0), 1)
|
||||
top = a[y0, x0] * (1 - fx) + a[y0, x0 + 1] * fx
|
||||
bot = a[y0 + 1, x0] * (1 - fx) + a[y0 + 1, x0 + 1] * fx
|
||||
return float(top * (1 - fy) + bot * fy)
|
||||
|
||||
|
||||
def offset(lat: float, lon: float, az_deg: float, d_m: float):
|
||||
az = math.radians(az_deg)
|
||||
dlat = d_m * math.cos(az) / 111_320.0
|
||||
dlon = d_m * math.sin(az) / (111_320.0 * math.cos(math.radians(lat)))
|
||||
return lat + dlat, lon + dlon
|
||||
|
||||
|
||||
def main() -> None:
|
||||
folder = Path(sys.argv[1])
|
||||
out = Path(sys.argv[2]) if len(sys.argv) > 2 else Path("src/app/features/scene/ridge/viennaHorizon.json")
|
||||
m = Mosaic(folder)
|
||||
h0 = m.height(LAT, LON) + EYE_ABOVE_GROUND
|
||||
az_count = int(360 / STEP_DEG)
|
||||
elev, dist, peak, east, north = [], [], [], [], []
|
||||
for i in range(az_count):
|
||||
az = i * STEP_DEG
|
||||
best, best_d, best_h, best_pt = -90.0, 0.0, h0, (LAT, LON)
|
||||
d = MIN_KM * 1000
|
||||
while d <= RADIUS_KM * 1000:
|
||||
lat, lon = offset(LAT, LON, az, d)
|
||||
h = m.height(lat, lon)
|
||||
if not math.isnan(h):
|
||||
drop = d * d / (2 * EARTH_R) * (1 - REFRACTION_K)
|
||||
ang = math.degrees(math.atan2(h - h0 - drop, d))
|
||||
if ang > best:
|
||||
best, best_d, best_h, best_pt = ang, d, h, (lat, lon)
|
||||
d += 30.0 if d < 5000 else 60.0 if d < 20000 else 120.0
|
||||
# Surface slope at the peak (rise per metre, east and north), central difference over 60 m.
|
||||
la, lo = best_pt
|
||||
dl, dn = 60.0 / 111_320.0, 60.0 / (111_320.0 * math.cos(math.radians(la)))
|
||||
ge = (m.height(la, lo + dn) - m.height(la, lo - dn)) / 120.0
|
||||
gn = (m.height(la + dl, lo) - m.height(la - dl, lo)) / 120.0
|
||||
elev.append(round(best, 3))
|
||||
dist.append(round(best_d / 1000, 2))
|
||||
peak.append(round(best_h, 1))
|
||||
east.append(round(ge, 3))
|
||||
north.append(round(gn, 3))
|
||||
doc = {
|
||||
"viewpoint": {"lat": LAT, "lon": LON, "groundM": round(h0, 1)},
|
||||
"stepDeg": STEP_DEG,
|
||||
"radiusKm": RADIUS_KM,
|
||||
"minKm": MIN_KM,
|
||||
"curvature": f"drop d^2/2R*(1-{REFRACTION_K}), R={int(EARTH_R)} m",
|
||||
"source": {
|
||||
"dataset": "Copernicus DEM GLO-30 (COP-DEM_GLO-30-DGED), a DSM, EGM2008 heights, 1 arc-second grid",
|
||||
"tiles": sorted(f"N{a:02d}_00_E{b:03d}_00" for a, b in m.tiles),
|
||||
"tileBytesEach": "about 42-44 MB (Cloud Optimized GeoTIFF); nine tiles, about 380 MB, read once, not committed",
|
||||
"url": "https://copernicus-dem-30m.s3.amazonaws.com/ (AWS Open Data, eu-central-1, no account)",
|
||||
"licence": "Copernicus DEM licence: free of charge for any use incl. commercial, attribution required, no warranty "
|
||||
"(https://spacedata.copernicus.eu/collections/copernicus-digital-elevation-model, Licencing)",
|
||||
"attribution": "Contains modified Copernicus data: DEM © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 "
|
||||
"provided under COPERNICUS by the European Union and ESA; all rights reserved.",
|
||||
"bakedBy": "scripts/bake-horizon.py",
|
||||
},
|
||||
"elevationDeg": elev,
|
||||
"distanceKm": dist,
|
||||
"peakHeightM": peak,
|
||||
"slopeEast": east,
|
||||
"slopeNorth": north,
|
||||
}
|
||||
out.write_text(json.dumps(doc, separators=(",", ":")) + "\n")
|
||||
top = int(np.argmax(elev))
|
||||
print(f"ground {h0:.1f} m; {az_count} azimuths; highest {elev[top]:.2f} deg at az {top * STEP_DEG}, {dist[top]} km, {peak[top]} m")
|
||||
print(f"wrote {out} ({out.stat().st_size} bytes)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -4,37 +4,20 @@
|
|||
config says `backgroundScene.style: 'raymarch'`; the tier flag still defaults to `off`, and null still
|
||||
means "keep the CSS ground". Everything below this section describes the opt-in ray-march scene.
|
||||
|
||||
- `ridge/Ridge.ts` `createRidgeScene({ canvas, tier, probe?, onProbe?, onBake?, sky? })` returns `{ login, dispose }` or
|
||||
null (tier `off`, no 2D context). Each of four ridge layers is a function of world-x (`ridge/ridgeWorld.ts` `profile`:
|
||||
ridged multifractal value noise, each octave folded at its crest and weighted by the previous one, domain-warped; one
|
||||
function, a parameter row per layer; nothing repeats). World-x is baked in chunks (1.2 viewport widths, integer pixels)
|
||||
onto plain 2D canvases over a baked sky gradient on the host canvas. Per layer a track holds three chunk canvases: two
|
||||
the window can reach and one ahead. The first view bakes only the first chunk of each layer; the others are baked in
|
||||
tasks of about 6 ms (`setTimeout`; a chunk is baked, put on a canvas with its in-scatter, and blurred in column bands, each sized from the last band's time). Per frame the only motion is the
|
||||
compositor sliding the track with a CSS transform (a Web Animation of `translate3d`, one chunk long, `fill: forwards`,
|
||||
150-420 s per viewport width, farther is slower); when it finishes the chunks move one slot left and the track restarts
|
||||
at 0 in the same task (no jump), and the canvas that left is baked with the next stretch of world. A second animation
|
||||
sways the whole rig (up to 5% of the width sideways, 3% of the height down, 150 s loop): the slow yaw and pitch.
|
||||
No script runs per frame. The host canvas and the layers' parent must be positioned and the canvas should fill the parent.
|
||||
- `ridge/ridgeBake.ts` is the pixel function (pure, no DOM): per column the crest's slope gives a normal, lit against the
|
||||
sun (`sunDirection`: x = 0.9 sin(2 pi \* `sunAzimuth`), so the sun is toward +x for azimuth 0 to 0.5, strongest at 0.25, toward -x for 0.5 to 1; with no `sunAzimuth` the face lighting falls back to 0.3 and the in-scatter is off); the face under it has a light-to-haze gradient, erosion
|
||||
streaks (a folded noise at gully width, darker with steepness) and a lit rim on the crest. Contrast scales with
|
||||
`transmittance`; the base colour, haze and blur are the aerial perspective below, not redone.
|
||||
- Paused when the tab is hidden; under `prefers-reduced-motion` the layers are painted but never played.
|
||||
`tier: 'still'` flattens sky and layers into the host canvas at once and leaves no extra elements.
|
||||
- `ridge/Ridge.ts` `createRidgeScene({ canvas, tier, probe?, onProbe?, sky? })` returns `{ login, dispose }` or
|
||||
null (tier `off`, no 2D context). It paints the sky (`ridge/physicalSky.ts`, from the `SkyColours` the host passes) on the host
|
||||
canvas at the viewport's size in canvas pixels, then the stars baked into it, a twinkle overlay canvas for the swinging ones
|
||||
(`ridge/stars.ts`) and, when it rains, tiled rain streaks slid down on the compositor (`ridge/rain.ts`). There is no skyline: the
|
||||
scene shows sky, stars and weather only. No script runs per frame except the twinkle, at most every 50 ms.
|
||||
The host canvas and its parent must be positioned and the canvas should fill the parent. A resize rebuilds it; so does a sky change
|
||||
(`index.ts`).
|
||||
- Paused when the tab is hidden; under `prefers-reduced-motion` the rain is paused and the stars stay at base brightness.
|
||||
`tier: 'still'` paints the sky and stars and adds no overlay, no rain and no loop.
|
||||
- Cadence guard: for the first 2 s after start (after 5 warm-up frames) rAF intervals are sampled; if their p95 is over
|
||||
33 ms the scene flattens to a still image (`ridge/probe.ts`) and stops. `?probe=1` (or `probe: true`) keeps sampling
|
||||
33 ms the scene settles to a still image (`ridge/probe.ts`) and stops. `?probe=1` (or `probe: true`) keeps sampling
|
||||
and shows `n / median / p95` in a corner readout.
|
||||
- `ridge/skyColour.ts` `skyColours()` is the one place sky colours come from: a fixed dusk placeholder until Void's
|
||||
`src/sky/sun.js` `light()` lands (PR #20); replace its body, keep the signature.
|
||||
- Aerial perspective (`ridge/ridgeWorld.ts` `AERIAL`, `transmittance`, `layerColour`, `edgeBlur`, `scatterAlpha`) is applied
|
||||
once while the layers are baked, from the `SkyColours` the one seam returns (`sunAzimuth` optional: omit it for no
|
||||
in-scatter). Layer distance d = 1 - depth; transmittance T = exp(-1.6 d) (0.24 / 0.37 / 0.58 / 1.00 far to near); colour is
|
||||
`T * ground + (1 - T) * haze`, then chroma drops by `0.5 (1 - T)`; the edge is blurred up to 2 px (canvas pixels at DPR 1,
|
||||
via the 2D `filter`, skipped where unsupported, e.g. Safari); a faint warm in-scatter (at most 0.16 alpha) peaks at the
|
||||
sun's azimuth in world-x (two incommensurate cosines, so not periodic). Nothing runs per frame. The in-scatter lobe is
|
||||
painted into each chunk, so it drifts with the layer rather than staying fixed under the sun; that is a known
|
||||
approximation until the sun is a real, fixed light.
|
||||
- `ridge/skyColour.ts` `skyColours()` is the fallback three-stop palette (top, mid, horizon) a scene gets with no `sky` option; the host
|
||||
passes `ridgeSkyFor` (skyForState.ts) instead.
|
||||
- `harness/scene/bundle.cjs <out> ridge` builds a standalone page (`?tier=`, `?probe=1`).
|
||||
- Not yet measured on a phone: see the PR description.
|
||||
|
||||
|
|
@ -78,13 +61,10 @@ holds a GL context gives no 2D one, so a GL failure after context creation (comp
|
|||
x `AMBIENT_GAIN` 0.25 x `NIGHT_LIFT` up to 4; now `ambient_linear` as baked, so midnight's fill is about 2.5 to 3.5 times darker than
|
||||
the lifted one). `HAZE_K` (0.0004 per metre) is unchanged.
|
||||
|
||||
## Ridge scene: Vienna, the real horizon and the weather
|
||||
## Ridge scene: Vienna and the weather
|
||||
|
||||
The ridge sky is the physical atmosphere (`ridge/earthAtmosphere.ts`) lit by the real sun over the viewpoint, 48.1929826 N, 16.3534237 E
|
||||
(`ridge/vienna.ts`). Its farthest layer is the real horizon of that viewpoint, standing still under the sun: `ridge/viennaHorizon.json`,
|
||||
baked by `scripts/bake-horizon.py` from Copernicus DEM GLO-30 (nine 1 degree tiles, about 380 MB, kept out of the repo). The file carries its
|
||||
own `source` block with the dataset, tiles, licence and the attribution the licence requires. Its elevation range is 2.1 degrees, so the
|
||||
layer draws the shape of the ring stretched to a fixed relief, not its scale.
|
||||
(`ridge/vienna.ts`).
|
||||
|
||||
The weather is one number (`ridge/weather.ts`), from the page URL's `?weather=`, else `weather.json` beside `config.json`, else clear.
|
||||
The browser never calls a weather service. `weather.json` is written by Eureka's refresher (gamecult-ops `docs/weather-feed.md`, a 5-minute timer; the only writer) from GeoSphere Austria's TAWES station 11035 (Wien Hohe Warte), credit
|
||||
|
|
@ -92,7 +72,7 @@ The browser never calls a weather service. `weather.json` is written by Eureka's
|
|||
glow_wm2, sunshine_s_10min, attribution}`, null for a missing measurement. A file fetched more than 30 minutes ago, or holding an observation more than 40 minutes old, or from another station, is a clear
|
||||
sky. Rain is the gauge; cloud is an estimate from the global radiation against Haurwitz's clear-sky value, cross-checked by the sunshine
|
||||
duration, with the humidity as the fallback when the sun is low (`ridge/weatherFeed.ts`). The weather draws a cloud deck in the sky
|
||||
(`ridge/clouds.ts`), thickens the layers' valley mist, and lays tiled rain streaks over everything (`ridge/rain.ts`, compositor-driven, none in a still).
|
||||
(`ridge/clouds.ts`) and lays tiled rain streaks over the sky (`ridge/rain.ts`, compositor-driven, none in a still).
|
||||
|
||||
## Entry points
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import { stopPropagation } from '../../utils/keyboard';
|
|||
import { useSkyState } from '../../hooks/useSkyState';
|
||||
import { SKY_STATES, setSkyState, type SkyState } from './skyState';
|
||||
import {
|
||||
HORIZON_CREDIT,
|
||||
WEATHER_CREDIT,
|
||||
WEATHER_CREDIT_URL,
|
||||
WEATHER_DATASET,
|
||||
|
|
@ -139,9 +138,6 @@ export function SkyStateControl() {
|
|||
</a>
|
||||
. {WEATHER_DATASET}.
|
||||
</Text>
|
||||
<Text size="T200" priority="300">
|
||||
{HORIZON_CREDIT}
|
||||
</Text>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
|
|
|
|||
|
|
@ -1,21 +1,8 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { createRidgeScene } from './Ridge';
|
||||
import { bakeSlice, BakeParams, layerPaint } from './ridgeBake';
|
||||
import { valueNoise, hash2 } from './noise';
|
||||
import { FrameSampler, frameStats, SLOW_P95_MS, WARMUP_FRAMES, WINDOW_MS } from './probe';
|
||||
import {
|
||||
AERIAL,
|
||||
LAYERS,
|
||||
edgeBlur,
|
||||
hazeColour,
|
||||
layerColour,
|
||||
layerSize,
|
||||
profile,
|
||||
ridgeY,
|
||||
scatterAlpha,
|
||||
transmittance,
|
||||
} from './ridgeWorld';
|
||||
import { skyColours, SkyColours } from './skyColour';
|
||||
import type { SkyColours } from './skyColour';
|
||||
import { makeStars } from './stars';
|
||||
import { makePhysicalSky } from './physicalSky';
|
||||
import { startBackgroundScene } from '../index';
|
||||
|
|
@ -36,111 +23,6 @@ describe('noise', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('ridge profile', () => {
|
||||
it('stays in [0, 1] for any world-x, negative and far included, and layers differ', () => {
|
||||
for (const spec of LAYERS) {
|
||||
for (let i = -300; i < 300; i += 7) {
|
||||
for (const off of [0, 1234.5, 98765.25]) {
|
||||
const p = profile(spec, i / 50 + off);
|
||||
expect(p).toBeGreaterThanOrEqual(0);
|
||||
expect(p).toBeLessThanOrEqual(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(profile(LAYERS[0], 0.3)).not.toBeCloseTo(profile(LAYERS[1], 0.3), 3);
|
||||
});
|
||||
|
||||
it('ridge tops lie inside the layer band', () => {
|
||||
const size = layerSize(400, 800, 1);
|
||||
for (const spec of LAYERS) {
|
||||
for (let x = -500; x < 5 * size.period; x += 17) {
|
||||
const y = ridgeY(spec, x / size.period, size.height, 800);
|
||||
expect(y).toBeGreaterThanOrEqual(0);
|
||||
expect(y).toBeLessThanOrEqual(size.height);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('layers get darker and slower toward the viewer, and their sizes are integers', () => {
|
||||
const sky = skyColours();
|
||||
const lum = (c: readonly number[]) => c[0] + c[1] + c[2];
|
||||
for (let i = 1; i < LAYERS.length; i += 1) {
|
||||
expect(lum(layerColour(LAYERS[i], sky))).toBeLessThan(lum(layerColour(LAYERS[i - 1], sky)));
|
||||
expect(LAYERS[i].seconds).toBeLessThan(LAYERS[i - 1].seconds);
|
||||
}
|
||||
for (const [w, h, s] of [
|
||||
[393, 851, 2],
|
||||
[1280, 720, 1],
|
||||
[412.5, 915.3, 2],
|
||||
] as const) {
|
||||
const z = layerSize(w, h, s);
|
||||
expect(
|
||||
Number.isInteger(z.period) && Number.isInteger(z.chunk) && Number.isInteger(z.height)
|
||||
).toBe(true);
|
||||
expect(z.chunk).toBeGreaterThan(z.period);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('aerial perspective', () => {
|
||||
const sky = skyColours();
|
||||
const lum = (c: readonly number[]) => 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
||||
const chroma = (c: readonly number[]) => Math.max(...c) - Math.min(...c);
|
||||
const far = LAYERS[0];
|
||||
const near = LAYERS[LAYERS.length - 1];
|
||||
|
||||
it('transmittance is Beer-Lambert in distance: 1 at the viewer, exp(-k d) behind, strictly falling', () => {
|
||||
expect(transmittance(near)).toBe(1);
|
||||
for (const l of LAYERS)
|
||||
expect(transmittance(l)).toBeCloseTo(Math.exp(-AERIAL.extinction * (1 - l.depth)), 12);
|
||||
for (let i = 1; i < LAYERS.length; i += 1)
|
||||
expect(transmittance(LAYERS[i])).toBeGreaterThan(transmittance(LAYERS[i - 1]));
|
||||
// two layers' optical depths add: T(a)*T(b) = T(a+b)
|
||||
const t = (d: number) => Math.exp(-AERIAL.extinction * d);
|
||||
expect(t(0.3) * t(0.4)).toBeCloseTo(t(0.7), 12);
|
||||
});
|
||||
|
||||
it('the nearest layer is exactly the ground colour; the farthest tends to the haze', () => {
|
||||
expect(layerColour(near, sky)).toEqual([...sky.ground]);
|
||||
const h = hazeColour(sky);
|
||||
const f = layerColour(far, sky);
|
||||
const dist = (a: readonly number[], b: readonly number[]) =>
|
||||
Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
||||
expect(dist(f, h)).toBeLessThan(dist(sky.ground, h) * (transmittance(far) + 0.2));
|
||||
});
|
||||
|
||||
it('colour moves toward the haze and loses chroma with distance, beyond what the mix alone does', () => {
|
||||
const h = hazeColour(sky);
|
||||
for (const l of LAYERS.slice(0, -1)) {
|
||||
const t = transmittance(l);
|
||||
const c = layerColour(l, sky);
|
||||
const mixed = [0, 1, 2].map((i) => sky.ground[i] * t + h[i] * (1 - t));
|
||||
expect(chroma(c)).toBeLessThan(chroma(mixed));
|
||||
expect(Math.abs(lum(c) - lum(mixed))).toBeLessThan(1.5); // desaturation keeps luma
|
||||
}
|
||||
});
|
||||
|
||||
it('edge softening grows with distance and is zero at the viewer', () => {
|
||||
expect(edgeBlur(near)).toBe(0);
|
||||
for (let i = 1; i < LAYERS.length; i += 1)
|
||||
expect(edgeBlur(LAYERS[i])).toBeLessThan(edgeBlur(LAYERS[i - 1]));
|
||||
expect(edgeBlur(far)).toBeLessThanOrEqual(AERIAL.blurPx);
|
||||
});
|
||||
|
||||
it('in-scatter is faint, grows with distance, is off without a sun, and never repeats', () => {
|
||||
const az = 0.3;
|
||||
const s = { ...sky, sunAzimuth: az };
|
||||
const lobe = (t: number) => scatterAlpha(far, s, t);
|
||||
expect(lobe(az * 1.9)).toBeGreaterThan(lobe(az * 1.9 + 0.95));
|
||||
for (const period of [1, 1.9, 3.8, 5.7, 19])
|
||||
expect(Math.abs(lobe(0.7 + period) - lobe(0.7))).toBeGreaterThan(1e-4);
|
||||
expect(lobe(az * 1.9)).toBeLessThanOrEqual(AERIAL.scatter);
|
||||
expect(scatterAlpha(near, s, az)).toBe(0);
|
||||
expect(scatterAlpha(LAYERS[1], s, az * 1.9)).toBeLessThan(scatterAlpha(far, s, az * 1.9));
|
||||
expect(scatterAlpha(far, { ...sky, sunAzimuth: undefined }, az)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('frame sampler', () => {
|
||||
const feed = (s: FrameSampler, dt: number, frames: number, from = 0) => {
|
||||
let t = from;
|
||||
|
|
@ -242,26 +124,19 @@ function fakeEl(tag = 'div') {
|
|||
};
|
||||
return el;
|
||||
}
|
||||
// A day sky has no stars, so the scene tests below see only the ridge loop; the dusk default
|
||||
// A day sky has no stars, so the scene tests above see only the sky; the dusk default
|
||||
// carries stars and a twinkle overlay, tested in 'the starfield in the scene'.
|
||||
const DAY: SkyColours = {
|
||||
top: [96, 150, 220],
|
||||
mid: [150, 190, 235],
|
||||
horizon: [240, 215, 190],
|
||||
ground: [7, 17, 26],
|
||||
sunAzimuth: 0.3,
|
||||
};
|
||||
const draws: string[] = [];
|
||||
/** Every ImageData put on any canvas, in order. */
|
||||
const puts: any[] = [];
|
||||
/** For every drawImage: the source canvas's width as it was at the moment of the draw. */
|
||||
const drawnWidths: number[] = [];
|
||||
function ctx(withFilter = false) {
|
||||
function ctx() {
|
||||
const c: any = {
|
||||
globalCompositeOperation: 'source-over',
|
||||
createLinearGradient: () => ({ addColorStop: vi.fn() }),
|
||||
fillRect() {
|
||||
draws.push(c.globalCompositeOperation === 'source-atop' ? 'scatter' : 'sky');
|
||||
draws.push('sky');
|
||||
},
|
||||
save() {},
|
||||
restore() {},
|
||||
|
|
@ -272,7 +147,7 @@ function ctx(withFilter = false) {
|
|||
width: w,
|
||||
height: h,
|
||||
}),
|
||||
putImageData: (img: any) => puts.push(img),
|
||||
putImageData() {},
|
||||
beginPath() {},
|
||||
moveTo() {},
|
||||
stroke() {},
|
||||
|
|
@ -292,13 +167,9 @@ function ctx(withFilter = false) {
|
|||
if (c.arcing) c.arcing = false;
|
||||
else draws.push('fill');
|
||||
},
|
||||
drawImage: (src: any) => {
|
||||
drawnWidths.push(src.width);
|
||||
draws.push('flatten');
|
||||
},
|
||||
drawImage() {},
|
||||
set fillStyle(_v: unknown) {},
|
||||
};
|
||||
if (withFilter) c.filter = 'none';
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
@ -310,8 +181,6 @@ let search: string;
|
|||
beforeEach(() => {
|
||||
rafQueue = [];
|
||||
draws.length = 0;
|
||||
puts.length = 0;
|
||||
drawnWidths.length = 0;
|
||||
search = '';
|
||||
motion = { matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() };
|
||||
doc = Object.assign(new EventTarget(), {
|
||||
|
|
@ -347,11 +216,6 @@ function host() {
|
|||
parent.appendChild(canvas);
|
||||
return { parent, canvas };
|
||||
}
|
||||
/** The rig holds one track per layer, farthest first; each track holds three chunk canvases. */
|
||||
const rigOf = (parent: any) => parent.children.find((c: any) => c.tag === 'div');
|
||||
const tracksOf = (parent: any): any[] => rigOf(parent).children;
|
||||
const animsOf = (parent: any): any[] =>
|
||||
[rigOf(parent), ...tracksOf(parent)].flatMap((e: any) => e.anims);
|
||||
const runFrames = (dt: number, n: number, from = 0) => {
|
||||
let t = from;
|
||||
for (let i = 0; i < n && rafQueue.length; i += 1) {
|
||||
|
|
@ -375,29 +239,17 @@ describe('createRidgeScene', () => {
|
|||
expect(createRidgeScene({ canvas, tier: 'full', sky: DAY })).toBeNull();
|
||||
});
|
||||
|
||||
it('bakes the sky once, and per layer only the first chunk before the first frame, at integer sizes, farthest first', () => {
|
||||
it('paints the sky once at the viewport in canvas pixels and adds nothing to the page in a clear day', () => {
|
||||
const { parent, canvas } = host();
|
||||
const baked: any[] = [];
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY, onBake: (b) => baked.push(b) })!;
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
expect(s).not.toBeNull();
|
||||
const tracks = tracksOf(parent);
|
||||
expect(tracks).toHaveLength(LAYERS.length);
|
||||
tracks.forEach((t: any, i: number) => {
|
||||
expect(t.children).toHaveLength(3);
|
||||
expect(t.animate).toHaveBeenCalledTimes(Number.isFinite(LAYERS[i].seconds) ? 1 : 0);
|
||||
t.children.forEach((c: any) => {
|
||||
expect(Number.isInteger(c.width) && Number.isInteger(c.height)).toBe(true);
|
||||
expect(c.width).toBe(layerSize(400, 800, 2).chunk);
|
||||
});
|
||||
});
|
||||
expect(baked.map((b) => [b.layer, b.chunk, b.first])).toEqual(
|
||||
LAYERS.map((l) => [l.index, 0, true])
|
||||
);
|
||||
expect([canvas.width, canvas.height]).toEqual([800, 1600]);
|
||||
expect(draws.filter((d) => d === 'sky')).toHaveLength(1);
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('after the layers are painted, a smooth run draws nothing more and ends its rAF loop', () => {
|
||||
it('a smooth run draws nothing more and ends its rAF loop', () => {
|
||||
const { canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
const before = draws.length;
|
||||
|
|
@ -407,53 +259,23 @@ describe('createRidgeScene', () => {
|
|||
s.dispose();
|
||||
});
|
||||
|
||||
it('p95 over 33 ms across 2 s flattens to a still image and removes the layers', () => {
|
||||
const { parent, canvas } = host();
|
||||
it('p95 over 33 ms across 2 s settles to a still and reports it', () => {
|
||||
const { canvas } = host();
|
||||
const onProbe = vi.fn();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', onProbe, sky: DAY })!;
|
||||
runFrames(100, 100);
|
||||
expect(draws.filter((d) => d === 'flatten')).toHaveLength(LAYERS.length);
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(onProbe).toHaveBeenLastCalledWith(expect.objectContaining({ still: true }));
|
||||
expect(rafQueue).toHaveLength(0);
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it("'still' tier flattens immediately and never starts a loop", () => {
|
||||
it("'still' tier never starts a loop", () => {
|
||||
const { parent, canvas } = host();
|
||||
createRidgeScene({ canvas, tier: 'still' });
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(draws.filter((d) => d === 'flatten')).toHaveLength(LAYERS.length);
|
||||
expect(rafQueue).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('prefers-reduced-motion: layers are built but never played, and nothing is sampled', () => {
|
||||
motion.matches = true;
|
||||
const { canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
const anims = animsOf(canvas.parentElement);
|
||||
expect(anims.length).toBe(LAYERS.filter((l) => Number.isFinite(l.seconds)).length + 1); // one drift per drifting layer (the horizon does not) and the sway
|
||||
expect(anims.every((a: any) => a.pause.mock.calls.length > 0)).toBe(true);
|
||||
anims.forEach((a: any) => expect(a.play).not.toHaveBeenCalled());
|
||||
expect(rafQueue).toHaveLength(0);
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('pauses the drift when the tab is hidden and resumes when it is visible', () => {
|
||||
const { parent, canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
const anims = animsOf(parent);
|
||||
anims.forEach((a: any) => a.pause.mockClear());
|
||||
doc.visibilityState = 'hidden';
|
||||
doc.dispatchEvent(new Event('visibilitychange'));
|
||||
anims.forEach((a: any) => expect(a.pause).toHaveBeenCalled());
|
||||
anims.forEach((a: any) => a.play.mockClear());
|
||||
doc.visibilityState = 'visible';
|
||||
doc.dispatchEvent(new Event('visibilitychange'));
|
||||
anims.forEach((a: any) => expect(a.play).toHaveBeenCalled());
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('?probe=1 keeps the rAF loop alive and shows median and p95', () => {
|
||||
search = '?probe=1';
|
||||
const { parent, canvas } = host();
|
||||
|
|
@ -469,9 +291,8 @@ describe('createRidgeScene', () => {
|
|||
it('?probe=1 does nothing where the overlays are not allowed: no readout, the loop ends', () => {
|
||||
search = '?probe=1';
|
||||
const { parent, canvas } = host();
|
||||
const before = parent.children.length;
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
expect(parent.children.length).toBe(before + 1); // the rig
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
runFrames(16.7, 300);
|
||||
expect(rafQueue.length).toBe(0);
|
||||
s.dispose();
|
||||
|
|
@ -485,33 +306,22 @@ describe('createRidgeScene', () => {
|
|||
(window as any).innerHeight = 0;
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY });
|
||||
expect(s).not.toBeNull();
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(draws).toHaveLength(0);
|
||||
// Still zero: a resize does not paint either.
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
await new Promise((r) => setTimeout(r, 300));
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(draws).toHaveLength(0);
|
||||
(window as any).innerWidth = 400;
|
||||
(window as any).innerHeight = 800;
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
await new Promise((r) => setTimeout(r, 300));
|
||||
expect(tracksOf(parent)).toHaveLength(LAYERS.length);
|
||||
expect(draws.filter((d) => d === 'sky')).toHaveLength(1);
|
||||
s!.dispose();
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
});
|
||||
|
||||
it('dispose cancels the loop, the animations and the layers', () => {
|
||||
const { parent, canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
const anims = animsOf(parent);
|
||||
s.dispose();
|
||||
anims.forEach((a: any) => expect(a.cancel).toHaveBeenCalled());
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(rafQueue).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('the door', () => {
|
||||
it('runs the ridge scene by default and never requests a WebGL context', async () => {
|
||||
const { canvas } = host();
|
||||
|
|
@ -530,65 +340,6 @@ describe('the door', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('aerial perspective in the scene', () => {
|
||||
it('is baked once: one scatter fill per hazy layer, none per frame, the nearest layer has none', () => {
|
||||
const { canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
expect(draws.filter((d) => d === 'scatter')).toHaveLength(LAYERS.length - 1);
|
||||
const before = draws.length;
|
||||
runFrames(16.7, 400);
|
||||
expect(draws.length).toBe(before);
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('a sky without a sun bakes no scatter', () => {
|
||||
const { canvas } = host();
|
||||
const s = createRidgeScene({
|
||||
canvas,
|
||||
tier: 'full',
|
||||
sky: { ...DAY, sunAzimuth: undefined },
|
||||
})!;
|
||||
expect(draws.filter((d) => d === 'scatter')).toHaveLength(0);
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('softens with the canvas filter where it exists, blur scaled by DPR, from pixels baked past the chunk edges', () => {
|
||||
const { parent, canvas } = host();
|
||||
const filters: string[] = [];
|
||||
const orig = (document as any).createElement;
|
||||
(document as any).createElement = (t: string) => {
|
||||
const el = orig(t);
|
||||
el.getContext = vi.fn(() => {
|
||||
const c = ctx(true);
|
||||
let f = 'none';
|
||||
Object.defineProperty(c, 'filter', {
|
||||
get: () => f,
|
||||
set: (v: string) => {
|
||||
f = v;
|
||||
filters.push(v);
|
||||
},
|
||||
});
|
||||
return c;
|
||||
});
|
||||
return el;
|
||||
};
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
const blurs = filters.filter((f) => f !== 'none');
|
||||
expect(blurs).toHaveLength(LAYERS.length - 1); // nearest is sharp
|
||||
expect(blurs[0]).toBe(`blur(${edgeBlur(LAYERS[0]) * 2}px)`); // DPR 2
|
||||
expect(parent.children).toHaveLength(2); // sky canvas and the rig
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it("'still' tier keeps the sky and flattens the aerial layers without extra elements", () => {
|
||||
const { parent, canvas } = host();
|
||||
createRidgeScene({ canvas, tier: 'still' });
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(draws.filter((d) => d === 'sky')).toHaveLength(1);
|
||||
expect(draws.filter((d) => d === 'flatten')).toHaveLength(LAYERS.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the starfield in the scene', () => {
|
||||
const count = (kind: string) => draws.filter((d) => d === kind).length;
|
||||
const night = {
|
||||
|
|
@ -602,7 +353,7 @@ describe('the starfield in the scene', () => {
|
|||
const calls = motion.addEventListener.mock.calls.filter((c: any[]) => c[0] === name);
|
||||
return calls[calls.length - 1][1] as () => void;
|
||||
};
|
||||
// Everything but the overlay's own marks: the bake and the ridges.
|
||||
// Everything but the overlay's own marks: the sky and its stars.
|
||||
const baked = () => draws.filter((d) => d !== 'twinkle' && d !== 'clear').length;
|
||||
|
||||
it('bakes every star once into the sky; per frame only the overlay is touched', () => {
|
||||
|
|
@ -610,8 +361,8 @@ describe('the starfield in the scene', () => {
|
|||
const s = createRidgeScene({ canvas, tier: 'full', sky: night })!;
|
||||
expect(count('star')).toBe(N);
|
||||
expect(count('sky')).toBe(1);
|
||||
expect(parent.children[1].anims).toHaveLength(0); // the overlay: above the sky, under the ridges
|
||||
expect(parent.children).toHaveLength(3);
|
||||
expect(parent.children[1].anims).toHaveLength(0); // the overlay, above the sky
|
||||
expect(parent.children).toHaveLength(2);
|
||||
const before = baked();
|
||||
runFrames(16.7, 300); // 5 s at 60 fps; the overlay repaints at 20 fps
|
||||
expect(baked()).toBe(before);
|
||||
|
|
@ -627,7 +378,7 @@ describe('the starfield in the scene', () => {
|
|||
const { parent, canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!;
|
||||
expect(count('star')).toBe(0);
|
||||
expect(parent.children).toHaveLength(2);
|
||||
expect(parent.children).toHaveLength(1);
|
||||
runFrames(16.7, 60);
|
||||
expect(count('clear')).toBe(0);
|
||||
s.dispose();
|
||||
|
|
@ -687,13 +438,12 @@ describe('the starfield in the scene', () => {
|
|||
s.dispose();
|
||||
});
|
||||
|
||||
it('flattening to a still (slow frames) drops the overlay and leaves every star baked under the ridges', () => {
|
||||
it('flattening to a still (slow frames) drops the overlay and leaves every star baked into the sky', () => {
|
||||
const { parent, canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: night })!;
|
||||
runFrames(100, 100);
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(count('star')).toBe(N);
|
||||
expect(draws.indexOf('flatten')).toBeGreaterThan(draws.lastIndexOf('star'));
|
||||
expect(rafQueue).toHaveLength(0);
|
||||
s.dispose();
|
||||
});
|
||||
|
|
@ -707,125 +457,14 @@ describe('the starfield in the scene', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('endless drift: chunks baked on demand and recycled', () => {
|
||||
const size = layerSize(400, 800, 2); // the fake host: 400 x 800 CSS px at DPR 2
|
||||
const until = async (cond: () => boolean) => {
|
||||
const t0 = Date.now();
|
||||
while (!cond()) {
|
||||
if (Date.now() - t0 > 10000) throw new Error('timed out waiting for the background bakes');
|
||||
await new Promise((r) => setTimeout(r, 5));
|
||||
}
|
||||
};
|
||||
/** The pixels chunk `m` of layer `li` must hold: the pure bake of its world columns, no blur. */
|
||||
const expected = (li: number, m: number) => {
|
||||
const p: BakeParams = {
|
||||
spec: LAYERS[li],
|
||||
sky: DAY,
|
||||
period: size.period,
|
||||
scale: 2,
|
||||
viewH: 1600,
|
||||
rows: size.height,
|
||||
bandH: size.height,
|
||||
px0: m * size.chunk,
|
||||
cols: size.chunk,
|
||||
};
|
||||
const out = new Uint8ClampedArray(p.cols * p.rows * 4);
|
||||
bakeSlice(out, p, layerPaint(p.spec, DAY), 0, p.cols);
|
||||
return Buffer.from(out.buffer);
|
||||
};
|
||||
/** Each distinct ImageData put, in order of first appearance: one per baked chunk. */
|
||||
const baked = () => [...new Set(puts)].map((img) => Buffer.from(img.data.buffer));
|
||||
const start = () => {
|
||||
const { parent, canvas } = host();
|
||||
const records: any[] = [];
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: DAY, onBake: (b) => records.push(b) })!;
|
||||
return { parent, s, records };
|
||||
};
|
||||
|
||||
it('bakes every chunk from its own world columns: no offset, the next chunk continues the last', async () => {
|
||||
const { s, records } = start();
|
||||
await until(() => records.length === 3 * LAYERS.length);
|
||||
// First view: chunk 0 of each layer; then, per layer in queue order, chunks 1 and 2.
|
||||
const order = [
|
||||
...LAYERS.map((l) => [l.index, 0]),
|
||||
...LAYERS.flatMap((l) => [
|
||||
[l.index, 1],
|
||||
[l.index, 2],
|
||||
]),
|
||||
];
|
||||
expect(records.map((r) => [r.layer, r.chunk])).toEqual(order);
|
||||
const imgs = baked();
|
||||
expect(imgs).toHaveLength(order.length);
|
||||
order.forEach(([li, m], i) => expect(imgs[i].equals(expected(li, m))).toBe(true));
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('when the drift animation ends, the chunks move one slot left and the track restarts', async () => {
|
||||
const { parent, s, records } = start();
|
||||
await until(() => records.length === 3 * LAYERS.length);
|
||||
const track = tracksOf(parent)[1]; // the first layer that drifts: the horizon, [0], stands still
|
||||
const [e0, e1, e2] = track.children;
|
||||
const first = track.anims[0];
|
||||
// One chunk of drift, not one viewport: the track slides by the width of a chunk.
|
||||
expect(first.keyframes[1].transform).toContain(`${-size.chunk / 2}px`);
|
||||
expect(track.animate).toHaveBeenCalledTimes(1);
|
||||
first.finish();
|
||||
expect(first.cancel).toHaveBeenCalled();
|
||||
expect(track.animate).toHaveBeenCalledTimes(2);
|
||||
const w = size.chunk / 2;
|
||||
expect([e1.style.left, e2.style.left, e0.style.left]).toEqual(['0px', `${w}px`, `${2 * w}px`]);
|
||||
expect(track.anims[1].keyframes[1].transform).toContain(`${-w}px`);
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('the canvas that left is baked with the next stretch of world, and each rotation after it, without end', async () => {
|
||||
const { parent, s, records } = start();
|
||||
await until(() => records.length === 3 * LAYERS.length);
|
||||
const track = tracksOf(parent)[1];
|
||||
const done = () => records.filter((r) => r.layer === 1).map((r) => r.chunk);
|
||||
for (let m = 3; m <= 5; m += 1) {
|
||||
track.anims[track.anims.length - 1].finish();
|
||||
await until(() => done().includes(m));
|
||||
}
|
||||
expect(done()).toEqual([0, 1, 2, 3, 4, 5]);
|
||||
// The pixels of chunks 3 to 5 are the world's, not a repeat of an earlier one.
|
||||
const imgs = baked();
|
||||
const layer1 = imgs.filter((_, i) => records[i].layer === 1);
|
||||
[3, 4, 5].forEach((m, k) => expect(layer1[3 + k].equals(expected(1, m))).toBe(true));
|
||||
expect(layer1[3].equals(layer1[0])).toBe(false);
|
||||
s.dispose();
|
||||
});
|
||||
|
||||
it('with the blur, each chunk is blurred from a scratch canvas of its own width: seams stay opaque and exact', async () => {
|
||||
const orig = (document as any).createElement;
|
||||
(document as any).createElement = (tag: string) => {
|
||||
const el = orig(tag);
|
||||
el.getContext = vi.fn(() => ctx(true));
|
||||
return el;
|
||||
};
|
||||
const { s, records } = start();
|
||||
await until(() => records.length === 3 * LAYERS.length);
|
||||
const want = new Set(
|
||||
LAYERS.filter((l) => edgeBlur(l) > 0).map(
|
||||
(l) => size.chunk + 2 * Math.ceil(3 * edgeBlur(l) * 2)
|
||||
)
|
||||
);
|
||||
expect(want.size).toBeGreaterThan(1); // the layers' pads differ, which is what a shared canvas gets wrong
|
||||
// Every blur reads a source exactly as wide as that chunk's padded bake, at the moment of the draw.
|
||||
expect(new Set(drawnWidths)).toEqual(want);
|
||||
s.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
describe('rain in the scene', () => {
|
||||
const rainy = (w: number): SkyColours => ({
|
||||
...DAY,
|
||||
physical: makePhysicalSky('day', new Date('2026-06-21T10:40:00Z'), w),
|
||||
});
|
||||
const rainEls = (parent: any) =>
|
||||
parent.children.filter((c: any) => c.tag === 'div' && c !== rigOf(parent));
|
||||
const rainEls = (parent: any) => parent.children.filter((c: any) => c.tag === 'div');
|
||||
|
||||
it('lays one falling tile per rain layer over the ridges when it rains, each slid by its own height on the compositor', () => {
|
||||
it('lays one falling tile per rain layer over the sky when it rains, each slid by its own height on the compositor', () => {
|
||||
const { parent, canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: rainy(1) })!;
|
||||
const els = rainEls(parent);
|
||||
|
|
|
|||
|
|
@ -1,33 +1,11 @@
|
|||
/* eslint-disable no-param-reassign -- the bake writes into the canvases and layer records it is handed */
|
||||
import type { Scene, SceneOptions } from '../Scene';
|
||||
import { overlayRequested } from '../debugOverlays';
|
||||
import { FrameSampler, FrameStats } from './probe';
|
||||
import { skyColours, SkyColours, Srgb } from './skyColour';
|
||||
import { paintSky as paintPhysicalSky } from './physicalSky';
|
||||
import { activeAt, drawStars, drawTwinkle as paintTwinkle, makeStars, Star } from './stars';
|
||||
import { bakeSlice, BakeParams, layerPaint } from './ridgeBake';
|
||||
import {
|
||||
LAYERS,
|
||||
LayerSpec,
|
||||
edgeBlur,
|
||||
HORIZON_TRACK_SHIFT,
|
||||
layerSize,
|
||||
scatterAlpha,
|
||||
transmittance,
|
||||
} from './ridgeWorld';
|
||||
import { hfovDeg } from './horizon';
|
||||
import { viewFor, VFOV_DEG } from './skyDome';
|
||||
import { drawRainTile, RAIN_TILES } from './rain';
|
||||
|
||||
/** One chunk's bake: `ms` is the summed task time, `maxTaskMs` the longest single task; `first` marks the bake of the first view. */
|
||||
export interface BakeRecord {
|
||||
layer: number;
|
||||
chunk: number;
|
||||
ms: number;
|
||||
maxTaskMs: number;
|
||||
first: boolean;
|
||||
}
|
||||
|
||||
export type RidgeOptions = Pick<SceneOptions, 'canvas' | 'tier'> & {
|
||||
/** Show the rAF median/p95 readout. Default: the page URL has `?probe=1`, where `debug` allows it. */
|
||||
probe?: boolean;
|
||||
|
|
@ -37,8 +15,6 @@ export type RidgeOptions = Pick<SceneOptions, 'canvas' | 'tier'> & {
|
|||
onProbe?: (s: FrameStats & { still: boolean }) => void;
|
||||
/** The sky's colours; default `skyColours()`, the one function to replace with Void's sun.js. */
|
||||
sky?: SkyColours;
|
||||
/** Called after each chunk is baked (a chunk is one layer's stretch of world-x): the cost record. */
|
||||
onBake?: (b: BakeRecord) => void;
|
||||
};
|
||||
|
||||
const css = (c: Srgb): string => `rgb(${c[0]},${c[1]},${c[2]})`;
|
||||
|
|
@ -107,217 +83,20 @@ function paintSky(
|
|||
|
||||
const clock = (): number => (typeof performance !== 'undefined' ? performance.now() : Date.now());
|
||||
|
||||
type Size = ReturnType<typeof layerSize>;
|
||||
|
||||
const SCATTER_STOPS = 16;
|
||||
|
||||
/** Warm in-scatter over the silhouette only (source-atop): a horizontal gradient over the chunk's world-x. */
|
||||
function scatter(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
spec: LayerSpec,
|
||||
sky: SkyColours,
|
||||
widthPx: number,
|
||||
heightPx: number,
|
||||
t0: number,
|
||||
tPerPx: number,
|
||||
bandX = 0,
|
||||
bandW = widthPx
|
||||
) {
|
||||
if (sky.sunAzimuth === undefined || transmittance(spec) >= 1) return; // the nearest layer takes none
|
||||
const g = ctx.createLinearGradient(0, 0, widthPx, 0);
|
||||
const [r, gr, b] = sky.horizon;
|
||||
for (let k = 0; k <= SCATTER_STOPS; k += 1) {
|
||||
const a = scatterAlpha(spec, sky, t0 + (tPerPx * widthPx * k) / SCATTER_STOPS);
|
||||
g.addColorStop(k / SCATTER_STOPS, `rgba(${r},${gr},${b},${a})`);
|
||||
}
|
||||
ctx.globalCompositeOperation = 'source-atop';
|
||||
ctx.fillStyle = g;
|
||||
ctx.fillRect(bandX, 0, bandW, heightPx);
|
||||
ctx.globalCompositeOperation = 'source-over';
|
||||
}
|
||||
|
||||
/** A chunk's bake in slices: `step(budgetMs)` returns true once the chunk is on its canvas. */
|
||||
interface Job {
|
||||
step(budgetMs: number): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* One layer's stretch of world-x `[m * chunk, (m + 1) * chunk)` painted onto `el`, in three phases of
|
||||
* column bands, each band sized to the task budget by measuring the last one: bake the pixels
|
||||
* (`bakeSlice`), put them on a canvas with the in-scatter, and (where the 2D `filter` exists) blur them
|
||||
* into `el`. The blur needs neighbours, so the pixels are baked `pad` columns past both ends and
|
||||
* the bottom into a scratch canvas this job owns, and each blurred band reads `pad` columns either side of
|
||||
* itself: seams show no fade. The scratch is made when the job first runs and dropped when it ends.
|
||||
*/
|
||||
function chunkJob(
|
||||
el: HTMLCanvasElement,
|
||||
makeCanvas: () => HTMLCanvasElement,
|
||||
spec: LayerSpec,
|
||||
sky: SkyColours,
|
||||
size: Size,
|
||||
viewH: number,
|
||||
scale: number,
|
||||
m: number,
|
||||
record: (ms: number, maxTaskMs: number) => void
|
||||
): Job | null {
|
||||
const ctx = context2d(el);
|
||||
if (!ctx) return null;
|
||||
const blur = edgeBlur(spec) * scale;
|
||||
const pad = blur > 0 && 'filter' in ctx ? Math.ceil(3 * blur) : 0;
|
||||
const cols = size.chunk + 2 * pad;
|
||||
const rows = size.height + pad;
|
||||
const params: BakeParams = {
|
||||
spec,
|
||||
sky,
|
||||
horizonView:
|
||||
spec.horizon && sky.physical
|
||||
? {
|
||||
azimuthDeg: viewFor(sky.physical.sun, size.period / viewH).azimuthDeg,
|
||||
hfovDeg: hfovDeg(size.period / viewH, VFOV_DEG),
|
||||
}
|
||||
: undefined,
|
||||
period: size.period,
|
||||
scale,
|
||||
viewH,
|
||||
rows,
|
||||
bandH: size.height,
|
||||
px0: m * size.chunk - pad,
|
||||
cols,
|
||||
};
|
||||
const paint = layerPaint(spec, sky);
|
||||
const t0World = params.px0 / size.period;
|
||||
let scratch: HTMLCanvasElement | undefined;
|
||||
let sctx: CanvasRenderingContext2D | null = ctx;
|
||||
let img: ImageData | undefined;
|
||||
/** 0 bake, 1 put and in-scatter, 2 blur into el; a chunk with no blur ends after 1. */
|
||||
let phase = 0;
|
||||
let pos = 0;
|
||||
let sliceCols = 32;
|
||||
let total = 0;
|
||||
let longest = 0;
|
||||
const last = pad > 0 ? 2 : 1;
|
||||
const start = (): boolean => {
|
||||
if (pad > 0) {
|
||||
scratch = makeCanvas();
|
||||
scratch.width = cols;
|
||||
scratch.height = rows;
|
||||
sctx = context2d(scratch);
|
||||
} else {
|
||||
el.width = size.chunk;
|
||||
el.height = size.height;
|
||||
}
|
||||
if (!sctx) return false;
|
||||
img = sctx.createImageData(cols, rows);
|
||||
return true;
|
||||
};
|
||||
const work = (x: number, n: number) => {
|
||||
if (!img || !sctx) return;
|
||||
if (phase === 0) bakeSlice(img.data, params, paint, x, x + n);
|
||||
else if (phase === 1) {
|
||||
sctx.putImageData(img, 0, 0, x, 0, n, rows);
|
||||
scatter(sctx, spec, sky, cols, rows, t0World, 1 / size.period, x, n);
|
||||
} else {
|
||||
// One draw: a blurred draw cut into bands costs more in the margins than it saves in task length.
|
||||
ctx.drawImage(scratch as HTMLCanvasElement, -pad, 0);
|
||||
}
|
||||
};
|
||||
return {
|
||||
step(budgetMs) {
|
||||
const t0 = clock();
|
||||
// Allocating the canvases and the pixel buffer is a task of its own.
|
||||
if (!img) {
|
||||
if (!start()) return true;
|
||||
if (Number.isFinite(budgetMs)) {
|
||||
total += clock() - t0;
|
||||
longest = Math.max(longest, clock() - t0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
while (phase <= last && clock() - t0 < budgetMs) {
|
||||
const end = phase === 2 ? size.chunk : cols;
|
||||
if (pos === 0 && phase === 2) {
|
||||
el.width = size.chunk;
|
||||
el.height = size.height;
|
||||
ctx.filter = `blur(${blur}px)`;
|
||||
}
|
||||
const n = phase === 2 ? end : Math.min(end - pos, sliceCols);
|
||||
const s0 = clock();
|
||||
work(pos, n);
|
||||
pos += n;
|
||||
const dt = Math.max(clock() - s0, 0.02);
|
||||
sliceCols = Number.isFinite(budgetMs)
|
||||
? Math.max(8, Math.min(512, Math.round((n * budgetMs * 0.4) / dt)))
|
||||
: cols;
|
||||
if (pos >= end) {
|
||||
if (phase === 2) ctx.filter = 'none';
|
||||
phase += 1;
|
||||
pos = 0;
|
||||
if (phase === 1 || phase === 2) sliceCols = Number.isFinite(budgetMs) ? 64 : cols;
|
||||
}
|
||||
}
|
||||
const dt = clock() - t0;
|
||||
total += dt;
|
||||
longest = Math.max(longest, dt);
|
||||
const done = phase > last;
|
||||
if (done) {
|
||||
img = undefined;
|
||||
if (scratch) {
|
||||
scratch.width = 0;
|
||||
scratch.height = 0;
|
||||
}
|
||||
scratch = undefined;
|
||||
record(total, longest);
|
||||
}
|
||||
return done;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
interface Chunk {
|
||||
el: HTMLCanvasElement;
|
||||
/** World chunk index it holds or is being baked to hold. */
|
||||
id: number;
|
||||
job?: Job;
|
||||
ready: boolean;
|
||||
}
|
||||
|
||||
/** One layer: a track that drifts by one chunk per animation, holding three chunk canvases. */
|
||||
interface LayerState {
|
||||
spec: LayerSpec;
|
||||
track: HTMLElement;
|
||||
/** Slot 0 and 1 are what the window can see; slot 2 is the one ahead, baked in the background. */
|
||||
slots: Chunk[];
|
||||
anim?: Animation;
|
||||
}
|
||||
|
||||
interface Built {
|
||||
rig: HTMLElement;
|
||||
layers: LayerState[];
|
||||
sway?: Animation;
|
||||
size: Size;
|
||||
/** CSS px to canvas px, and the viewport's height in canvas px, as baked. */
|
||||
scale: number;
|
||||
viewH: number;
|
||||
/** Makes a canvas, bound to the document the scene was built in. */
|
||||
makeCanvas: () => HTMLCanvasElement;
|
||||
/** The twinkling stars' own canvas, between the sky and the ridges; absent in a day sky and in 'still'. */
|
||||
/** The twinkling stars' own canvas, over the sky; absent in a day sky and in 'still'. */
|
||||
twinkle?: HTMLCanvasElement;
|
||||
/** The rain's tiles and their falling, present only when the weather rains (`rain.ts`). */
|
||||
rain?: { els: HTMLElement[]; anims: (Animation | undefined)[] };
|
||||
}
|
||||
|
||||
/** Yaw and pitch: the camera's slow sway, a loop of this many seconds over the whole rig. */
|
||||
const SWAY_SECONDS = 150;
|
||||
const SLICE_BUDGET_MS = 6;
|
||||
|
||||
/** The twinkle overlay redraws at most this often: the swings are 2 to 7 s, no need for 60 fps. */
|
||||
const TWINKLE_FRAME_MS = 50;
|
||||
|
||||
/**
|
||||
* The ridge scene: same contract as `createScene` ({ login, dispose }, null for "keep the CSS
|
||||
* ground"), no WebGL. The layers are painted once on the CPU; per frame the only work is the
|
||||
* browser compositor sliding each layer with a CSS transform (a Web Animation, no script). The host
|
||||
* canvas holds the baked sky; it and the layers' parent must be positioned, and the canvas should fill it.
|
||||
* ground"), no WebGL. It draws the sky, the stars and the rain, with no skyline. The host canvas holds the baked sky; it and
|
||||
* its parent must be positioned, and the canvas should fill the parent.
|
||||
*/
|
||||
export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
||||
const tier = opts.tier ?? 'full';
|
||||
|
|
@ -334,9 +113,6 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
let twRaf = 0;
|
||||
let twLast = 0;
|
||||
let still = tier === 'still';
|
||||
let jobTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let queue: Chunk[] = [];
|
||||
let generation = 0;
|
||||
let disposed = false;
|
||||
let raf = 0;
|
||||
let readout: HTMLElement | undefined;
|
||||
|
|
@ -349,14 +125,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
return { w, h, scale: (window.devicePixelRatio || 1) >= 2 ? 2 : 1 };
|
||||
};
|
||||
|
||||
const teardownLayers = () => {
|
||||
generation += 1;
|
||||
clearTimeout(jobTimer);
|
||||
jobTimer = undefined;
|
||||
queue = [];
|
||||
built?.sway?.cancel();
|
||||
built?.layers.forEach((l) => l.anim?.cancel());
|
||||
built?.rig.remove();
|
||||
const teardown = () => {
|
||||
built?.twinkle?.remove();
|
||||
built?.rain?.anims.forEach((a) => a?.cancel());
|
||||
built?.rain?.els.forEach((e) => e.remove());
|
||||
|
|
@ -368,111 +137,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
/** True while there is nothing to paint on: the canvas has no client size and the window itself is 0 x 0 (`viewSize` falls back to the window). */
|
||||
const hasNoArea = () => {
|
||||
const { w, h, scale } = viewSize();
|
||||
const size = layerSize(w, h, scale);
|
||||
return size.period < 1 || size.height < 1 || Math.round(h * scale) < 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Start baking chunk `c` of layer `l`. `first` runs it to the end in this task (the first view);
|
||||
* otherwise it joins the queue, which `pump` works through in short tasks. False when the canvas has no 2D context.
|
||||
*/
|
||||
const bake = (l: LayerState, c: Chunk, first: boolean): boolean => {
|
||||
if (!built) return false;
|
||||
const { scale, viewH, makeCanvas } = built;
|
||||
const job = chunkJob(
|
||||
c.el,
|
||||
makeCanvas,
|
||||
l.spec,
|
||||
sky,
|
||||
built.size,
|
||||
viewH,
|
||||
scale,
|
||||
c.id,
|
||||
(ms, maxTaskMs) => {
|
||||
c.ready = true;
|
||||
c.job = undefined;
|
||||
opts.onBake?.({ layer: l.spec.index, chunk: c.id, ms, maxTaskMs, first });
|
||||
}
|
||||
);
|
||||
if (!job) return false;
|
||||
c.ready = false;
|
||||
c.job = job;
|
||||
if (first) job.step(Infinity);
|
||||
else queue.push(c);
|
||||
return true;
|
||||
};
|
||||
|
||||
const pump = () => {
|
||||
if (jobTimer !== undefined || !queue.length) return;
|
||||
const gen = generation;
|
||||
jobTimer = setTimeout(() => {
|
||||
jobTimer = undefined;
|
||||
if (gen !== generation) return;
|
||||
const c = queue[0];
|
||||
if (!c.job || c.job.step(SLICE_BUDGET_MS)) queue.shift();
|
||||
pump();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/** Bake a still-queued chunk to the end now: only when the drift has caught up with the background work. */
|
||||
const flush = (c: Chunk) => {
|
||||
while (c.job && !c.job.step(Infinity));
|
||||
queue = queue.filter((q) => q !== c);
|
||||
};
|
||||
|
||||
const chunkSeconds = (spec: LayerSpec, size: Size) => (spec.seconds * size.chunk) / size.period;
|
||||
|
||||
/** One chunk of drift as one animation, holding its end until `rotate` hands the track the next chunk. */
|
||||
const startDrift = (l: LayerState, onEnd: (l: LayerState) => void) => {
|
||||
if (!built || !Number.isFinite(l.spec.seconds)) return; // the horizon layer does not drift
|
||||
const { size, scale } = built;
|
||||
l.anim = l.track.animate?.(
|
||||
[
|
||||
{ transform: 'translate3d(0,0,0)' },
|
||||
{ transform: `translate3d(${-size.chunk / scale}px,0,0)` },
|
||||
],
|
||||
{ duration: chunkSeconds(l.spec, size) * 1000, easing: 'linear', fill: 'forwards' }
|
||||
);
|
||||
if (l.anim) l.anim.onfinish = () => onEnd(l);
|
||||
};
|
||||
|
||||
/**
|
||||
* The window has drifted one chunk. Slot 1 is now slot 0 and slot 2 slot 1, at the same screen place
|
||||
* (the track restarts at 0 and the chunks move one slot left in the same task, so nothing jumps); the
|
||||
* canvas that left becomes slot 2 and is baked with the world one chunk further on, off the critical path.
|
||||
*/
|
||||
const rotate = (l: LayerState) => {
|
||||
if (!built || !built.layers.includes(l)) return;
|
||||
const [s0, s1, s2] = l.slots;
|
||||
flush(s1);
|
||||
flush(s2);
|
||||
l.slots = [s1, s2, s0];
|
||||
s0.id = s2.id + 1;
|
||||
const { size, scale } = built;
|
||||
l.slots.forEach((c, i) => {
|
||||
c.el.style.left = `${(i * size.chunk) / scale}px`;
|
||||
});
|
||||
l.anim?.cancel();
|
||||
startDrift(l, rotate);
|
||||
bake(l, s0, false);
|
||||
pump();
|
||||
syncPlayState();
|
||||
};
|
||||
|
||||
/** The camera's slow yaw and pitch: the rig eases sideways (up to 5% of the width) and down (up to 3% of the height) and back, in a loop. */
|
||||
const startSway = (rig: HTMLElement, w: number, h: number) => {
|
||||
const x = 0.05 * w;
|
||||
const y = 0.03 * h;
|
||||
const at = (fx: number, fy: number) => `translate3d(${-x * fx}px,${y * fy}px,0)`;
|
||||
return rig.animate?.(
|
||||
[
|
||||
{ transform: at(0, 0), offset: 0 },
|
||||
{ transform: at(0.55, 1), offset: 0.35 },
|
||||
{ transform: at(1, 0.3), offset: 0.7 },
|
||||
{ transform: at(0, 0), offset: 1 },
|
||||
],
|
||||
{ duration: SWAY_SECONDS * 1000, iterations: Infinity, easing: 'ease-in-out' }
|
||||
);
|
||||
return Math.round(w * scale) < 1 || Math.round(h * scale) < 1;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -525,14 +190,13 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
return { els, anims };
|
||||
};
|
||||
|
||||
/** Bake the sky, then the layers. Returns false when a 2D context is missing or there is no area yet. */
|
||||
/** Paint the sky, the stars and the rain. Returns false when a 2D context is missing or there is no area yet. */
|
||||
const build = (): boolean => {
|
||||
teardownLayers();
|
||||
teardown();
|
||||
// A zero-size canvas throws on drawImage; wait for the first resize that gives the host an area.
|
||||
if (hasNoArea()) return false;
|
||||
const { w, h, scale } = viewSize();
|
||||
const size = layerSize(w, h, scale);
|
||||
canvas.width = size.period;
|
||||
canvas.width = Math.round(w * scale);
|
||||
canvas.height = Math.round(h * scale);
|
||||
if (!paintSky(canvas, sky, w, h, () => document.createElement('canvas'))) return false;
|
||||
// Every star is baked into the sky; the twinkling ones get their own canvas, which a per-frame
|
||||
|
|
@ -557,75 +221,9 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
parent.appendChild(twinkle);
|
||||
}
|
||||
field = stars;
|
||||
// The rig carries the camera's sway; each layer's track carries its drift; chunks sit on the track.
|
||||
const rig = document.createElement('div');
|
||||
rig.setAttribute('aria-hidden', 'true');
|
||||
Object.assign(rig.style, {
|
||||
position: 'absolute',
|
||||
left: '0',
|
||||
bottom: '0',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
pointerEvents: 'none',
|
||||
willChange: 'transform',
|
||||
});
|
||||
const layers: LayerState[] = LAYERS.map((spec) => {
|
||||
const track = document.createElement('div');
|
||||
Object.assign(track.style, {
|
||||
position: 'absolute',
|
||||
left: spec.horizon ? `${(-HORIZON_TRACK_SHIFT * size.period) / scale}px` : '0',
|
||||
bottom: '0',
|
||||
width: `${size.period / scale}px`,
|
||||
height: `${size.height / scale}px`,
|
||||
willChange: 'transform',
|
||||
});
|
||||
const slots: Chunk[] = [0, 1, 2].map((i) => {
|
||||
const el = document.createElement('canvas');
|
||||
el.width = size.chunk;
|
||||
el.height = size.height;
|
||||
Object.assign(el.style, {
|
||||
position: 'absolute',
|
||||
bottom: '0',
|
||||
width: `${size.chunk / scale}px`,
|
||||
height: `${size.height / scale}px`,
|
||||
});
|
||||
return { el, id: i, ready: false };
|
||||
});
|
||||
return { spec, track, slots };
|
||||
});
|
||||
const doc = document;
|
||||
built = {
|
||||
rig,
|
||||
layers,
|
||||
size,
|
||||
scale,
|
||||
viewH: canvas.height,
|
||||
makeCanvas: () => doc.createElement('canvas'),
|
||||
twinkle,
|
||||
};
|
||||
// First view: only slot 0 of each layer, in this task. The window sees nothing else for the first
|
||||
// fifth of a chunk's drift; slots 1 and 2 are baked in short tasks behind it.
|
||||
if (!layers.every((l) => bake(l, l.slots[0], true))) {
|
||||
teardownLayers();
|
||||
return false;
|
||||
}
|
||||
layers.forEach((l) => {
|
||||
l.slots.forEach((c, i) => {
|
||||
c.el.setAttribute('aria-hidden', 'true');
|
||||
c.el.style.left = `${(i * size.chunk) / scale}px`;
|
||||
l.track.appendChild(c.el);
|
||||
});
|
||||
rig.appendChild(l.track);
|
||||
bake(l, l.slots[1], false);
|
||||
bake(l, l.slots[2], false);
|
||||
});
|
||||
// DOM order is paint order: farthest first, so the nearest ridge ends up on top.
|
||||
parent.appendChild(rig);
|
||||
layers.forEach((l) => startDrift(l, rotate));
|
||||
built.sway = startSway(rig, w, h);
|
||||
built = { twinkle };
|
||||
if (tier !== 'still' && sky.physical && sky.physical.weather.rain > 0)
|
||||
built.rain = startRain(sky.physical.weather.rain, sky.horizon, w, h, scale);
|
||||
pump();
|
||||
syncPlayState();
|
||||
return true;
|
||||
};
|
||||
|
|
@ -658,9 +256,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
};
|
||||
|
||||
function syncPlayState() {
|
||||
const anims = built
|
||||
? [built.sway, ...built.layers.map((l) => l.anim), ...(built.rain?.anims ?? [])]
|
||||
: [];
|
||||
const anims = built?.rain?.anims ?? [];
|
||||
anims.forEach((a) => (moving() ? a?.play() : a?.pause()));
|
||||
if (!built?.twinkle) return;
|
||||
if (moving()) {
|
||||
|
|
@ -672,24 +268,11 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
}
|
||||
}
|
||||
|
||||
/** Flatten the sky and layers into the host canvas and drop the layers: a still image, no compositor layers left. */
|
||||
/** Drop the twinkle and the rain, leaving the painted sky as a still image. */
|
||||
const settleToStill = () => {
|
||||
if (still && !built) return;
|
||||
still = true;
|
||||
const ctx = context2d(canvas);
|
||||
if (ctx && built) {
|
||||
const { size } = built;
|
||||
built.layers.forEach((l) => {
|
||||
// Freeze where the drift is, so the swap to a still does not jump; whatever is baked and in view.
|
||||
const dur = chunkSeconds(l.spec, size) * 1000;
|
||||
const p = Math.min(1, Math.max(0, Number(l.anim?.currentTime ?? 0) / dur));
|
||||
const x = -Math.round(p * size.chunk);
|
||||
l.slots.slice(0, 2).forEach((c, i) => {
|
||||
if (c.ready) ctx.drawImage(c.el, x + i * size.chunk, canvas.height - size.height);
|
||||
});
|
||||
});
|
||||
}
|
||||
teardownLayers();
|
||||
teardown();
|
||||
cancelAnimationFrame(raf);
|
||||
raf = 0;
|
||||
report(true);
|
||||
|
|
@ -773,7 +356,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
|
||||
return {
|
||||
login() {
|
||||
// No camera to pull back; the ridges are the same before and after.
|
||||
// No camera to pull back; the sky is the same before and after.
|
||||
},
|
||||
dispose() {
|
||||
if (disposed) return;
|
||||
|
|
@ -783,7 +366,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
document.removeEventListener('visibilitychange', onVisibility);
|
||||
window.removeEventListener('resize', onResize);
|
||||
reducedMotion?.removeEventListener?.('change', syncPlayState);
|
||||
teardownLayers();
|
||||
teardown();
|
||||
readout?.remove();
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { HORIZON_CREDIT, WEATHER_CREDIT, WEATHER_CREDIT_URL, WEATHER_DATASET } from './credits';
|
||||
import { HORIZON_ATTRIBUTION } from './horizon';
|
||||
import { WEATHER_CREDIT, WEATHER_CREDIT_URL, WEATHER_DATASET } from './credits';
|
||||
import { WEATHER_ATTRIBUTION } from './weatherFeed';
|
||||
|
||||
describe('the credits the Sky menu shows', () => {
|
||||
it("are the sources' own", () => {
|
||||
expect(HORIZON_CREDIT).toBe(HORIZON_ATTRIBUTION);
|
||||
expect(WEATHER_CREDIT).toBe(WEATHER_ATTRIBUTION);
|
||||
});
|
||||
it('credit GeoSphere with its requested line, and state a licence only with the dataset named', () => {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
// What the Ridge background owes its data sources, shown in the Sky menu (SkyStateControl). Plain strings in their own module so the
|
||||
// main chunk carries these and not the baked horizon table or the weather parser; credits.test.ts holds them equal to the sources'.
|
||||
// main chunk carries these and not the weather parser; credits.test.ts holds them equal to the sources'.
|
||||
|
||||
/** GeoSphere's own requested credit line. It names no licence: that is the dataset's (below). */
|
||||
export const WEATHER_CREDIT = 'Datenquelle: GeoSphere Austria - https://data.hub.geosphere.at';
|
||||
export const WEATHER_CREDIT_URL = 'https://data.hub.geosphere.at';
|
||||
/** The dataset the weather is read from, and its licence as the dataset page names it (data.hub.geosphere.at, tawes-v1-10min). */
|
||||
export const WEATHER_DATASET = 'TAWES weather stations, 10-minute data (station 11035), CC BY 4.0';
|
||||
/** The terrain silhouette's credit, as the Copernicus DEM licence asks (equal to `HORIZON_ATTRIBUTION`). */
|
||||
export const HORIZON_CREDIT =
|
||||
'Contains modified Copernicus data: DEM © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved.';
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import bake from './viennaHorizon.json';
|
||||
import { VIENNA } from './vienna';
|
||||
import { horizonDistanceKm, horizonElevation, horizonNormal } from './horizon';
|
||||
|
||||
describe('the baked horizon', () => {
|
||||
it('was baked from the viewpoint the sun is computed for', () => {
|
||||
expect(bake.viewpoint.lat).toBe(VIENNA.lat);
|
||||
expect(bake.viewpoint.lon).toBe(VIENNA.lon);
|
||||
expect(bake.viewpoint.groundM / 1000).toBeCloseTo(VIENNA.altitudeKm, 2);
|
||||
});
|
||||
it('carries its source and licence beside the data', () => {
|
||||
expect(bake.source.licence).toMatch(/attribution required/);
|
||||
expect(bake.source.attribution).toMatch(/COPERNICUS/);
|
||||
});
|
||||
it('is a closed ring of plausible angles: the Wienerwald NW, open Marchfeld E', () => {
|
||||
expect(bake.elevationDeg).toHaveLength(720);
|
||||
expect(horizonElevation(0)).toBeCloseTo(horizonElevation(360), 6);
|
||||
expect(horizonElevation(305)).toBeGreaterThan(horizonElevation(70));
|
||||
expect(Math.max(...bake.elevationDeg)).toBeLessThan(5);
|
||||
expect(horizonDistanceKm(305)).toBeGreaterThan(1);
|
||||
});
|
||||
it('interpolates between samples and returns unit normals', () => {
|
||||
expect(horizonElevation(100.25)).toBeCloseTo(
|
||||
(bake.elevationDeg[200] + bake.elevationDeg[201]) / 2,
|
||||
6
|
||||
);
|
||||
expect(Math.hypot(...horizonNormal(250))).toBeCloseTo(1, 6);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
// The terrain horizon seen from the viewpoint, baked from open DEM by `scripts/bake-horizon.py` (source, licence and attribution are
|
||||
// in the file's `source` block and in `HORIZON_ATTRIBUTION`).
|
||||
import bake from './viennaHorizon.json';
|
||||
|
||||
export const HORIZON_ATTRIBUTION = bake.source.attribution;
|
||||
|
||||
const N = bake.elevationDeg.length;
|
||||
|
||||
/** Index pair and weight of an azimuth (degrees clockwise from north) on the baked ring. */
|
||||
function at(azimuth: number): [number, number, number] {
|
||||
const f = (((azimuth / bake.stepDeg) % N) + N) % N;
|
||||
const i = Math.floor(f);
|
||||
return [i, (i + 1) % N, f - i];
|
||||
}
|
||||
|
||||
const lerp = (arr: readonly number[], az: number): number => {
|
||||
const [a, b, t] = at(az);
|
||||
return arr[a] * (1 - t) + arr[b] * t;
|
||||
};
|
||||
|
||||
/** Elevation of the horizon, degrees above the astronomical horizon, at an azimuth. */
|
||||
export const horizonElevation = (azimuth: number): number => lerp(bake.elevationDeg, azimuth);
|
||||
|
||||
/** Distance of the terrain that sets the horizon, km. */
|
||||
export const horizonDistanceKm = (azimuth: number): number => lerp(bake.distanceKm, azimuth);
|
||||
|
||||
/** Unit surface normal of the terrain at the horizon point: x east, y up, z north. */
|
||||
export function horizonNormal(azimuth: number): [number, number, number] {
|
||||
const e = lerp(bake.slopeEast, azimuth);
|
||||
const n = lerp(bake.slopeNorth, azimuth);
|
||||
const l = Math.hypot(e, 1, n);
|
||||
return [-e / l, 1 / l, -n / l];
|
||||
}
|
||||
|
||||
/** The elevations blurred over +-SMOOTH_DEG (a box, around the ring): at 30 m a city's roofs are the horizon's teeth, and a silhouette of them reads as a fence. */
|
||||
const SMOOTH_DEG = 1.5;
|
||||
const SMOOTH = Array.from({ length: N }, (_, i) => {
|
||||
const k = Math.round(SMOOTH_DEG / bake.stepDeg);
|
||||
let sum = 0;
|
||||
for (let d = -k; d <= k; d += 1) sum += bake.elevationDeg[(i + d + N) % N];
|
||||
return sum / (2 * k + 1);
|
||||
});
|
||||
const MIN_E = Math.min(...SMOOTH);
|
||||
const RANGE_E = Math.max(...SMOOTH) - MIN_E;
|
||||
|
||||
/** The horizon at an azimuth as 0..1 of the ring's own range (the lowest point of the horizon 0, the highest 1): the silhouette's shape, not its scale. */
|
||||
export const horizonShape = (azimuth: number): number => (lerp(SMOOTH, azimuth) - MIN_E) / RANGE_E;
|
||||
|
||||
/** Real range of the smoothed horizon, degrees: what `horizonShape` stretches to the layer's relief. */
|
||||
export const HORIZON_RANGE_DEG = RANGE_E;
|
||||
|
||||
/** Horizontal field of view, degrees, of a camera with the sky's vertical field (`skyDome.ts` VFOV_DEG) at an aspect ratio. */
|
||||
export const hfovDeg = (aspect: number, vfovDeg: number): number =>
|
||||
(2 * Math.atan(aspect * Math.tan((vfovDeg * Math.PI) / 360)) * 180) / Math.PI;
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { hfovDeg, horizonShape } from './horizon';
|
||||
import { HORIZON_TRACK_SHIFT, LAYERS, layerProfile, profile } from './ridgeWorld';
|
||||
import { layerPaint } from './ridgeBake';
|
||||
import { weatherOf } from './weather';
|
||||
import { skyColours } from './skyColour';
|
||||
import { makePhysicalSky } from './physicalSky';
|
||||
import { VFOV_DEG } from './skyDome';
|
||||
|
||||
describe('the horizon layer', () => {
|
||||
const far = LAYERS[0];
|
||||
const view = { azimuthDeg: 200, hfovDeg: hfovDeg(16 / 9, VFOV_DEG) };
|
||||
|
||||
it('is the farthest layer, real and standing still', () => {
|
||||
expect(far.horizon).toBe(true);
|
||||
expect(Number.isFinite(far.seconds)).toBe(false);
|
||||
expect(LAYERS.slice(1).every((l) => !l.horizon && Number.isFinite(l.seconds))).toBe(true);
|
||||
});
|
||||
|
||||
it('reads world-x as azimuth across the viewport: the left edge is half the field to the left of the view, the right edge half to the right', () => {
|
||||
const left = layerProfile(far, HORIZON_TRACK_SHIFT, view);
|
||||
const right = layerProfile(far, HORIZON_TRACK_SHIFT + 1, view);
|
||||
expect(left).toBeCloseTo(horizonShape(200 - view.hfovDeg / 2), 9);
|
||||
expect(right).toBeCloseTo(horizonShape(200 + view.hfovDeg / 2), 9);
|
||||
});
|
||||
|
||||
it('stays in 0..1 and covers a real range of shape, not a line', () => {
|
||||
const v = Array.from({ length: 200 }, (_, i) =>
|
||||
layerProfile(far, -0.06 + (i / 200) * 1.2, { azimuthDeg: 305, hfovDeg: view.hfovDeg })
|
||||
);
|
||||
expect(Math.min(...v)).toBeGreaterThanOrEqual(0);
|
||||
expect(Math.max(...v)).toBeLessThanOrEqual(1);
|
||||
expect(Math.max(...v) - Math.min(...v)).toBeGreaterThan(0.2);
|
||||
});
|
||||
|
||||
it('is the noise profile for the other layers, and for the horizon layer when no view is known', () => {
|
||||
expect(layerProfile(LAYERS[2], 0.4, view)).toBe(profile(LAYERS[2], 0.4));
|
||||
expect(layerProfile(far, 0.4)).toBe(profile(far, 0.4));
|
||||
});
|
||||
|
||||
it('the horizontal field of a 1:1 view is the vertical one, and grows with the aspect', () => {
|
||||
expect(hfovDeg(1, VFOV_DEG)).toBeCloseTo(VFOV_DEG, 9);
|
||||
expect(hfovDeg(16 / 9, VFOV_DEG)).toBeGreaterThan(VFOV_DEG);
|
||||
});
|
||||
});
|
||||
|
||||
describe('weather in the layers', () => {
|
||||
it("mist multiplies the layers' own, and clear air leaves it alone", () => {
|
||||
const base = skyColours();
|
||||
const day = new Date('2026-06-21T10:40:00Z');
|
||||
const clear = layerPaint(LAYERS[1], { ...base, physical: makePhysicalSky('day', day, 0) });
|
||||
const misty = layerPaint(LAYERS[1], { ...base, physical: makePhysicalSky('day', day, 0.8) });
|
||||
expect(clear.mistK).toBe(1);
|
||||
expect(misty.mistK).toBeGreaterThan(2);
|
||||
expect(layerPaint(LAYERS[1], base).mistK).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the weather number', () => {
|
||||
it('a number that is not finite is a clear sky, not an error', () => {
|
||||
expect(weatherOf(Number.NaN).value).toBe(0);
|
||||
expect(weatherOf(Infinity).value).toBe(0);
|
||||
expect(weatherOf(0.5).value).toBe(0.5);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,404 +0,0 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { BakeParams, bakeSlice, faceLight, layerPaint, sunDirection } from './ridgeBake';
|
||||
import { SKY_BAND } from '../skyBand';
|
||||
import { ridgeSkyFor } from '../skyForState';
|
||||
import { LACUNARITY, LAYERS, profile } from './ridgeWorld';
|
||||
import { skyColours, SkyColours } from './skyColour';
|
||||
|
||||
const SKY: SkyColours = { ...skyColours(), sunAzimuth: 0.3 }; // sun toward +x
|
||||
const PERIOD = 400;
|
||||
const VIEW_H = 800;
|
||||
const BAND = 480;
|
||||
|
||||
const params = (
|
||||
li: number,
|
||||
px0: number,
|
||||
cols: number,
|
||||
over: Partial<BakeParams> = {}
|
||||
): BakeParams => ({
|
||||
spec: LAYERS[li],
|
||||
sky: SKY,
|
||||
period: PERIOD,
|
||||
scale: 1,
|
||||
viewH: VIEW_H,
|
||||
rows: BAND,
|
||||
bandH: BAND,
|
||||
px0,
|
||||
cols,
|
||||
...over,
|
||||
});
|
||||
|
||||
function bake(p: BakeParams, slices: number[] = [p.cols]): Uint8ClampedArray {
|
||||
const out = new Uint8ClampedArray(p.cols * p.rows * 4);
|
||||
const paint = layerPaint(p.spec, p.sky);
|
||||
let c = 0;
|
||||
for (const n of slices) {
|
||||
bakeSlice(out, p, paint, c, Math.min(p.cols, c + n));
|
||||
c += n;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const lum = (d: Uint8ClampedArray, cols: number, x: number, y: number) => {
|
||||
const o = (y * cols + x) * 4;
|
||||
return 0.2126 * d[o] + 0.7152 * d[o + 1] + 0.0722 * d[o + 2];
|
||||
};
|
||||
/** First row of column x whose alpha is full. */
|
||||
const solidRow = (d: Uint8ClampedArray, cols: number, x: number) => {
|
||||
let y = 0;
|
||||
while (y < BAND && d[(y * cols + x) * 4 + 3] < 255) y += 1;
|
||||
return y;
|
||||
};
|
||||
|
||||
describe('the field is a function of world-x', () => {
|
||||
it('is deterministic, and defined and bounded at any world-x', () => {
|
||||
for (const spec of LAYERS) {
|
||||
for (const t of [-40.3, 0, 0.5, 17.77, 5000.123]) {
|
||||
expect(profile(spec, t)).toBe(profile(spec, t));
|
||||
expect(profile(spec, t)).toBeGreaterThanOrEqual(0);
|
||||
expect(profile(spec, t)).toBeLessThanOrEqual(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('has no repeat at the old period (1 viewport) or its multiples: the profile differs from itself shifted', () => {
|
||||
for (const spec of LAYERS) {
|
||||
for (const lag of [1, 2, 3, 0.5]) {
|
||||
let diff = 0;
|
||||
for (let i = 0; i < 400; i += 1)
|
||||
diff += Math.abs(profile(spec, i / 100) - profile(spec, i / 100 + lag));
|
||||
expect(diff / 400).toBeGreaterThan(0.04);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('the same world column bakes to the same pixels whichever chunk or slice paints it', () => {
|
||||
for (const li of [0, 3]) {
|
||||
const whole = bake(params(li, 1000, 200));
|
||||
const sliced = bake(params(li, 1000, 200), [37, 64, 1000]);
|
||||
expect(Array.from(sliced)).toEqual(Array.from(whole));
|
||||
// A chunk starting 120 columns later sees the same pixels for the columns it shares.
|
||||
const shifted = bake(params(li, 1120, 80));
|
||||
for (const x of [0, 17, 79]) {
|
||||
for (const y of [0, 100, 300, BAND - 1]) {
|
||||
const a = (y * 200 + 120 + x) * 4;
|
||||
const b = (y * 80 + x) * 4;
|
||||
expect(Array.from(shifted.slice(b, b + 4))).toEqual(Array.from(whole.slice(a, a + 4)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('is continuous across a chunk seam: the crest steps no more at the seam than elsewhere', () => {
|
||||
const chunk = Math.round(PERIOD * 1.2);
|
||||
for (const li of [0, 1, 2, 3]) {
|
||||
const p = params(li, chunk - 40, 80);
|
||||
const d = bake(p);
|
||||
let worst = 0;
|
||||
for (let x = 1; x < 80; x += 1)
|
||||
worst = Math.max(worst, Math.abs(solidRow(d, 80, x) - solidRow(d, 80, x - 1)));
|
||||
const seam = Math.abs(solidRow(d, 80, 40) - solidRow(d, 80, 39));
|
||||
expect(seam).toBeLessThanOrEqual(Math.max(worst, 1));
|
||||
// and the seam columns equal a chunk baked from the other side
|
||||
const other = bake(params(li, chunk - 40, 80, { cols: 80 }));
|
||||
expect(Array.from(other)).toEqual(Array.from(d));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('shading from the slope normal', () => {
|
||||
const sun = sunDirection(SKY);
|
||||
|
||||
it('the sun is toward +x for azimuth 0.3', () => {
|
||||
expect(sun[0]).toBeGreaterThan(0.5);
|
||||
});
|
||||
|
||||
it('a face looking at the sun is lit more than one looking away', () => {
|
||||
// slope < 0: the crest falls toward +x, so the face looks at +x, at the sun.
|
||||
for (const s of [0.2, 0.6, 1.5]) expect(faceLight(-s, sun)).toBeGreaterThan(faceLight(s, sun));
|
||||
expect(faceLight(1.5, sun)).toBeLessThan(0.2);
|
||||
expect(faceLight(-1.5, sun)).toBeGreaterThan(0.6);
|
||||
});
|
||||
|
||||
it('in the baked pixels the lit side is brighter than the shadow side', () => {
|
||||
for (const li of [0, 1, 2]) {
|
||||
const cols = 900;
|
||||
const p = params(li, 0, cols);
|
||||
const d = bake(p);
|
||||
const slope = (x: number) => (solidRow(d, cols, x - 1) - solidRow(d, cols, x + 1)) / 2; // rows up per column
|
||||
const litX: number[] = [];
|
||||
const shadeX: number[] = [];
|
||||
for (let x = 2; x < cols - 2; x += 1) {
|
||||
if (slope(x) < -0.8) litX.push(x);
|
||||
if (slope(x) > 0.8) shadeX.push(x);
|
||||
}
|
||||
expect(litX.length).toBeGreaterThan(5);
|
||||
expect(shadeX.length).toBeGreaterThan(5);
|
||||
const mean = (xs: number[]) =>
|
||||
xs.reduce((a, x) => a + lum(d, cols, x, solidRow(d, cols, x) + 12), 0) / xs.length;
|
||||
expect(mean(litX)).toBeGreaterThan(mean(shadeX));
|
||||
}
|
||||
});
|
||||
|
||||
it('a lit crest rim: the crest pixels are brighter than the face a little below, on both sides', () => {
|
||||
for (const li of [0, 1, 2, 3]) {
|
||||
const cols = 600;
|
||||
const d = bake(params(li, 300, cols));
|
||||
let rimmed = 0;
|
||||
let n = 0;
|
||||
for (let x = 3; x < cols - 3; x += 1) {
|
||||
const y = solidRow(d, cols, x);
|
||||
if (y + 40 >= BAND) continue;
|
||||
n += 1;
|
||||
if (lum(d, cols, x, y + 1) > lum(d, cols, x, y + 30)) rimmed += 1;
|
||||
}
|
||||
expect(n).toBeGreaterThan(100);
|
||||
expect(rimmed / n).toBeGreaterThan(0.8);
|
||||
}
|
||||
});
|
||||
|
||||
it('the foot of the face is clearly darker than its top, on every layer: volume from the depth below the crest', () => {
|
||||
// Without the depth shading the bottom row is 0.93 to 0.98 of the luminance 12 rows under the crest; with it, 0.73 to 0.82.
|
||||
for (const li of [0, 1, 2, 3]) {
|
||||
const cols = 900;
|
||||
const d = bake(params(li, 0, cols, { spec: { ...LAYERS[li], mist: 0, gully: 0 } }));
|
||||
let ratio = 0;
|
||||
let n = 0;
|
||||
for (let x = 0; x < cols; x += 1) {
|
||||
const y = solidRow(d, cols, x);
|
||||
if (y + 90 >= BAND) continue;
|
||||
n += 1;
|
||||
ratio += lum(d, cols, x, BAND - 1) / Math.max(1, lum(d, cols, x, y + 12));
|
||||
}
|
||||
expect(n).toBeGreaterThan(30);
|
||||
expect(ratio / n).toBeLessThan(0.88);
|
||||
}
|
||||
});
|
||||
|
||||
it('the valley mist still pulls the foot toward the haze colour', () => {
|
||||
const cols = 300;
|
||||
const p = params(0, 0, cols);
|
||||
const misty = bake(p);
|
||||
const clear = bake(params(0, 0, cols, { spec: { ...LAYERS[0], mist: 0 } }));
|
||||
const haze = layerPaint(p.spec, p.sky).haze;
|
||||
const dist = (d: Uint8ClampedArray, x: number, y: number) => {
|
||||
const o = (y * cols + x) * 4;
|
||||
return Math.hypot(d[o] - haze[0], d[o + 1] - haze[1], d[o + 2] - haze[2]);
|
||||
};
|
||||
let nearer = 0;
|
||||
let n = 0;
|
||||
for (let x = 0; x < cols; x += 1) {
|
||||
const y = solidRow(misty, cols, x);
|
||||
if (y + 200 >= BAND) continue;
|
||||
n += 1;
|
||||
if (dist(misty, x, y + 200) < dist(clear, x, y + 200)) nearer += 1;
|
||||
}
|
||||
expect(n).toBeGreaterThan(50);
|
||||
expect(nearer / n).toBeGreaterThan(0.9);
|
||||
});
|
||||
|
||||
it('erosion streaks run down the face: brightness varies across columns at one depth, and not without them', () => {
|
||||
const cols = 500;
|
||||
const spread = (gully: number) => {
|
||||
const d = bake(params(2, 0, cols, { spec: { ...LAYERS[2], gully } }));
|
||||
// The same depth below the crest in every column, in the lit-independent part (gullies darken, lit is column-wise).
|
||||
const v: number[] = [];
|
||||
for (let x = 0; x < cols; x += 1) {
|
||||
const y = solidRow(d, cols, x);
|
||||
if (y + 90 < BAND) v.push(lum(d, cols, x, y + 80) / Math.max(1, lum(d, cols, x, y + 8)));
|
||||
}
|
||||
const m = v.reduce((a, b) => a + b, 0) / v.length;
|
||||
return v.reduce((a, b) => a + (b - m) ** 2, 0) / v.length;
|
||||
};
|
||||
expect(spread(LAYERS[2].gully)).toBeGreaterThan(spread(0) * 1.2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bake cost', () => {
|
||||
it('is recorded, not asserted: one chunk of every layer at 1280 x 720', () => {
|
||||
const period = 1280;
|
||||
const rows = Math.round(720 * 0.6);
|
||||
const ms = LAYERS.map((spec) => {
|
||||
const p: BakeParams = {
|
||||
spec,
|
||||
sky: SKY,
|
||||
period,
|
||||
scale: 1,
|
||||
viewH: 720,
|
||||
rows,
|
||||
bandH: rows,
|
||||
px0: 0,
|
||||
cols: Math.round(period * 1.2),
|
||||
};
|
||||
const t0 = performance.now();
|
||||
bake(p);
|
||||
return performance.now() - t0;
|
||||
});
|
||||
expect(ms.every((v) => Number.isFinite(v) && v >= 0)).toBe(true);
|
||||
console.info(
|
||||
`ridge bake ms per layer (node, 1 chunk, 1280x720): ${ms.map((v) => v.toFixed(1)).join(' ')}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the ridged multifractal core, each rule on its own', () => {
|
||||
const one = { ...LAYERS[0], octaves: 1, warp: 0, crag: 1 };
|
||||
|
||||
it('folds each octave at its crest: a creased, sharp ridge line, not a smooth swell', () => {
|
||||
// Largest second difference over a fine scan. A smooth curve of this size stays in the hundreds;
|
||||
// a fold leaves a crease where the noise crosses its midpoint.
|
||||
const h = 1e-3;
|
||||
let worst = 0;
|
||||
for (let i = 1; i < 20000; i += 1) {
|
||||
const t = i * h;
|
||||
worst = Math.max(
|
||||
worst,
|
||||
Math.abs(profile(one, t + h) - 2 * profile(one, t) + profile(one, t - h)) / (h * h)
|
||||
);
|
||||
}
|
||||
expect(worst).toBeGreaterThan(2000);
|
||||
});
|
||||
|
||||
it('domain-warps: the same layer without its warp is a measurably different line', () => {
|
||||
const spec = LAYERS[1];
|
||||
let diff = 0;
|
||||
for (let i = 0; i < 2000; i += 1)
|
||||
diff += Math.abs(profile(spec, i / 100) - profile({ ...spec, warp: 0 }, i / 100));
|
||||
expect(diff / 2000).toBeGreaterThan(0.02);
|
||||
});
|
||||
|
||||
it('weights each octave by the previous one: where the first octave is low, the later ones add almost nothing', () => {
|
||||
const lo = { ...LAYERS[1], octaves: 1, warp: 0 };
|
||||
const hi = { ...LAYERS[1], octaves: 5, warp: 0 };
|
||||
let valley = 0;
|
||||
let nv = 0;
|
||||
let peak = 0;
|
||||
let np = 0;
|
||||
for (let i = 0; i < 10000; i += 1) {
|
||||
const a = profile(lo, i / 500);
|
||||
const d = Math.abs(profile(hi, i / 500) - a);
|
||||
if (a < 0.12) {
|
||||
valley += d;
|
||||
nv += 1;
|
||||
} else if (a > 0.35) {
|
||||
peak += d;
|
||||
np += 1;
|
||||
}
|
||||
}
|
||||
expect(nv).toBeGreaterThan(200);
|
||||
expect(np).toBeGreaterThan(200);
|
||||
expect(valley / nv).toBeLessThan(0.25 * (peak / np));
|
||||
});
|
||||
|
||||
it('octave lattices do not line up: the lacunarity is not a power of two', () => {
|
||||
expect(Number.isInteger(Math.log2(LACUNARITY))).toBe(false);
|
||||
expect(Number.isInteger(LACUNARITY)).toBe(false);
|
||||
});
|
||||
|
||||
it('distance flattens relief: contrast falls from the nearest layer to the farthest', () => {
|
||||
const c = LAYERS.map((spec) => layerPaint(spec, SKY).contrast);
|
||||
expect(c[LAYERS.length - 1]).toBe(1);
|
||||
for (let i = 1; i < c.length; i += 1) expect(c[i]).toBeGreaterThan(c[i - 1]);
|
||||
// and it shows in the pixels: the lit/shadow difference is smaller on the farthest layer than the nearest
|
||||
const gap = (li: number) => {
|
||||
const cols = 700;
|
||||
const d = bake(params(li, 0, cols));
|
||||
const slope = (x: number) => (solidRow(d, cols, x - 1) - solidRow(d, cols, x + 1)) / 2;
|
||||
const avg = (pick: (s: number) => boolean) => {
|
||||
const xs = Array.from({ length: cols - 4 }, (_, k) => k + 2).filter((x) => pick(slope(x)));
|
||||
return (
|
||||
xs.reduce((a, x) => a + lum(d, cols, x, solidRow(d, cols, x) + 12), 0) /
|
||||
Math.max(1, xs.length)
|
||||
);
|
||||
};
|
||||
return (
|
||||
Math.abs(avg((s) => s < -0.8) - avg((s) => s > 0.8)) /
|
||||
Math.max(
|
||||
1,
|
||||
avg(() => true)
|
||||
)
|
||||
);
|
||||
};
|
||||
expect(gap(0)).toBeLessThan(gap(3));
|
||||
});
|
||||
});
|
||||
|
||||
describe('the state band: the theme ink clears 4.5:1 on a ridge as on bare sky', () => {
|
||||
const linear = (v: number) => {
|
||||
const c = v / 255;
|
||||
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
||||
};
|
||||
const luma = (d: Uint8ClampedArray, o: number) =>
|
||||
0.2126 * linear(d[o]) + 0.7152 * linear(d[o + 1]) + 0.0722 * linear(d[o + 2]);
|
||||
/** Lowest and highest luminance over the solid pixels of every layer. */
|
||||
const range = (band: typeof SKY_BAND[keyof typeof SKY_BAND] | undefined) => {
|
||||
let lo = 1;
|
||||
let hi = 0;
|
||||
for (const li of [0, 1, 2, 3]) {
|
||||
const p = params(li, 0, 700, { sky: { ...SKY, band } });
|
||||
const d = bake(p);
|
||||
for (let o = 0; o < d.length; o += 4) {
|
||||
if (d[o + 3] < 255) continue;
|
||||
const l = luma(d, o);
|
||||
lo = Math.min(lo, l);
|
||||
hi = Math.max(hi, l);
|
||||
}
|
||||
}
|
||||
return { lo, hi };
|
||||
};
|
||||
|
||||
it("day and dusk: no ridge pixel is darker than the text floor (Day's), on every layer", () => {
|
||||
for (const band of [SKY_BAND.day, SKY_BAND.dusk]) {
|
||||
expect(range(band).lo).toBeGreaterThanOrEqual(SKY_BAND.day.floor);
|
||||
}
|
||||
});
|
||||
|
||||
it('night: no ridge pixel is lighter than the ceiling', () => {
|
||||
expect(range(SKY_BAND.night).hi).toBeLessThanOrEqual(SKY_BAND.night.ceiling);
|
||||
});
|
||||
|
||||
it('is the identity with no band, so nothing else changes', () => {
|
||||
expect(layerPaint(LAYERS[2], SKY).shift).toBeNull();
|
||||
expect(range(undefined).lo).toBeLessThan(SKY_BAND.day.floor);
|
||||
});
|
||||
|
||||
it('keeps the shading: the foot is still darker than the top inside the band', () => {
|
||||
// Inside the band the face's range is compressed, not removed: dusk, no mist or gullies, bottom row over 12 rows under the crest.
|
||||
const sky = { ...SKY, band: SKY_BAND.dusk };
|
||||
for (const li of [0, 1, 2, 3]) {
|
||||
const cols = 900;
|
||||
const d = bake(params(li, 0, cols, { sky, spec: { ...LAYERS[li], mist: 0, gully: 0 } }));
|
||||
let ratio = 0;
|
||||
let n = 0;
|
||||
for (let x = 0; x < cols; x += 1) {
|
||||
const y = solidRow(d, cols, x);
|
||||
if (y + 90 >= BAND) continue;
|
||||
n += 1;
|
||||
ratio += luma(d, ((BAND - 1) * cols + x) * 4) / luma(d, ((y + 12) * cols + x) * 4);
|
||||
}
|
||||
expect(n).toBeGreaterThan(30);
|
||||
// Measured 0.84, 0.85, 0.91, 0.97 far to near: the nearest ground is near black, so its range is small in absolute terms.
|
||||
expect(ratio / n).toBeLessThan(li < 3 ? 0.95 : 1);
|
||||
}
|
||||
});
|
||||
|
||||
it('the real states, over a sweep of the sun: no pixel overflows the encoding (an overflow reads as a stray black or yellow channel)', () => {
|
||||
for (const state of ['day', 'dusk', 'night'] as const) {
|
||||
for (const sunAzimuth of [0, 0.1, 0.25, 0.3, 0.5, 0.75, 0.9]) {
|
||||
const sky = { ...ridgeSkyFor(state), sunAzimuth };
|
||||
for (const li of [0, 1, 2, 3]) {
|
||||
const d = bake(params(li, 1000, 400, { sky }));
|
||||
let stray = 0;
|
||||
for (let o = 0; o < d.length; o += 4) {
|
||||
if (d[o + 3] < 255) continue;
|
||||
// A channel far below both others is the signature of a lookup that read past its table.
|
||||
const lo = Math.min(d[o], d[o + 1], d[o + 2]);
|
||||
const mid = d[o] + d[o + 1] + d[o + 2] - lo - Math.max(d[o], d[o + 1], d[o + 2]);
|
||||
if (mid - lo > 120) stray += 1;
|
||||
}
|
||||
expect(stray).toBe(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -1,221 +0,0 @@
|
|||
/* eslint-disable no-param-reassign -- `bakeSlice` fills the caller's pixel buffer */
|
||||
// The pixels of a ridge chunk, as a pure function: no DOM, no canvas. Each column is lit from the
|
||||
// slope of the heightfield's crest line against the sun; the face under it takes a light-to-haze
|
||||
// gradient, erosion streaks and a lit rim on the crest. The depth treatment (colour, haze, contrast
|
||||
// by distance) is ridgeWorld's `layerColour`, `hazeColour` and `transmittance`, used here and not redone.
|
||||
import {
|
||||
gullyAt,
|
||||
HorizonView,
|
||||
LayerSpec,
|
||||
layerProfile,
|
||||
hazeColour,
|
||||
layerColour,
|
||||
transmittance,
|
||||
} from './ridgeWorld';
|
||||
import type { SkyBand } from '../skyBand';
|
||||
import { LUMA, SKY_BAND } from '../skyBand';
|
||||
import type { SkyColours, Srgb } from './skyColour';
|
||||
|
||||
export type Vec3 = readonly [number, number, number];
|
||||
|
||||
/** Unit vector toward the sun: x across the screen (from the azimuth), y up, z toward the viewer. */
|
||||
export function sunDirection(sky: SkyColours): Vec3 {
|
||||
const az = sky.sunAzimuth ?? 0.3;
|
||||
const x = 0.9 * Math.sin(2 * Math.PI * az);
|
||||
const l = Math.hypot(x, 0.35, 0.45);
|
||||
return [x / l, 0.35 / l, 0.45 / l];
|
||||
}
|
||||
|
||||
/** How steeply the crest's slope tilts the face's normal sideways. */
|
||||
const TILT = 1.2;
|
||||
|
||||
/**
|
||||
* Sun light on the face under a crest whose silhouette has `slope` (rows per column, positive when the
|
||||
* crest rises toward +x, so the face looks toward -x). 0 in full shadow .. 1 head-on to the sun.
|
||||
*/
|
||||
export function faceLight(slope: number, sun: Vec3): number {
|
||||
const nx = -slope * TILT;
|
||||
const inv = 1 / Math.hypot(nx, 0.55, 0.85);
|
||||
const d = (nx * sun[0] + 0.55 * sun[1] + 0.85 * sun[2]) * inv;
|
||||
return Math.min(1, Math.max(0, (d - 0.2) / 0.7));
|
||||
}
|
||||
|
||||
export interface BakeParams {
|
||||
spec: LayerSpec;
|
||||
sky: SkyColours;
|
||||
/** Pixels in one viewport width: the unit of world-x. */
|
||||
period: number;
|
||||
/** CSS px to canvas px. */
|
||||
scale: number;
|
||||
/** Viewport height in canvas px. */
|
||||
viewH: number;
|
||||
/** Rows of the pixel buffer (the band plus any padding below it). */
|
||||
rows: number;
|
||||
/** Row count of the visible band; the crest is measured from the top of it. */
|
||||
bandH: number;
|
||||
/** Where world-x is a compass azimuth, for the horizon layer (`LayerSpec.horizon`); absent: every layer is noise. */
|
||||
horizonView?: HorizonView;
|
||||
/** World pixel of the buffer's column 0 (may be fractional-free negative: a chunk's left minus its padding). */
|
||||
px0: number;
|
||||
/** Columns of the buffer. */
|
||||
cols: number;
|
||||
}
|
||||
|
||||
const clamp01 = (v: number): number => Math.min(1, Math.max(0, v));
|
||||
const smoothstep = (a: number, b: number, v: number): number => {
|
||||
const t = clamp01((v - a) / (b - a));
|
||||
return t * t * (3 - 2 * t);
|
||||
};
|
||||
const SUN_WHITE: Srgb = [255, 238, 205];
|
||||
|
||||
/** Everything `bakeSlice` needs per layer, computed once. */
|
||||
export interface LayerPaint {
|
||||
/** The state's band as a shift of linear light (raises the floor, lowers the ceiling); null when the sky has none. */
|
||||
shift: BandShift | null;
|
||||
base: Srgb;
|
||||
haze: Srgb;
|
||||
warm: Srgb;
|
||||
contrast: number;
|
||||
sun: Vec3;
|
||||
/** How much the weather's mist multiplies the layer's own (`weather.ts`): 1 in clear air. */
|
||||
mistK: number;
|
||||
}
|
||||
|
||||
const decode = (v: number): number => {
|
||||
const s = v / 255;
|
||||
return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
||||
};
|
||||
const DECODE = Float32Array.from({ length: 256 }, (_, v) => decode(v));
|
||||
const ENCODE_STEPS = 4095;
|
||||
const ENCODE = Uint8ClampedArray.from({ length: ENCODE_STEPS + 1 }, (_, i) => {
|
||||
const l = i / ENCODE_STEPS;
|
||||
return 255 * (l <= 0.0031308 ? 12.92 * l : 1.055 * l ** (1 / 2.4) - 0.055);
|
||||
});
|
||||
/** What the band is held clear of at its edges: the 8-bit rounding and the blur and in-scatter the chunk takes after the bake. */
|
||||
const BAND_MARGIN = 0.012;
|
||||
|
||||
/** Linear light out = in * `scale` + `add[channel]`. */
|
||||
export interface BandShift {
|
||||
add: readonly [number, number, number];
|
||||
scale: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The state's band (skyBand.ts) as a shift of linear light, solved once per layer. Adding `add` (the zenith colour, so
|
||||
* the ridge reads as shadowed by the sky above, a hue apart from the horizon behind it) raises every pixel's
|
||||
* luminance by exactly the floor, so the face keeps its whole gradient and the darkest pixel is on the floor; scaling by
|
||||
* `scale` puts the lightest pixel on the ceiling. Smooth in the pixel's own luminance: no cut and no region.
|
||||
* The floor is the text bound (Day's), not Dusk's higher link bound: the link ink is not set on ridges, and Dusk's
|
||||
* floor washes the faces to a flat pale slab.
|
||||
*/
|
||||
export function bandShift(band: SkyBand | undefined, lift: Srgb): BandShift | null {
|
||||
if (!band) return null;
|
||||
const floor = Math.min(band.floor, SKY_BAND.day.floor);
|
||||
const scale = band.ceiling < 1 ? band.ceiling - BAND_MARGIN / 3 : 1;
|
||||
if (floor <= 0 && scale === 1) return null;
|
||||
const lin = lift.map(decode);
|
||||
const k =
|
||||
floor > 0
|
||||
? (floor + BAND_MARGIN) / (LUMA[0] * lin[0] + LUMA[1] * lin[1] + LUMA[2] * lin[2])
|
||||
: 0;
|
||||
return { add: [lin[0] * k, lin[1] * k, lin[2] * k], scale };
|
||||
}
|
||||
|
||||
export function layerPaint(spec: LayerSpec, sky: SkyColours): LayerPaint {
|
||||
const warm: Srgb = [
|
||||
(sky.horizon[0] + SUN_WHITE[0]) / 2,
|
||||
(sky.horizon[1] + SUN_WHITE[1]) / 2,
|
||||
(sky.horizon[2] + SUN_WHITE[2]) / 2,
|
||||
];
|
||||
return {
|
||||
shift: bandShift(sky.band, sky.top),
|
||||
base: layerColour(spec, sky),
|
||||
haze: hazeColour(sky),
|
||||
warm,
|
||||
// Distance flattens relief: the same transmittance that thins the colour.
|
||||
contrast: 0.35 + 0.65 * transmittance(spec),
|
||||
sun: sunDirection(sky),
|
||||
mistK: 1 + 2.5 * (sky.physical?.weather.mist ?? 0),
|
||||
};
|
||||
}
|
||||
|
||||
/** Crest row (float, from the top of the band) of every buffer column from c0 - 1 to c1 (inclusive). */
|
||||
function crestRows(p: BakeParams, c0: number, c1: number): Float64Array {
|
||||
const out = new Float64Array(c1 - c0 + 2);
|
||||
const amp = p.spec.relief * p.viewH;
|
||||
const lift = p.spec.base * p.viewH;
|
||||
for (let c = c0 - 1; c <= c1; c += 1) {
|
||||
const top = Math.min(
|
||||
p.bandH,
|
||||
lift + amp * layerProfile(p.spec, (p.px0 + c) / p.period, p.horizonView)
|
||||
);
|
||||
out[c - c0 + 1] = p.bandH - top;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint columns [c0, c1) of the chunk into `out` (RGBA, `p.cols` wide, `p.rows` tall, zeroed). One
|
||||
* call is a slice of a chunk, so a caller can keep each task short. Seams are exact: a column's pixels
|
||||
* depend only on its world pixel, never on where the slice or chunk begins.
|
||||
*/
|
||||
export function bakeSlice(
|
||||
out: Uint8ClampedArray,
|
||||
p: BakeParams,
|
||||
paint: LayerPaint,
|
||||
c0: number,
|
||||
c1: number
|
||||
): void {
|
||||
const { spec } = p;
|
||||
const crest = crestRows(p, c0, c1);
|
||||
const faceH = 0.45 * p.viewH;
|
||||
const rim = 2.2 * p.scale;
|
||||
const glow = 9 * p.scale;
|
||||
const { base, haze, warm, contrast, sun, shift, mistK } = paint;
|
||||
for (let c = c0; c < c1; c += 1) {
|
||||
const cy = crest[c - c0 + 1];
|
||||
const slope = (crest[c - c0 + 2] - crest[c - c0]) * -0.5; // rows up per column
|
||||
const lit = faceLight(slope, sun);
|
||||
const steep = 0.45 + 0.55 * clamp01(Math.abs(slope) * 0.8);
|
||||
const gl = gullyAt(spec, (p.px0 + c) / p.scale) * steep;
|
||||
const y0 = Math.max(0, Math.floor(cy));
|
||||
for (let y = y0; y < p.rows; y += 1) {
|
||||
const d = y + 0.5 - cy;
|
||||
const dn = clamp01(d / faceH);
|
||||
const cover = clamp01(y + 1 - cy);
|
||||
const gully = spec.gully * gl * smoothstep(0, 0.2, dn);
|
||||
// Shade the ground colour by the sun; the lit warm light fades down the face and in the gullies.
|
||||
// Volume from the depth below the crest: the face darkens toward its foot (before the mist lifts it
|
||||
// toward the haze), and the sun catches its top. A few multiplies per pixel, in the bake only.
|
||||
const foot = 1 - 0.4 * contrast * smoothstep(0.05, 0.9, dn);
|
||||
const top = 1 - smoothstep(0, 0.3, dn);
|
||||
const shade = (0.7 + 0.3 * lit * contrast + 0.3 * (1 - contrast)) * (1 - 0.5 * gully) * foot;
|
||||
const warmK =
|
||||
0.22 * contrast * lit * lit * (1 - 0.7 * dn) * (1 - 0.6 * gully) +
|
||||
0.04 * contrast * lit * top;
|
||||
// A hard 2 px lip on the crest and a soft glow under it.
|
||||
const rimK =
|
||||
(clamp01(1 - d / rim) * 0.4 + (d < glow * 5 ? Math.exp(-d / glow) * 0.08 : 0)) *
|
||||
contrast *
|
||||
(0.3 + 0.7 * lit);
|
||||
const mist = Math.min(0.9, spec.mist * mistK) * smoothstep(0, 1, dn);
|
||||
const o = (y * p.cols + c) * 4;
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
let v = base[i] * shade + warm[i] * (warmK + rimK);
|
||||
v += (haze[i] - v) * mist;
|
||||
out[o + i] = shift
|
||||
? ENCODE[
|
||||
Math.min(
|
||||
ENCODE_STEPS,
|
||||
((DECODE[v >= 255 ? 255 : v <= 0 ? 0 : Math.round(v)] * shift.scale +
|
||||
shift.add[i]) *
|
||||
ENCODE_STEPS) |
|
||||
0
|
||||
)
|
||||
]
|
||||
: v;
|
||||
}
|
||||
out[o + 3] = cover * 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,236 +0,0 @@
|
|||
// Every number of the ridge scene, and the pure functions that turn them into silhouettes. No DOM.
|
||||
// A ridge is a function of world-x (t, in viewport widths): ridged multifractal noise, domain-warped,
|
||||
// one function for every layer with the parameters below. Nothing in it repeats.
|
||||
import { horizonShape } from './horizon';
|
||||
import { valueNoise } from './noise';
|
||||
import type { Srgb, SkyColours } from './skyColour';
|
||||
|
||||
export interface LayerSpec {
|
||||
/** 0 farthest. Also the noise row, so layers never share a profile. */
|
||||
index: number;
|
||||
/** Lattice cells per viewport width for the first octave; each octave multiplies it by LACUNARITY. */
|
||||
baseCells: number;
|
||||
/** Peak-to-valley height of the silhouette, as a fraction of the viewport height. */
|
||||
relief: number;
|
||||
/** 0 rounded hills .. 1 sharp crags: how tightly each octave is folded at its crest. */
|
||||
crag: number;
|
||||
/** Ridge top at its lowest point, fraction of the viewport height up from the bottom. */
|
||||
base: number;
|
||||
/** 0 = the layer is the horizon haze, 1 = the nearest ground colour. */
|
||||
depth: number;
|
||||
/** Seconds for the layer to drift one viewport width. Farther layers are slower. */
|
||||
seconds: number;
|
||||
/** Octaves of the ridged multifractal; the bake cost is linear in it. */
|
||||
octaves: number;
|
||||
/** Domain warp, in cells of the first octave. */
|
||||
warp: number;
|
||||
/** 0..1 depth of the erosion streaks down the face. */
|
||||
gully: number;
|
||||
/** Width of one gully, CSS px. */
|
||||
gullyPx: number;
|
||||
/** 0..1 how far the foot of the face dissolves into the valley mist. */
|
||||
mist: number;
|
||||
/**
|
||||
* The layer is the real horizon of the viewpoint (`horizon.ts`), not noise: world-x is compass azimuth across the viewport
|
||||
* (`HorizonView`) and it does not drift, so it stays under the sun it is lit by. Its `relief` is the ring's own range.
|
||||
*/
|
||||
horizon?: boolean;
|
||||
}
|
||||
|
||||
/** Where the camera looks and how wide it sees, to read world-x as an azimuth: the sky's own view (`skyDome.ts viewFor`). */
|
||||
export interface HorizonView {
|
||||
/** Compass azimuth of the viewport's centre, degrees clockwise from north. */
|
||||
azimuthDeg: number;
|
||||
hfovDeg: number;
|
||||
}
|
||||
|
||||
/** The static horizon layer's track sits this many viewport widths left of the screen, so the camera's sway never shows its edge. */
|
||||
export const HORIZON_TRACK_SHIFT = 0.06;
|
||||
|
||||
/** Four layers: one function, four parameter rows. */
|
||||
export const LAYERS: readonly LayerSpec[] = [
|
||||
{
|
||||
index: 0,
|
||||
baseCells: 2.2,
|
||||
relief: 0.16,
|
||||
crag: 0.85,
|
||||
base: 0.3,
|
||||
depth: 0.12,
|
||||
seconds: Infinity,
|
||||
octaves: 5,
|
||||
warp: 0.6,
|
||||
gully: 0.3,
|
||||
gullyPx: 16,
|
||||
mist: 0.35,
|
||||
horizon: true,
|
||||
},
|
||||
{
|
||||
index: 1,
|
||||
baseCells: 3.0,
|
||||
relief: 0.2,
|
||||
crag: 0.7,
|
||||
base: 0.26,
|
||||
depth: 0.38,
|
||||
seconds: 300,
|
||||
octaves: 5,
|
||||
warp: 0.55,
|
||||
gully: 0.5,
|
||||
gullyPx: 20,
|
||||
mist: 0.3,
|
||||
},
|
||||
{
|
||||
index: 2,
|
||||
baseCells: 3.8,
|
||||
relief: 0.16,
|
||||
crag: 0.5,
|
||||
base: 0.17,
|
||||
depth: 0.66,
|
||||
seconds: 210,
|
||||
octaves: 5,
|
||||
warp: 0.5,
|
||||
gully: 0.6,
|
||||
gullyPx: 24,
|
||||
mist: 0.22,
|
||||
},
|
||||
{
|
||||
index: 3,
|
||||
baseCells: 4.6,
|
||||
relief: 0.12,
|
||||
crag: 0.3,
|
||||
base: 0.08,
|
||||
depth: 1,
|
||||
seconds: 150,
|
||||
octaves: 4,
|
||||
warp: 0.45,
|
||||
gully: 0.7,
|
||||
gullyPx: 30,
|
||||
mist: 0.16,
|
||||
},
|
||||
];
|
||||
|
||||
/** Not an integer power of two, so no octave's lattice lines up with another's. */
|
||||
export const LACUNARITY = 2.07;
|
||||
/** Each octave is weighted by the previous octave's folded signal, times this, clamped to 1. */
|
||||
export const WEIGHT_GAIN = 2;
|
||||
const AMP_GAIN = 0.5;
|
||||
/** Calibration: the weighted sum's typical top is about 1 / this. */
|
||||
const PEAK_NORM = 1.25;
|
||||
|
||||
/** Silhouette height in [0, 1] at world-x `t` (viewport widths); defined for every real t. */
|
||||
export function profile(spec: LayerSpec, t: number): number {
|
||||
const row = spec.index * 101;
|
||||
const wt =
|
||||
t + (spec.warp * (2 * valueNoise(t * spec.baseCells * 0.7, row + 97) - 1)) / spec.baseCells;
|
||||
const e = 0.03 + (1 - spec.crag) * 0.4;
|
||||
const top = Math.sqrt(1 + e * e);
|
||||
let sum = 0;
|
||||
let norm = 0;
|
||||
let amp = 1;
|
||||
let f = spec.baseCells;
|
||||
let w = 1;
|
||||
for (let k = 0; k < spec.octaves; k += 1) {
|
||||
const v = 2 * valueNoise(wt * f, row + k * 13) - 1;
|
||||
// Fold: 1 at the zero crossing of the noise, 0 at its extremes; `e` rounds the crease.
|
||||
let sig = 1 - Math.sqrt(v * v + e * e) / top;
|
||||
sig *= sig;
|
||||
sig *= w;
|
||||
w = Math.min(1, sig * WEIGHT_GAIN);
|
||||
sum += sig * amp;
|
||||
norm += amp;
|
||||
amp *= AMP_GAIN;
|
||||
f *= LACUNARITY;
|
||||
}
|
||||
// A soft swell under the folds, so the valleys between sharp crests are not flat floors.
|
||||
const swell = valueNoise(wt * spec.baseCells * 0.6, row + 211);
|
||||
return Math.min(1, 0.85 * (sum / norm) * PEAK_NORM + 0.15 * swell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Silhouette height in [0, 1] of a layer at world-x `t` (viewport widths). The horizon layer reads the baked horizon at the azimuth `t`
|
||||
* is under `view`; every other layer, or a horizon layer with no view, is the noise `profile`.
|
||||
*/
|
||||
export function layerProfile(spec: LayerSpec, t: number, view?: HorizonView): number {
|
||||
if (!spec.horizon || !view) return profile(spec, t);
|
||||
return horizonShape(view.azimuthDeg + (t - HORIZON_TRACK_SHIFT - 0.5) * view.hfovDeg);
|
||||
}
|
||||
|
||||
/** Erosion streak strength in [0, 1] at world-x `wxCss` (CSS px): a folded noise at gully width. */
|
||||
export function gullyAt(spec: LayerSpec, wxCss: number): number {
|
||||
const g = 1 - Math.abs(2 * valueNoise(wxCss / spec.gullyPx, spec.index * 131 + 5) - 1);
|
||||
return g * g;
|
||||
}
|
||||
|
||||
/** The distance haze the far layers dissolve into: between the mid sky and the horizon, not the horizon glow itself. */
|
||||
export function hazeColour(sky: SkyColours): Srgb {
|
||||
const m = (a: number, b: number) => Math.round(a + (b - a) * 0.4);
|
||||
return [
|
||||
m(sky.mid[0], sky.horizon[0]),
|
||||
m(sky.mid[1], sky.horizon[1]),
|
||||
m(sky.mid[2], sky.horizon[2]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Aerial perspective, applied once at bake time. A layer at distance d (0 nearest, 1 farthest) is seen
|
||||
* through Beer-Lambert transmittance T = exp(-extinction * d): it shows T of its own colour and 1 - T of
|
||||
* the haze, then loses `desaturate * (1 - T)` of its chroma, is softened by up to `blurPx` (canvas
|
||||
* pixels at scale 1) and takes a faint warm in-scatter of at most `scatter` on the sun side.
|
||||
*/
|
||||
export const AERIAL = { extinction: 1.6, desaturate: 0.5, blurPx: 2, scatter: 0.16 };
|
||||
|
||||
/** Distance of a layer from the viewer, 0 (nearest) .. 1 (farthest). */
|
||||
export const layerDistance = (spec: LayerSpec): number => 1 - spec.depth;
|
||||
|
||||
export const transmittance = (spec: LayerSpec): number =>
|
||||
Math.exp(-AERIAL.extinction * layerDistance(spec));
|
||||
|
||||
/** Layer colour as seen: its own ground colour thinned by the haze between it and the eye. */
|
||||
export function layerColour(spec: LayerSpec, sky: SkyColours): Srgb {
|
||||
const h = hazeColour(sky);
|
||||
const t = transmittance(spec);
|
||||
const seen = (i: number) => sky.ground[i] * t + h[i] * (1 - t);
|
||||
const luma = 0.2126 * seen(0) + 0.7152 * seen(1) + 0.0722 * seen(2);
|
||||
const keep = 1 - AERIAL.desaturate * (1 - t);
|
||||
const out = (i: number) => Math.round(luma + (seen(i) - luma) * keep);
|
||||
return [out(0), out(1), out(2)];
|
||||
}
|
||||
|
||||
/** Edge softening for a layer, in canvas pixels at scale 1; 0 for the nearest. */
|
||||
export const edgeBlur = (spec: LayerSpec): number => AERIAL.blurPx * (1 - transmittance(spec));
|
||||
|
||||
/**
|
||||
* Alpha of the warm sun-side in-scatter at world-x `t` (viewport widths). Zero when the sky has no
|
||||
* sun; grows with distance. The lobe is the product of two cosines with incommensurate wavelengths
|
||||
* (1.9 and 1.9 * golden ratio), so it is not periodic; its peaks are where the sun's azimuth puts them.
|
||||
*/
|
||||
export function scatterAlpha(spec: LayerSpec, sky: SkyColours, t: number): number {
|
||||
if (sky.sunAzimuth === undefined) return 0;
|
||||
const a = 0.5 + 0.5 * Math.cos(2 * Math.PI * (t / 1.9 - sky.sunAzimuth));
|
||||
const b = 0.75 + 0.25 * Math.cos((2 * Math.PI * t) / (1.9 * 1.618034));
|
||||
return AERIAL.scatter * (1 - transmittance(spec)) * a * a * b;
|
||||
}
|
||||
|
||||
/** Chunk width as a multiple of the viewport width: room for the yaw sway on top of the viewport. */
|
||||
export const CHUNK_OVER = 1.2;
|
||||
|
||||
/**
|
||||
* Integer pixel sizes for a viewport. `period` is one viewport width, the unit of world-x; a chunk
|
||||
* is `chunk` pixels of world, `height` the band a layer is painted in.
|
||||
*/
|
||||
export function layerSize(cssW: number, cssH: number, scale: number) {
|
||||
const period = Math.round(cssW * scale);
|
||||
const band = Math.round(cssH * scale * 0.6);
|
||||
return { period, chunk: Math.round(period * CHUNK_OVER), height: band };
|
||||
}
|
||||
|
||||
/** Ridge-top y (canvas pixels, from the top of the layer's band) at world-x `t` (viewport widths). */
|
||||
export function ridgeY(
|
||||
spec: LayerSpec,
|
||||
t: number,
|
||||
bandH: number,
|
||||
viewH: number,
|
||||
view?: HorizonView
|
||||
): number {
|
||||
const topFromBottom = spec.base * viewH + spec.relief * viewH * layerProfile(spec, t, view);
|
||||
return bandH - Math.min(bandH, topFromBottom);
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
// The one place the sky's colours come from. Void's `src/sky/sun.js` (`light({ time, lat, lon,
|
||||
// cloud_cover, precipitation })`, PR #20) is the intended source; until it lands this returns a
|
||||
// fixed twilight: lavender zenith, rose mid-sky, orange horizon. These are the raw stops: the scene draws them
|
||||
// shaped into the dusk band of ../skyBand.ts (`ridgeSkyFor`, skyForState.ts), whose floor the link of Noonday Sky needs. Replace the body, keep the signature: the scene calls it once, at startup,
|
||||
// and bakes the result.
|
||||
// fixed twilight: lavender zenith, rose mid-sky, orange horizon. Replace the body, keep the signature: the scene calls it once, at startup,
|
||||
// and paints the result.
|
||||
|
||||
import type { SkyBand } from '../skyBand';
|
||||
import type { PhysicalSky } from './physicalSky';
|
||||
|
||||
export type Srgb = readonly [number, number, number];
|
||||
|
|
@ -14,14 +12,8 @@ export interface SkyColours {
|
|||
top: Srgb;
|
||||
/** Mid-sky band. */
|
||||
mid: Srgb;
|
||||
/** Colour at the horizon, which the far ridges fade into. */
|
||||
/** Colour at the horizon. */
|
||||
horizon: Srgb;
|
||||
/** Nearest ridge: the ground colour the farther layers mix away from. */
|
||||
ground: Srgb;
|
||||
/** Where the sun sits across one drift period, 0..1; the layers pick up a faint warm in-scatter there. Omit for none. */
|
||||
sunAzimuth?: number;
|
||||
/** The state's luminance band (skyBand.ts): the layers are shaped into it as the sky is, so the theme ink clears 4.5:1 on a ridge as on bare sky. Omit for none. */
|
||||
band?: SkyBand;
|
||||
/** The physical sky this palette was read from; when present the host canvas is painted from it, not from the three stops. */
|
||||
physical?: PhysicalSky;
|
||||
}
|
||||
|
|
@ -31,7 +23,5 @@ export function skyColours(_now: Date = new Date()): SkyColours {
|
|||
top: [170, 145, 220],
|
||||
mid: [225, 130, 165],
|
||||
horizon: [240, 150, 80],
|
||||
ground: [7, 17, 26],
|
||||
sunAzimuth: 0.3,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,306 +0,0 @@
|
|||
{
|
||||
"viewpoint": { "lat": 48.1929826, "lon": 16.3534237, "groundM": 183.3 },
|
||||
"stepDeg": 0.5,
|
||||
"radiusKm": 60.0,
|
||||
"minKm": 1.0,
|
||||
"curvature": "drop d^2/2R*(1-0.13), R=6371000 m",
|
||||
"source": {
|
||||
"dataset": "Copernicus DEM GLO-30 (COP-DEM_GLO-30-DGED), a DSM, EGM2008 heights, 1 arc-second grid",
|
||||
"tiles": [
|
||||
"N47_00_E015_00",
|
||||
"N47_00_E016_00",
|
||||
"N47_00_E017_00",
|
||||
"N48_00_E015_00",
|
||||
"N48_00_E016_00",
|
||||
"N48_00_E017_00",
|
||||
"N49_00_E015_00",
|
||||
"N49_00_E016_00",
|
||||
"N49_00_E017_00"
|
||||
],
|
||||
"tileBytesEach": "about 42-44 MB (Cloud Optimized GeoTIFF); nine tiles, about 380 MB, read once, not committed",
|
||||
"url": "https://copernicus-dem-30m.s3.amazonaws.com/ (AWS Open Data, eu-central-1, no account)",
|
||||
"licence": "Copernicus DEM licence: free of charge for any use incl. commercial, attribution required, no warranty (https://spacedata.copernicus.eu/collections/copernicus-digital-elevation-model, Licencing)",
|
||||
"attribution": "Contains modified Copernicus data: DEM \u00a9 DLR e.V. 2010-2014 and \u00a9 Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved.",
|
||||
"bakedBy": "scripts/bake-horizon.py"
|
||||
},
|
||||
"elevationDeg": [
|
||||
1.608, 1.522, 1.467, 1.452, 1.433, 1.426, 1.497, 1.6, 1.597, 1.564, 1.532, 1.495, 1.467, 1.544,
|
||||
1.62, 1.655, 1.707, 1.775, 1.803, 1.683, 1.532, 1.394, 1.263, 1.297, 1.358, 1.412, 1.433, 1.339,
|
||||
1.264, 1.269, 1.195, 1.142, 1.13, 1.22, 1.401, 1.368, 1.326, 1.294, 1.378, 1.46, 1.488, 1.516,
|
||||
1.549, 1.598, 1.647, 1.698, 1.769, 1.816, 1.801, 1.783, 1.695, 1.619, 1.586, 1.547, 1.442,
|
||||
1.335, 1.282, 1.286, 1.335, 1.421, 1.449, 1.437, 1.313, 1.268, 1.164, 1.14, 1.098, 1.06, 0.984,
|
||||
0.938, 0.91, 0.877, 0.884, 0.872, 0.943, 0.974, 0.919, 0.873, 0.861, 0.839, 0.731, 0.673, 0.56,
|
||||
0.494, 0.527, 0.601, 0.566, 0.584, 0.579, 0.643, 0.666, 0.741, 0.851, 0.711, 0.703, 0.573, 0.54,
|
||||
0.488, 0.433, 0.452, 0.467, 0.483, 0.475, 0.517, 0.419, 0.428, 0.457, 0.489, 0.522, 0.482, 0.5,
|
||||
0.527, 0.528, 0.471, 0.458, 0.487, 0.521, 0.578, 0.553, 0.419, 0.301, 0.324, 0.425, 0.468,
|
||||
0.512, 0.558, 0.575, 0.521, 0.477, 0.444, 0.372, 0.297, 0.365, 0.446, 0.486, 0.523, 0.532,
|
||||
0.516, 0.516, 0.531, 0.52, 0.546, 0.565, 0.535, 0.527, 0.508, 0.516, 0.37, 0.359, 0.33, 0.375,
|
||||
0.454, 0.546, 0.496, 0.449, 0.425, 0.447, 0.398, 0.388, 0.439, 0.476, 0.496, 0.517, 0.541,
|
||||
0.494, 0.439, 0.383, 0.411, 0.502, 0.621, 0.578, 0.548, 0.568, 0.642, 0.713, 0.708, 0.654,
|
||||
0.704, 0.741, 0.709, 0.677, 0.661, 0.66, 0.666, 0.662, 0.651, 0.699, 0.727, 0.746, 0.809, 0.788,
|
||||
0.799, 0.793, 0.702, 0.734, 0.79, 0.754, 0.704, 0.616, 0.598, 0.708, 0.719, 0.706, 0.704, 0.726,
|
||||
0.826, 0.849, 0.85, 0.813, 0.853, 0.926, 0.971, 0.918, 1.003, 1.0, 0.927, 0.985, 1.031, 1.043,
|
||||
1.067, 1.13, 1.022, 1.02, 1.043, 1.101, 1.144, 1.099, 1.082, 1.064, 1.2, 1.238, 1.16, 1.084,
|
||||
1.202, 1.326, 1.39, 1.429, 1.405, 1.332, 1.358, 1.361, 1.357, 1.354, 1.335, 1.319, 1.376, 1.309,
|
||||
1.289, 1.257, 1.283, 1.237, 1.296, 1.353, 1.259, 1.314, 1.236, 1.307, 1.344, 1.36, 1.251, 1.292,
|
||||
1.308, 1.26, 1.288, 1.365, 1.391, 1.414, 1.32, 1.299, 1.35, 1.288, 1.361, 1.303, 1.268, 1.29,
|
||||
1.305, 1.326, 1.344, 1.328, 1.32, 1.358, 1.375, 1.443, 1.477, 1.492, 1.525, 1.513, 1.422, 1.314,
|
||||
1.294, 1.337, 1.414, 1.343, 1.397, 1.431, 1.409, 1.378, 1.423, 1.438, 1.343, 1.257, 1.208,
|
||||
1.209, 1.233, 1.251, 1.267, 1.274, 1.248, 1.254, 1.297, 1.34, 1.359, 1.34, 1.199, 1.162, 1.255,
|
||||
1.292, 1.29, 1.24, 1.222, 1.24, 1.271, 1.264, 1.317, 1.256, 1.26, 1.321, 1.301, 1.266, 1.268,
|
||||
1.308, 1.357, 1.474, 1.419, 1.438, 1.393, 1.354, 1.343, 1.354, 1.333, 1.321, 1.359, 1.437, 1.47,
|
||||
1.395, 1.413, 1.446, 1.466, 1.434, 1.446, 1.458, 1.419, 1.522, 1.502, 1.506, 1.512, 1.528,
|
||||
1.526, 1.485, 1.427, 1.508, 1.5, 1.48, 1.534, 1.514, 1.449, 1.449, 1.386, 1.368, 1.388, 1.404,
|
||||
1.374, 1.374, 1.352, 1.3, 1.347, 1.332, 1.265, 1.235, 1.39, 1.285, 1.226, 1.233, 1.235, 1.211,
|
||||
1.164, 1.183, 1.217, 1.143, 1.128, 1.117, 1.112, 1.086, 1.071, 1.118, 1.103, 1.002, 0.99, 0.995,
|
||||
1.025, 0.998, 1.024, 0.971, 1.045, 1.09, 1.11, 1.108, 1.081, 1.171, 1.308, 1.446, 1.482, 1.484,
|
||||
1.494, 1.469, 1.472, 1.479, 1.493, 1.467, 1.388, 1.293, 1.203, 1.104, 1.145, 1.12, 1.028, 1.004,
|
||||
0.982, 0.968, 0.933, 0.97, 0.986, 1.035, 1.12, 1.227, 1.281, 1.316, 1.312, 1.273, 1.187, 1.205,
|
||||
1.197, 1.199, 1.176, 1.177, 1.142, 1.19, 1.377, 1.369, 1.322, 1.295, 1.385, 1.493, 1.576, 1.679,
|
||||
1.769, 1.622, 1.711, 1.641, 1.517, 1.582, 1.525, 1.39, 1.389, 1.343, 1.331, 1.369, 1.343, 1.257,
|
||||
1.212, 1.134, 1.039, 1.03, 1.075, 1.027, 1.059, 1.112, 1.132, 1.14, 1.16, 1.167, 1.178, 1.179,
|
||||
1.192, 1.214, 1.245, 1.289, 1.286, 1.279, 1.259, 1.256, 1.202, 1.138, 1.159, 1.116, 1.12, 1.102,
|
||||
0.999, 1.042, 1.051, 1.09, 1.143, 1.244, 1.269, 1.296, 1.353, 1.412, 1.579, 1.686, 1.814, 1.857,
|
||||
1.773, 1.731, 1.748, 1.742, 1.668, 1.594, 1.628, 1.692, 1.76, 1.822, 1.863, 1.904, 1.895, 1.849,
|
||||
1.786, 1.778, 1.731, 1.666, 1.633, 1.561, 1.526, 1.662, 1.747, 1.75, 1.704, 1.631, 1.563, 1.473,
|
||||
1.501, 1.488, 1.464, 1.441, 1.386, 1.31, 1.298, 1.293, 1.306, 1.371, 1.42, 1.416, 1.417, 1.418,
|
||||
1.409, 1.399, 1.408, 1.431, 1.434, 1.437, 1.509, 1.544, 1.58, 1.674, 1.528, 1.534, 1.517, 1.497,
|
||||
1.525, 1.546, 1.562, 1.58, 1.55, 1.634, 1.614, 1.66, 1.643, 1.663, 1.68, 1.829, 1.99, 2.058,
|
||||
2.014, 1.911, 2.025, 2.023, 2.036, 2.031, 2.009, 2.012, 2.02, 2.109, 2.107, 2.12, 2.171, 2.179,
|
||||
2.125, 2.084, 2.09, 2.129, 2.183, 2.16, 2.172, 2.239, 2.237, 2.218, 2.217, 2.137, 2.169, 2.203,
|
||||
2.233, 2.262, 2.272, 2.21, 2.133, 1.955, 1.909, 1.97, 2.138, 2.187, 2.229, 2.278, 2.191, 2.167,
|
||||
2.213, 2.327, 2.409, 2.31, 2.242, 2.205, 2.152, 2.154, 2.258, 2.217, 2.126, 2.054, 1.97, 1.942,
|
||||
2.022, 1.894, 1.886, 1.921, 1.897, 1.936, 1.964, 1.978, 1.961, 1.927, 1.879, 1.904, 1.96, 1.9,
|
||||
1.922, 2.023, 2.061, 2.115, 1.99, 1.805, 1.736, 1.776, 1.841, 1.863, 1.934, 1.942, 1.962, 2.043,
|
||||
2.082, 2.082, 2.092, 2.062, 1.957, 1.794, 1.821, 1.913, 2.009, 2.066, 2.105, 2.036, 1.964,
|
||||
1.984, 2.005, 2.036, 2.072, 2.094, 2.022, 2.153, 2.177, 2.146, 2.125, 2.061, 2.004, 1.955,
|
||||
1.902, 1.84, 1.767, 1.7, 1.696, 1.718, 1.725, 1.709, 1.745, 1.805, 1.836, 1.939, 2.053, 2.14,
|
||||
2.139, 2.142, 2.035, 1.902, 1.779, 1.667, 1.564, 1.57, 1.581, 1.628, 1.693, 1.739, 1.738, 1.738,
|
||||
1.675
|
||||
],
|
||||
"distanceKm": [
|
||||
1.0, 1.0, 1.06, 1.06, 1.06, 1.06, 1.06, 1.03, 1.0, 1.0, 1.0, 1.0, 1.09, 1.09, 1.0, 1.09, 1.09,
|
||||
1.09, 1.09, 1.09, 1.09, 1.09, 1.09, 1.12, 1.12, 1.12, 1.12, 1.12, 1.12, 1.09, 1.09, 1.09, 1.09,
|
||||
1.0, 1.0, 1.0, 1.0, 1.03, 1.06, 1.06, 1.03, 1.03, 1.03, 1.03, 1.03, 1.03, 1.0, 1.0, 1.0, 1.0,
|
||||
1.0, 1.03, 1.03, 1.03, 1.03, 1.03, 1.0, 1.0, 1.06, 1.06, 1.06, 1.06, 1.06, 1.12, 1.0, 1.0, 1.24,
|
||||
1.24, 1.21, 1.21, 1.3, 1.3, 1.27, 1.3, 1.33, 1.33, 1.33, 1.33, 1.27, 1.24, 1.27, 1.27, 1.27,
|
||||
1.03, 1.03, 1.42, 1.84, 1.84, 1.81, 1.03, 1.72, 1.63, 1.63, 1.63, 1.33, 1.33, 1.06, 1.06, 1.72,
|
||||
1.72, 1.69, 1.69, 1.69, 1.69, 1.69, 1.81, 1.81, 1.75, 1.51, 1.75, 1.75, 1.75, 1.75, 1.75, 1.72,
|
||||
1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.42,
|
||||
1.42, 1.24, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.27, 1.03, 1.36, 1.36, 1.36, 1.36, 1.36, 1.45,
|
||||
1.45, 1.09, 1.12, 1.12, 1.54, 1.57, 1.48, 1.48, 1.48, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
1.0, 1.18, 1.18, 1.21, 1.21, 1.21, 1.12, 1.12, 1.12, 1.12, 1.12, 1.15, 1.15, 1.15, 1.15, 1.18,
|
||||
1.15, 1.15, 1.24, 1.24, 1.27, 1.27, 1.24, 1.24, 1.24, 1.27, 1.27, 1.27, 1.9, 1.9, 1.93, 1.93,
|
||||
1.93, 1.99, 1.99, 1.99, 1.99, 1.9, 2.02, 2.02, 2.02, 2.05, 2.02, 1.99, 1.99, 1.99, 1.48, 1.21,
|
||||
1.21, 1.57, 1.69, 1.69, 1.66, 1.39, 1.39, 1.39, 1.54, 1.6, 1.54, 1.54, 1.54, 1.48, 1.45, 1.21,
|
||||
1.21, 1.21, 1.27, 1.39, 1.39, 1.36, 1.39, 1.39, 1.39, 1.33, 1.33, 1.33, 1.33, 1.33, 1.48, 1.45,
|
||||
1.39, 1.39, 1.18, 1.18, 1.18, 1.48, 1.48, 1.27, 1.24, 1.27, 1.36, 1.36, 1.39, 1.33, 1.3, 1.3,
|
||||
1.3, 1.3, 1.3, 1.3, 1.33, 1.0, 1.42, 1.42, 1.27, 1.27, 1.27, 1.27, 1.03, 1.03, 1.03, 1.03, 1.03,
|
||||
1.03, 1.03, 1.03, 1.06, 1.06, 1.03, 1.03, 1.03, 1.36, 1.06, 1.06, 1.06, 1.06, 1.09, 1.09, 1.18,
|
||||
1.21, 1.09, 1.09, 1.09, 1.09, 1.09, 1.09, 1.09, 1.09, 1.09, 1.09, 1.15, 1.15, 1.36, 1.36, 1.36,
|
||||
1.36, 1.33, 1.33, 3.13, 1.21, 1.21, 3.34, 3.31, 2.83, 2.65, 2.65, 1.3, 2.29, 1.3, 1.15, 1.15,
|
||||
1.15, 2.29, 2.68, 2.41, 2.23, 2.23, 2.2, 1.12, 2.23, 2.17, 2.17, 2.17, 1.84, 2.74, 1.87, 1.87,
|
||||
2.95, 2.2, 2.17, 2.17, 2.35, 2.35, 2.23, 2.23, 2.11, 2.14, 2.08, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2,
|
||||
2.41, 2.41, 2.38, 2.41, 2.41, 2.44, 2.44, 2.44, 1.99, 2.08, 2.08, 2.08, 2.08, 2.05, 2.05, 2.5,
|
||||
2.38, 2.47, 2.29, 2.23, 2.17, 1.69, 1.69, 2.38, 2.47, 2.38, 2.17, 2.71, 2.71, 2.2, 2.47, 2.41,
|
||||
2.41, 2.32, 2.38, 2.38, 2.08, 2.5, 2.11, 2.11, 1.75, 1.75, 1.48, 1.81, 1.81, 1.78, 1.78, 1.87,
|
||||
17.2, 17.2, 17.26, 17.32, 17.44, 18.1, 17.56, 17.5, 17.38, 17.5, 17.62, 17.68, 17.74, 17.8,
|
||||
14.86, 14.92, 14.98, 2.98, 26.38, 26.38, 26.38, 26.62, 26.14, 26.02, 26.02, 26.38, 26.26, 26.38,
|
||||
26.38, 26.26, 26.26, 26.26, 14.98, 14.98, 14.98, 14.44, 13.12, 13.18, 13.66, 13.72, 13.72,
|
||||
13.84, 13.84, 13.84, 13.72, 12.52, 12.58, 12.58, 12.28, 12.22, 12.28, 16.54, 14.02, 15.04,
|
||||
16.18, 16.24, 17.08, 17.26, 17.44, 17.5, 17.44, 17.32, 17.44, 17.02, 13.96, 14.14, 9.22, 9.16,
|
||||
9.1, 9.22, 9.28, 9.28, 9.22, 9.16, 9.16, 9.34, 8.68, 8.68, 8.62, 8.74, 8.86, 8.92, 8.86, 8.92,
|
||||
8.92, 11.74, 14.08, 11.98, 12.22, 12.04, 34.3, 10.36, 10.06, 9.64, 9.58, 9.58, 9.7, 9.7, 10.18,
|
||||
10.18, 10.18, 10.24, 10.06, 10.48, 9.94, 9.82, 9.76, 9.7, 8.02, 8.14, 8.14, 8.14, 8.08, 8.56,
|
||||
8.38, 8.38, 8.32, 8.38, 8.02, 8.02, 8.02, 8.14, 8.2, 7.9, 7.9, 7.84, 7.78, 7.66, 7.72, 7.72,
|
||||
7.72, 1.0, 1.0, 1.0, 1.0, 1.0, 1.45, 1.21, 1.21, 1.3, 1.15, 1.15, 1.15, 1.15, 1.15, 1.15, 1.15,
|
||||
1.33, 1.33, 1.33, 1.48, 1.3, 1.3, 1.3, 1.42, 1.09, 2.02, 1.81, 2.59, 2.59, 2.53, 1.21, 1.75,
|
||||
1.69, 1.66, 2.38, 1.57, 1.57, 1.57, 7.18, 7.18, 7.24, 7.24, 7.18, 7.12, 1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
7.36, 7.3, 7.3, 7.18, 7.24, 7.06, 7.06, 7.06, 7.06, 7.0, 7.12, 7.12, 7.12, 7.0, 7.0, 7.0, 7.0,
|
||||
7.24, 7.24, 7.06, 7.18, 7.0, 7.06, 7.0, 7.0, 6.94, 7.0, 7.24, 1.03, 1.03, 1.03, 1.0, 1.0, 1.0,
|
||||
1.06, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.03, 1.03, 1.03, 1.03, 1.03, 1.03, 1.27, 1.27, 1.27,
|
||||
1.24, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.09, 1.09, 1.06, 1.06, 1.06, 1.06, 1.06,
|
||||
1.09, 1.09, 9.64, 9.58, 9.64, 9.64, 9.7, 9.7, 9.7, 9.7, 9.7, 9.64, 9.64, 9.64, 9.7, 1.03, 1.03,
|
||||
1.03, 1.03, 1.03, 1.03, 9.52, 1.0, 1.0, 9.4, 8.68, 8.68, 8.68, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 9.52, 9.46, 9.46, 9.46, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
|
||||
],
|
||||
"peakHeightM": [
|
||||
211.4, 209.9, 210.5, 210.2, 209.9, 209.7, 211.0, 212.1, 211.2, 210.6, 210.1, 209.4, 211.3,
|
||||
212.7, 211.6, 214.8, 215.8, 217.1, 217.7, 215.4, 212.5, 209.9, 207.4, 208.7, 209.9, 211.0,
|
||||
211.4, 209.5, 208.1, 207.5, 206.1, 205.1, 204.8, 204.6, 207.8, 207.2, 206.5, 206.6, 208.8,
|
||||
210.4, 210.1, 210.6, 211.2, 212.1, 213.0, 213.9, 214.2, 215.0, 214.8, 214.5, 212.9, 212.5,
|
||||
211.9, 211.2, 209.3, 207.3, 205.7, 205.8, 208.1, 209.6, 210.2, 209.9, 207.6, 208.2, 203.7,
|
||||
203.2, 207.2, 206.3, 204.2, 203.2, 204.0, 203.3, 203.0, 203.2, 205.3, 206.0, 204.7, 203.7,
|
||||
202.5, 201.5, 199.6, 198.3, 195.8, 192.2, 192.8, 198.3, 201.7, 202.3, 201.8, 194.9, 203.5,
|
||||
204.5, 207.7, 203.7, 199.7, 196.7, 193.3, 192.4, 196.5, 197.1, 197.2, 197.7, 197.5, 198.7,
|
||||
195.8, 197.0, 197.9, 198.4, 197.2, 198.2, 198.7, 199.6, 199.6, 197.9, 197.2, 198.1, 199.1,
|
||||
200.8, 200.1, 196.0, 192.5, 189.0, 190.8, 191.5, 192.3, 193.1, 193.4, 192.4, 191.7, 191.1,
|
||||
189.8, 190.8, 192.5, 193.0, 194.4, 195.2, 195.5, 195.1, 195.1, 195.4, 195.2, 195.5, 193.5,
|
||||
196.1, 195.9, 195.5, 195.6, 192.2, 192.5, 191.8, 190.5, 192.2, 194.0, 196.8, 195.7, 194.4,
|
||||
195.0, 193.7, 190.1, 191.0, 191.7, 192.0, 192.4, 192.8, 192.0, 191.0, 190.0, 191.8, 193.7,
|
||||
196.5, 195.6, 194.9, 194.5, 195.9, 197.3, 197.2, 196.1, 197.5, 198.2, 197.6, 196.9, 197.0,
|
||||
196.6, 196.7, 197.7, 197.5, 198.9, 199.5, 199.5, 200.9, 200.4, 201.1, 201.0, 198.9, 207.9,
|
||||
209.7, 208.9, 207.2, 204.3, 204.3, 208.1, 208.5, 208.1, 206.9, 209.1, 212.7, 213.5, 214.0,
|
||||
212.2, 213.2, 215.7, 217.3, 207.1, 204.6, 204.5, 208.8, 212.5, 213.9, 213.7, 209.3, 210.8,
|
||||
208.2, 210.9, 212.6, 213.0, 214.2, 213.0, 211.4, 210.3, 208.7, 209.5, 207.9, 207.4, 212.6,
|
||||
215.6, 216.4, 218.1, 217.5, 215.7, 214.9, 215.0, 214.9, 214.8, 214.4, 217.5, 218.3, 215.2,
|
||||
214.7, 209.3, 209.8, 208.9, 216.9, 218.4, 211.3, 211.8, 210.8, 214.4, 215.3, 216.4, 212.4,
|
||||
212.7, 213.1, 212.0, 212.6, 214.4, 215.0, 216.2, 206.4, 215.6, 216.9, 211.9, 213.6, 212.3,
|
||||
211.5, 206.5, 206.8, 207.2, 207.5, 207.2, 207.1, 207.8, 208.1, 210.0, 210.7, 210.2, 210.8,
|
||||
210.5, 217.2, 207.7, 207.3, 208.1, 209.5, 208.9, 209.9, 212.8, 213.1, 209.6, 210.4, 210.7,
|
||||
208.9, 207.3, 206.3, 206.4, 206.8, 207.2, 207.5, 208.9, 208.4, 213.2, 214.2, 215.2, 215.7,
|
||||
214.5, 211.2, 247.4, 209.9, 210.7, 259.2, 255.7, 244.2, 241.1, 242.6, 212.1, 236.3, 211.9,
|
||||
208.7, 209.9, 209.5, 234.2, 243.1, 238.7, 236.5, 241.0, 238.1, 211.5, 237.8, 234.9, 234.5,
|
||||
234.9, 226.3, 246.9, 227.9, 230.4, 259.6, 237.2, 237.1, 238.4, 243.8, 242.5, 239.9, 240.4,
|
||||
235.8, 240.4, 238.1, 241.4, 241.7, 242.3, 242.2, 240.6, 238.4, 247.1, 246.8, 245.2, 248.2,
|
||||
247.4, 245.4, 245.4, 242.7, 231.1, 234.0, 234.5, 233.4, 233.5, 231.9, 230.1, 242.5, 239.0,
|
||||
238.2, 233.0, 237.7, 232.3, 219.6, 219.9, 235.0, 235.9, 232.0, 228.4, 241.4, 237.8, 226.9,
|
||||
231.8, 230.5, 229.4, 227.0, 230.1, 229.5, 219.9, 226.9, 220.2, 221.3, 214.0, 214.8, 208.5,
|
||||
216.5, 217.9, 218.0, 217.9, 218.8, 554.9, 596.3, 639.3, 651.8, 655.9, 677.7, 654.8, 653.7,
|
||||
652.5, 660.3, 655.7, 632.9, 605.1, 578.6, 484.8, 496.7, 491.5, 237.4, 693.3, 682.9, 676.3,
|
||||
665.1, 672.6, 677.4, 699.5, 746.5, 793.0, 820.8, 836.9, 831.7, 813.8, 774.3, 513.7, 511.5,
|
||||
512.0, 493.9, 464.6, 457.9, 479.7, 526.0, 524.0, 515.7, 509.3, 531.0, 553.8, 538.4, 562.8,
|
||||
582.7, 541.4, 558.5, 545.3, 640.0, 583.8, 599.0, 593.8, 595.2, 603.6, 604.7, 620.9, 614.5,
|
||||
586.6, 570.3, 549.1, 511.8, 447.5, 462.2, 354.3, 358.3, 365.5, 371.3, 373.8, 377.0, 376.8,
|
||||
377.3, 377.6, 383.6, 372.4, 377.1, 382.3, 384.6, 386.4, 384.8, 382.9, 375.9, 365.9, 430.3,
|
||||
471.0, 427.2, 428.5, 403.2, 887.7, 380.7, 381.5, 382.0, 397.5, 401.8, 409.1, 418.8, 441.2,
|
||||
470.9, 490.1, 514.8, 516.4, 515.3, 490.4, 489.5, 486.6, 472.2, 410.8, 419.1, 428.3, 437.9,
|
||||
444.8, 466.6, 466.6, 465.3, 456.6, 449.4, 436.6, 430.0, 421.0, 419.8, 411.4, 398.0, 416.8,
|
||||
426.6, 425.1, 415.1, 407.2, 398.0, 385.9, 209.6, 209.3, 208.9, 208.5, 207.5, 216.6, 210.8,
|
||||
210.7, 213.0, 210.9, 211.9, 211.8, 211.8, 211.8, 211.6, 211.4, 216.1, 216.6, 216.7, 220.6,
|
||||
217.6, 218.4, 219.2, 224.9, 212.4, 237.7, 231.4, 251.4, 252.7, 252.0, 216.4, 231.7, 229.2,
|
||||
230.8, 250.7, 228.9, 228.5, 229.0, 397.4, 416.0, 438.4, 447.0, 439.3, 424.3, 218.7, 218.7,
|
||||
218.9, 218.8, 218.4, 445.6, 444.4, 455.8, 451.0, 454.8, 454.3, 455.3, 448.6, 443.6, 442.1,
|
||||
451.4, 458.2, 455.3, 452.1, 460.3, 460.0, 457.7, 467.1, 457.0, 454.1, 463.0, 459.5, 465.5,
|
||||
464.3, 456.8, 445.0, 425.5, 428.2, 218.8, 221.8, 222.7, 222.3, 223.1, 221.6, 223.5, 222.0,
|
||||
224.0, 225.4, 223.7, 222.5, 221.8, 220.9, 222.1, 224.0, 223.2, 221.6, 220.3, 218.8, 226.4,
|
||||
228.2, 225.4, 224.2, 216.9, 216.5, 217.1, 217.6, 217.9, 217.6, 217.0, 216.1, 216.6, 220.6,
|
||||
219.5, 218.9, 220.8, 221.5, 222.5, 220.2, 217.7, 216.4, 488.4, 497.5, 503.2, 515.2, 518.5,
|
||||
522.0, 535.7, 542.3, 542.3, 541.8, 536.7, 518.9, 493.5, 216.1, 217.8, 219.5, 220.5, 221.2,
|
||||
220.0, 516.0, 218.0, 218.4, 523.4, 502.5, 505.8, 494.9, 220.9, 221.3, 220.8, 220.4, 219.3,
|
||||
218.3, 217.5, 216.5, 215.5, 214.2, 213.0, 212.9, 213.3, 213.5, 473.5, 477.6, 487.5, 492.6,
|
||||
217.2, 219.2, 220.7, 220.7, 220.7, 218.9, 216.5, 214.4, 212.5, 210.6, 210.7, 210.9, 211.8,
|
||||
212.9, 213.7, 213.7, 213.7, 212.6
|
||||
],
|
||||
"slopeEast": [
|
||||
0.002, -0.001, 0.056, 0.043, 0.022, 0.002, 0.007, -0.005, 0.014, 0.012, 0.002, -0.013, 0.046,
|
||||
0.027, -0.083, -0.005, -0.017, -0.01, -0.007, -0.03, -0.051, -0.056, -0.058, -0.088, -0.109,
|
||||
-0.099, -0.085, -0.079, -0.077, 0.008, 0.005, 0.006, -0.01, 0.062, 0.068, 0.071, 0.074, 0.084,
|
||||
0.019, -0.001, 0.023, 0.02, 0.021, 0.024, 0.025, 0.031, 0.054, 0.031, 0.003, -0.022, -0.034,
|
||||
-0.054, -0.055, -0.049, -0.047, -0.045, -0.038, -0.041, -0.051, -0.054, -0.073, -0.086, -0.104,
|
||||
-0.05, -0.085, -0.083, 0.125, 0.082, 0.049, 0.018, 0.064, 0.034, -0.013, -0.004, -0.06, -0.087,
|
||||
-0.128, -0.166, -0.129, -0.038, -0.154, -0.158, -0.163, -0.116, -0.12, 0.088, 0.055, 0.048,
|
||||
0.095, 0.036, 0.154, 0.016, -0.009, -0.018, -0.079, -0.121, -0.161, -0.174, 0.003, 0.037, 0.108,
|
||||
0.103, 0.1, 0.106, 0.101, -0.064, -0.045, 0.013, 0.149, 0.083, 0.078, 0.071, 0.039, -0.062,
|
||||
-0.065, -0.118, -0.105, -0.072, -0.045, -0.025, -0.001, -0.008, -0.007, -0.02, -0.037, -0.058,
|
||||
-0.078, -0.075, -0.069, -0.063, -0.054, -0.008, 0.003, 0.123, 0.036, 0.015, -0.005, 0.017,
|
||||
0.049, 0.086, 0.068, 0.013, 0.032, -0.024, -0.01, 0.005, 0.009, -0.005, -0.004, 0.021, 0.062,
|
||||
-0.012, -0.014, -0.013, -0.031, 0.02, -0.004, -0.021, -0.005, -0.018, -0.026, -0.032, -0.038,
|
||||
-0.046, -0.055, -0.063, -0.067, -0.007, 0.009, -0.048, -0.051, -0.051, -0.004, -0.015, -0.025,
|
||||
-0.018, 0.002, -0.002, 0.005, 0.013, 0.02, 0.049, 0.013, 0.002, -0.023, -0.009, -0.075, -0.065,
|
||||
0.018, 0.02, 0.024, -0.023, -0.022, -0.049, 0.01, 0.056, -0.003, -0.001, 0.008, -0.048, -0.05,
|
||||
-0.03, -0.015, 0.002, -0.045, -0.077, -0.052, -0.113, -0.035, 0.052, 0.029, -0.006, -0.008,
|
||||
0.119, 0.111, 0.049, 0.019, -0.001, -0.008, 0.003, 0.025, 0.028, 0.004, -0.059, 0.008, 0.005,
|
||||
-0.0, 0.055, 0.03, -0.044, -0.024, -0.002, -0.029, -0.015, -0.028, -0.04, -0.079, -0.084,
|
||||
-0.073, 0.118, 0.104, 0.095, 0.098, 0.122, -0.042, 0.014, 0.108, 0.117, -0.077, -0.066, -0.052,
|
||||
0.006, 0.018, -0.026, -0.008, 0.016, -0.019, -0.02, 0.006, 0.033, 0.056, 0.035, 0.017, 0.002,
|
||||
0.011, 0.009, -0.015, 0.039, -0.016, -0.019, 0.073, 0.06, 0.028, 0.012, -0.052, -0.037, -0.027,
|
||||
-0.026, -0.025, -0.027, -0.034, -0.033, -0.112, -0.098, -0.018, -0.005, 0.014, -0.002, -0.012,
|
||||
-0.021, -0.041, -0.06, -0.073, -0.068, -0.007, 0.023, -0.002, 0.014, 0.031, 0.042, 0.045, 0.05,
|
||||
0.06, 0.075, 0.066, 0.054, 0.029, 0.03, -0.066, -0.045, -0.033, -0.035, 0.1, 0.072, 0.022,
|
||||
-0.017, 0.002, 0.006, 0.105, 0.007, -0.015, 0.014, -0.019, -0.045, 0.021, -0.027, -0.032,
|
||||
-0.043, 0.023, -0.048, 0.051, -0.072, -0.099, -0.013, 0.016, 0.062, 0.05, 0.066, 0.041, 0.022,
|
||||
-0.031, -0.028, -0.003, 0.047, -0.019, -0.007, 0.014, -0.047, 0.019, -0.023, -0.023, 0.008,
|
||||
-0.064, 0.049, -0.035, -0.026, 0.01, 0.043, 0.057, 0.094, -0.076, -0.07, 0.043, 0.029, 0.051,
|
||||
0.001, 0.036, 0.056, -0.016, -0.042, -0.015, -0.0, 0.037, 0.052, 0.089, 0.032, 0.021, 0.06,
|
||||
-0.018, 0.018, 0.002, 0.036, 0.058, -0.043, 0.005, -0.0, -0.004, -0.084, -0.088, 0.055, -0.004,
|
||||
0.02, 0.027, 0.018, -0.003, -0.013, -0.01, -0.005, 0.032, 0.037, -0.085, -0.114, 0.016, -0.076,
|
||||
-0.081, 0.043, 0.029, 0.014, -0.247, -0.334, -0.183, -0.03, -0.023, 0.027, 0.067, 0.018, -0.17,
|
||||
0.04, 0.076, 0.16, 0.142, 0.214, -0.239, -0.036, 0.236, 0.006, -0.075, -0.015, -0.134, 0.191,
|
||||
-0.098, -0.235, -0.094, -0.348, -0.156, -0.126, 0.06, -0.008, 0.039, 0.184, 0.048, 0.037, 0.035,
|
||||
-0.057, -0.06, 0.062, -0.295, -0.071, -0.175, 0.046, -0.045, -0.173, -0.173, -0.161, -0.148,
|
||||
0.042, -0.034, -0.145, 0.247, 0.002, -0.209, 0.028, -0.129, -0.037, 0.154, -0.069, -0.023,
|
||||
0.149, 0.119, -0.146, 0.175, 0.112, -0.005, -0.029, -0.11, -0.064, -0.06, -0.018, -0.04, 0.03,
|
||||
-0.087, -0.043, -0.015, -0.031, -0.13, -0.068, -0.06, 0.001, -0.021, -0.0, -0.013, 0.032, 0.012,
|
||||
-0.025, 0.013, 0.081, 0.008, -0.101, 0.006, -0.063, -0.072, -0.034, -0.109, -0.03, -0.058,
|
||||
-0.068, -0.174, -0.1, -0.092, -0.088, -0.053, 0.072, 0.007, -0.043, -0.029, -0.004, -0.033,
|
||||
-0.07, -0.071, -0.07, -0.077, -0.07, -0.021, -0.02, -0.061, -0.004, -0.114, -0.02, -0.023,
|
||||
0.032, 0.05, -0.037, -0.005, -0.02, -0.109, -0.063, 0.014, -0.015, -0.037, 0.007, 0.019, 0.035,
|
||||
0.051, 0.064, -0.018, -0.034, -0.025, 0.038, -0.074, -0.071, -0.068, -0.065, -0.061, -0.056,
|
||||
-0.05, -0.038, -0.032, -0.02, 0.035, -0.023, -0.034, -0.042, -0.009, -0.053, -0.061, -0.048,
|
||||
0.032, 0.055, -0.052, 0.019, 0.04, -0.026, 0.007, -0.033, -0.04, -0.044, -0.047, 0.134, -0.002,
|
||||
0.095, 0.061, -0.082, -0.127, 0.039, 0.057, 0.077, 0.092, 0.081, 0.007, -0.041, 0.057, -0.038,
|
||||
0.02, 0.004, -0.126, -0.118, -0.042, -0.061, -0.009, -0.034, -0.028, -0.016, 0.066, -0.008,
|
||||
-0.033, -0.062, -0.168, 0.054, 0.058, -0.007, 0.007, -0.054, -0.042, -0.257, -0.152, 0.009,
|
||||
0.029, 0.032, 0.036, -0.033, -0.046, -0.05, 0.018, -0.059, -0.065, -0.078, -0.093, -0.109,
|
||||
-0.126, -0.136, -0.072, -0.057, -0.05, -0.039, -0.032, -0.029, -0.024, -0.055, -0.05, -0.057,
|
||||
0.019, 0.031, 0.057, 0.078, 0.091, 0.084, 0.071, 0.05, 0.033, 0.066, 0.024, -0.039, -0.043,
|
||||
-0.062, -0.086, -0.078, -0.035, -0.041, 0.114, -0.004, 0.08, -0.043, 0.008, 0.035, 0.117, 0.075,
|
||||
0.091, -0.088, -0.074, -0.157, -0.187, 0.023, 0.023, 0.021, 0.021, 0.017, 0.002, -0.01, 0.054,
|
||||
0.037, 0.016, 0.058, -0.096, -0.292, 0.009, 0.007, -0.003, -0.011, -0.009, -0.005, -0.017,
|
||||
-0.031, -0.04, -0.029, -0.019, 0.007, 0.036, 0.064, 0.06, 0.091, 0.084, 0.021, 0.044, 0.024,
|
||||
0.007, 0.007, 0.006, -0.001, -0.004, -0.011, -0.026, -0.037, -0.048, -0.06, -0.057, -0.054,
|
||||
-0.051, -0.031, -0.014, -0.007
|
||||
],
|
||||
"slopeNorth": [
|
||||
-0.005, 0.005, -0.003, 0.002, -0.006, -0.016, -0.044, -0.027, -0.024, -0.026, -0.026, -0.026,
|
||||
-0.05, -0.054, 0.02, -0.042, -0.033, -0.022, -0.009, 0.008, 0.025, 0.032, 0.037, 0.003, 0.01,
|
||||
0.01, 0.013, 0.017, 0.026, 0.059, 0.018, -0.02, -0.039, 0.024, 0.024, 0.008, -0.005, -0.003,
|
||||
-0.06, -0.088, -0.024, -0.033, -0.037, -0.039, -0.046, -0.052, -0.026, -0.019, -0.023, -0.025,
|
||||
-0.027, -0.106, -0.113, -0.118, -0.111, -0.103, -0.016, -0.016, -0.129, -0.122, -0.096, -0.075,
|
||||
-0.046, -0.071, 0.056, 0.061, -0.108, -0.077, 0.028, 0.067, -0.029, -0.009, 0.048, -0.009,
|
||||
-0.029, -0.018, 0.006, 0.025, 0.144, 0.19, 0.17, 0.167, 0.149, -0.078, -0.083, -0.0, -0.081,
|
||||
-0.04, -0.001, -0.033, -0.082, -0.031, 0.061, 0.14, 0.078, 0.132, 0.104, 0.127, -0.011, -0.01,
|
||||
0.071, 0.129, 0.113, 0.103, 0.13, -0.038, -0.037, 0.044, 0.052, 0.016, 0.01, -0.01, -0.02,
|
||||
-0.014, 0.06, 0.086, 0.082, 0.067, 0.049, 0.051, 0.058, -0.08, -0.095, -0.099, -0.098, -0.093,
|
||||
-0.064, -0.024, 0.007, 0.03, 0.041, -0.085, -0.064, -0.021, -0.069, -0.063, -0.054, -0.027,
|
||||
0.013, 0.058, 0.082, 0.091, 0.065, 0.04, 0.085, 0.117, 0.139, 0.134, 0.059, 0.047, 0.008, 0.002,
|
||||
0.005, 0.01, 0.034, 0.039, 0.068, 0.077, -0.041, -0.017, -0.011, -0.017, -0.021, -0.021, -0.003,
|
||||
0.016, 0.034, -0.057, -0.046, -0.067, -0.062, -0.059, -0.032, -0.028, -0.023, -0.01, -0.01,
|
||||
-0.033, -0.028, -0.004, 0.019, -0.01, 0.056, 0.067, -0.061, -0.049, -0.108, -0.079, -0.0, 0.018,
|
||||
0.024, 0.053, 0.08, 0.085, -0.008, 0.015, 0.016, 0.027, 0.048, -0.05, -0.038, -0.058, -0.086,
|
||||
-0.001, -0.061, -0.038, -0.014, 0.027, 0.062, -0.036, -0.007, 0.046, -0.023, -0.001, 0.01,
|
||||
-0.073, 0.053, 0.073, -0.02, 0.004, -0.001, -0.014, -0.069, -0.016, -0.041, 0.001, 0.021,
|
||||
-0.017, -0.019, -0.115, -0.11, -0.083, -0.119, -0.097, -0.076, -0.101, -0.069, -0.054, -0.022,
|
||||
-0.045, -0.028, -0.016, -0.008, 0.019, -0.037, 0.005, 0.007, 0.01, -0.092, -0.096, -0.079,
|
||||
0.074, 0.07, -0.076, -0.025, -0.075, -0.039, 0.003, -0.006, 0.013, -0.03, -0.064, -0.079,
|
||||
-0.076, -0.056, -0.026, 0.042, -0.084, 0.038, 0.055, 0.002, 0.033, 0.01, -0.003, 0.001, -0.02,
|
||||
-0.041, -0.057, -0.056, -0.053, -0.045, -0.037, 0.043, 0.037, -0.023, -0.013, -0.012, 0.063,
|
||||
0.029, 0.024, 0.012, -0.007, 0.01, 0.006, -0.057, 0.007, -0.017, 0.02, 0.061, 0.058, 0.039,
|
||||
0.021, 0.001, -0.02, -0.025, -0.024, 0.039, 0.052, 0.03, 0.03, 0.028, 0.035, 0.003, 0.005,
|
||||
0.027, -0.048, -0.059, 0.005, -0.037, -0.029, -0.058, -0.066, -0.009, -0.02, 0.014, -0.009,
|
||||
-0.015, -0.01, -0.045, -0.036, -0.085, -0.017, 0.011, -0.052, 0.048, -0.025, -0.024, -0.035,
|
||||
-0.031, -0.05, -0.058, -0.013, -0.05, -0.053, -0.058, -0.033, -0.017, 0.001, -0.025, -0.066,
|
||||
-0.023, -0.014, -0.011, -0.059, -0.019, -0.009, 0.005, -0.007, -0.034, -0.051, 0.002, 0.036,
|
||||
0.0, 0.007, -0.022, -0.028, -0.046, -0.051, -0.018, -0.021, -0.013, 0.012, -0.005, -0.035,
|
||||
-0.036, 0.011, -0.065, 0.025, 0.006, 0.018, -0.103, 0.005, -0.007, -0.025, -0.061, -0.044,
|
||||
-0.049, -0.008, 0.004, -0.043, 0.022, -0.062, -0.019, -0.055, 0.001, -0.01, -0.057, -0.005,
|
||||
-0.051, -0.064, -0.023, 0.029, -0.044, 0.079, 0.066, -0.049, -0.043, 0.043, 0.037, 0.009, -0.04,
|
||||
-0.175, -0.046, -0.025, -0.055, -0.045, 0.01, -0.078, -0.036, -0.127, -0.126, -0.145, 0.102,
|
||||
0.094, -0.123, 0.055, -0.109, 0.133, -0.142, -0.009, -0.085, 0.067, 0.024, 0.056, -0.06, 0.156,
|
||||
0.025, -0.068, 0.018, -0.106, 0.077, 0.019, -0.02, -0.043, 0.021, -0.021, 0.053, -0.023, -0.091,
|
||||
-0.044, 0.016, 0.174, 0.024, 0.172, 0.213, -0.05, -0.021, -0.051, -0.255, 0.041, 0.076, -0.168,
|
||||
0.031, -0.153, -0.058, -0.022, 0.063, -0.084, -0.122, -0.153, -0.157, -0.171, 0.014, 0.054,
|
||||
0.036, 0.084, 0.009, 0.019, 0.018, -0.012, 0.013, 0.008, 0.011, 0.061, 0.061, 0.057, -0.013,
|
||||
-0.036, -0.024, -0.045, -0.046, -0.101, -0.156, -0.066, -0.239, -0.1, -0.077, -0.243, -0.08,
|
||||
0.073, 0.039, 0.179, 0.106, 0.005, 0.086, 0.044, 0.321, 0.232, 0.195, 0.145, -0.074, -0.069,
|
||||
-0.057, 0.021, -0.1, -0.165, 0.063, 0.139, 0.12, 0.091, 0.134, 0.082, 0.064, -0.056, -0.118,
|
||||
-0.146, -0.004, -0.123, -0.142, -0.092, -0.121, 0.172, 0.209, 0.083, -0.15, -0.088, -0.128,
|
||||
-0.152, -0.196, 0.004, -0.017, -0.027, -0.037, -0.042, 0.021, 0.014, 0.009, 0.003, 0.082, 0.074,
|
||||
0.061, 0.048, 0.031, 0.013, -0.006, 0.081, 0.074, 0.055, -0.036, 0.041, 0.024, 0.006, -0.068,
|
||||
-0.022, 0.073, 0.021, 0.055, 0.009, 0.022, 0.079, -0.019, 0.052, 0.08, 0.02, 0.073, 0.04, 0.01,
|
||||
0.224, 0.291, 0.218, -0.011, -0.137, -0.234, 0.091, 0.094, 0.095, 0.093, 0.062, 0.02, 0.061,
|
||||
0.003, 0.044, -0.063, 0.145, -0.012, -0.046, -0.011, 0.075, 0.117, 0.046, -0.033, 0.108, 0.084,
|
||||
-0.011, -0.094, -0.024, -0.13, 0.075, 0.1, 0.124, -0.018, -0.058, -0.136, -0.149, -0.227,
|
||||
-0.022, 0.105, 0.119, 0.113, 0.09, 0.076, 0.045, -0.045, 0.032, 0.029, 0.034, 0.051, 0.055,
|
||||
0.044, 0.028, -0.072, -0.095, -0.088, -0.06, -0.032, -0.005, 0.003, -0.016, -0.008, 0.039,
|
||||
0.085, 0.076, 0.061, 0.046, 0.035, 0.031, 0.022, 0.018, 0.014, 0.006, 0.014, 0.009, -0.002,
|
||||
-0.002, 0.003, -0.003, -0.024, -0.018, 0.068, 0.212, 0.049, 0.187, 0.06, 0.024, 0.003, -0.084,
|
||||
-0.173, 0.03, -0.138, -0.17, -0.157, 0.006, -0.007, -0.026, -0.034, -0.038, -0.045, 0.001,
|
||||
-0.075, -0.067, 0.237, 0.215, 0.109, 0.055, -0.068, -0.066, -0.059, -0.054, -0.059, -0.062,
|
||||
-0.065, -0.07, -0.072, -0.064, -0.054, -0.045, -0.035, -0.022, 0.059, 0.161, 0.071, 0.021,
|
||||
-0.021, -0.027, -0.033, -0.039, -0.044, -0.038, -0.029, -0.034, -0.057, -0.078, -0.075, -0.071,
|
||||
-0.076, -0.085, -0.083, -0.057, -0.03, -0.018
|
||||
]
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|||
import { atStandardTime } from './standardTime.testkit';
|
||||
import { baked } from '../../../sky/baked';
|
||||
import { AA, luminance } from '../../../sky/skyTokens.js';
|
||||
import { skyColours } from './ridge/skyColour';
|
||||
import { chooseSky, skyColour } from './terrain/terrainSky';
|
||||
import {
|
||||
DUSK_SUN_ELEVATION,
|
||||
|
|
@ -78,10 +77,9 @@ describe('the bands the text ink needs', () => {
|
|||
});
|
||||
|
||||
describe('ridgeSkyFor', () => {
|
||||
it('carries the state band, which the layers are shaped into, and the physical sky of that state', () => {
|
||||
it('carries the physical sky of the state', () => {
|
||||
for (const state of STATES) {
|
||||
const sky = ridgeSkyFor(state, 0.3);
|
||||
expect(sky.band).toEqual(SKY_BAND[state]);
|
||||
expect(sky.physical?.state).toBe(state);
|
||||
expect(sky.physical?.stops).toEqual({ top: sky.top, mid: sky.mid, horizon: sky.horizon });
|
||||
}
|
||||
|
|
@ -92,7 +90,6 @@ describe('ridgeSkyFor', () => {
|
|||
s.top,
|
||||
s.mid,
|
||||
s.horizon,
|
||||
s.band,
|
||||
s.physical?.sun,
|
||||
];
|
||||
setSkyClock(() => atStandardTime(12, 0));
|
||||
|
|
@ -110,7 +107,6 @@ describe('ridgeSkyFor', () => {
|
|||
const dusk = ridgeSkyFor('dusk', 0);
|
||||
expect(Math.abs(dusk.physical?.sun.elevation ?? 99)).toBeLessThanOrEqual(DAY_FROM);
|
||||
expect(ridgeSkyFor('night', 0).physical?.sun.elevation).toBeLessThanOrEqual(-DAY_FROM);
|
||||
expect(day.ground).toEqual(skyColours().ground);
|
||||
});
|
||||
|
||||
it('keys a rebuild by state and weather, not by the moving sun', () => {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { baked } from '../../../sky/baked';
|
|||
import { chooseSky, skyColour, urlSky } from './terrain/terrainSky';
|
||||
import type { SkyName } from './terrain/terrainSky';
|
||||
import type { SkyColours, Srgb } from './ridge/skyColour';
|
||||
import { skyColours } from './ridge/skyColour';
|
||||
import { makePhysicalSky } from './ridge/physicalSky';
|
||||
import { BUDGET } from './ridge/toneMap';
|
||||
import { ridgeWeather, setFedWeather } from './ridge/weather';
|
||||
|
|
@ -54,13 +53,10 @@ export function ridgeSkyFor(
|
|||
weather: number = ridgeWeather(),
|
||||
now: Date = skyNow()
|
||||
): SkyColours {
|
||||
const { ground } = skyColours();
|
||||
const fixed = resolveSkyState(state, now);
|
||||
const physical = makePhysicalSky(fixed, now, weather);
|
||||
return {
|
||||
...physical.stops,
|
||||
ground,
|
||||
band: SKY_BAND[fixed],
|
||||
physical,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue