diff --git a/harness/scene/README.md b/harness/scene/README.md index d3981fa6..217e2241 100644 --- a/harness/scene/README.md +++ b/harness/scene/README.md @@ -21,6 +21,12 @@ directory whose ancestors hold no empty `package.json` (esbuild reads them). Timings from SwiftShader are CPU time: use them for the split between passes and for before and after of one change, never as a phone frame time. +## Ridge live scene + +`ridgeLive.html` is one live scene (tier 'full', the sky plate and the cards on the compositor) filling the window, for a driver to turn and screenshot: `?h=214&sun=232:22&speed=6` (start heading, the sun's azimuth and elevation, degrees a second of rotation), +`?sky=night&lines=1`. `window.live` offers `hold(h)`, `pose()`, `plate()`, `left()` (the plate's left edge on the page) and `plateCost()` (ms of main thread to paint one plate here); `window.longTasks` lists the tasks over 50 ms. +A held heading's sun lands within a tenth of a pixel of the column the heading owner says, across re-centres of the plate. + ## Ridge look sheet Renders a baked place (`?place=`, the index default otherwise) lit for six sky states (dawn 2, morning 15, noon 55, golden 6, dusk -3, night -30 degrees of sun) @@ -30,6 +36,8 @@ behind a cell is the app's own, without clouds. Not shipped. ...ridgeSheet.html?views=214:0:200,0:0:200,214:90:98.2&sky=2 # one column per view heading:phi:offset (degrees, degrees, metres) at one sky (an index of SKIES) +`&sun=100:6` puts the sun of that sky at compass azimuth 100, 6 degrees up (the stars are those of the moment the sheet is opened): a sun at the heading's side shows where the turned sky puts it, `&sky=5&lines=1` is the night. + A heading of 0 or 360 is across north; a phi other than 0 is the offset-only rotation mode (the camera circling the centre, the view direction staying); the offset is clamped to the place's range as the app does (phi 0: `camera.r_max_forward_m`, another phi: `camera.r_max_m`). diff --git a/harness/scene/ridgeLive.html b/harness/scene/ridgeLive.html new file mode 100644 index 00000000..fba96a06 --- /dev/null +++ b/harness/scene/ridgeLive.html @@ -0,0 +1,8 @@ + + + +Ridge live scene + +
+ + diff --git a/harness/scene/ridgeLive.ts b/harness/scene/ridgeLive.ts new file mode 100644 index 00000000..3fb40a33 --- /dev/null +++ b/harness/scene/ridgeLive.ts @@ -0,0 +1,71 @@ +// One live ridge scene (tier 'full': the sky plate and the cards on the compositor) filling the window, for a driver to turn and screenshot. Not shipped. +// `?h=214` the heading the scene starts at; `?sun=232:22` the sun's compass azimuth and elevation (degrees); `?sky=night` the stars of now (sun below the horizon); `?lines=1` the constellation lines. +// `?speed=6` degrees a second the view turns (rotation mode 'both'); 0 holds it. The page offers `window.live`: `hold(h)` turns the view by hand, `pose()` is the heading owner's pose now, +// `plate()` the sky plate's element and `left()` its left edge and width on the page. +import { parseManifest } from '../../src/app/features/scene/ridge/manifest'; +import { makePhysicalSky } from '../../src/app/features/scene/ridge/physicalSky'; +import { createBackdrop } from '../../src/app/features/scene/ridge/Backdrop'; +import { createRidgeScene } from '../../src/app/features/scene/ridge/Ridge'; +import { anchor, hold, poseAt } from '../../src/app/features/scene/ridge/heading'; +import { setCamera } from '../../src/app/features/scene/cameraState'; +import { HFOV_MAX_DEG, windowFor } from '../../src/app/features/scene/ridge/view'; +import { paintSky } from '../../src/app/features/scene/ridge/physicalSky'; +import { nightBodies } from '../../src/app/features/scene/ridge/nightBodies'; +import { plateCamera, plateSize } from '../../src/app/features/scene/ridge/skyTurn'; + +const q = new URLSearchParams(location.search); +/** The main-thread tasks over 50 ms the page saw, ms: `window.longTasks`. */ +const longTasks: number[] = []; +(window as unknown as { longTasks: number[] }).longTasks = longTasks; +try { + new PerformanceObserver((l) => l.getEntries().forEach((e) => longTasks.push(e.duration))).observe({ entryTypes: ['longtask'] }); +} catch { + // No long-task entries in this browser. +} + +async function main() { + const index = await (await fetch('/public/ridge/index.json')).json(); + const dir = `/public/ridge/${index.places[q.get('place') ?? index.default]}/`; + const manifest = parseManifest(await (await fetch(`${dir}manifest.json`)).json(), dir); + const { view } = manifest; + const [az, el] = (q.get('sun') ?? '232:22').split(':').map(Number); + const time = new Date(); + const sun = q.get('sky') === 'night' ? { azimuth: 0, elevation: -30, time } : { azimuth: az, elevation: el, time }; + const physical = makePhysicalSky(sun, 0, view); + const h0 = Number(q.get('h') ?? view.lookAzDeg); + anchor(view.place.id, h0, performance.now()); + setCamera({ mode: 'both', speedDegPerS: Number(q.get('speed') ?? 0), offsetM: 200 }); + const backdrop = createBackdrop(manifest, physical); + await backdrop.ensure({ fromDeg: h0 - HFOV_MAX_DEG, toDeg: h0 + HFOV_MAX_DEG }); + const canvas = document.getElementById('c') as HTMLCanvasElement; + const scene = createRidgeScene({ canvas, tier: 'full', sky: { ...physical.stops, physical }, backdrop, lines: q.get('lines') === '1' }); + const host = document.getElementById('host') as HTMLElement; + // The plate is the host's div whose first child is a canvas (the rig's first child is a div, the rain's has none). + const plate = () => [...host.children].find((c) => c.tagName === 'DIV' && c.firstElementChild?.tagName === 'CANVAS'); + (window as unknown as { live: unknown }).live = { + scene, + hold: (h: number) => hold(h, performance.now()), + pose: () => poseAt(performance.now()), + plate, + /** Mean ms of the main-thread part of painting one plate here (the dome, its pixels and the bodies, not the canvas upscale), over `n` runs. */ + plateCost: (n = 10) => { + const w = innerWidth; + const h = innerHeight; + const win = windowFor(view, w, h); + const { cssW } = plateSize(win, w, h, devicePixelRatio >= 2 ? 2 : 1); + const t0 = performance.now(); + for (let i = 0; i < n; i += 1) nightBodies(physical, paintSky(physical, cssW, h, plateCamera(win, 214 + i)), true); + return (performance.now() - t0) / n; + }, + left: () => { + const r = plate()?.getBoundingClientRect(); + return r && { left: r.left, width: r.width }; + }, + }; + document.title = 'ridge live: done'; +} + +main().catch((e) => { + console.error(e); + document.title = `ridge live: failed ${e}`; +}); diff --git a/harness/scene/ridgeSheet.ts b/harness/scene/ridgeSheet.ts index 79671f38..440a3a57 100644 --- a/harness/scene/ridgeSheet.ts +++ b/harness/scene/ridgeSheet.ts @@ -1,7 +1,7 @@ // Look sheet for the lit ridge cards: a baked place lit for a grid of sky states (or pinned moments) x looks, each cell a small canvas drawn by the app's own still path // (`createRidgeScene` at tier 'still', the tiles of the arc round the heading, each card at `cardPose`). Not shipped. // `?views=214:0:200,0:0:200,100:0:200,214:90:98.2` one column per view `heading:phi:offset` (degrees, degrees, metres) at one sky (`?sky=2`, an index of SKIES, noon by default); a heading -// of 360 or 0 is across north. The offset is clamped to the place's range as the app does (phi 0: the bake's forward bound, any other phi: the worst-case bound), and a phi other than 0 is the offset-only rotation mode, the camera circling the centre. +// of 360 or 0 is across north. `&sun=100:6` puts the sun of that sky at azimuth 100, 6 degrees up (the stars are always those of the moment the sheet is opened). The offset is clamped to the place's range as the app does (phi 0: the bake's forward bound, any other phi: the worst-case bound), and a phi other than 0 is the offset-only rotation mode, the camera circling the centre. // `?place=vienna` the baked place (index.json's default if absent) // `?preset=all|physical|swiss|poster|painterly|painterly-cel-2|painterly-cel-3|painterly-cel-4` (default all: one row each; painterly is DEFAULT_LOOK); `?looks=` replaces the rows with // the given `{label, ...partial RidgeLook}` entries (inkKeep and reliefLight merge by key). `?w=480` sets the cell width, 16:9 unless `?h=` gives the height (`?w=375&h=812` is a phone). @@ -171,11 +171,12 @@ function momentsFrom(params: URLSearchParams, place: Parameters[0] }); return cols; } -/** `?views=h:phi:r,...`: one column per view, all at the sky `?sky=` (default noon). */ +/** `?views=h:phi:r,...`: one column per view, all at the sky `?sky=` (default noon), whose sun `?sun=az:el` may put elsewhere (compass degrees, degrees above the horizon). */ function viewsFrom(params: URLSearchParams): Column[] | undefined { const list = params.get('views'); if (!list) return undefined; - const sky = SKIES[Number(params.get('sky') ?? 2)]; + const [az, el] = (params.get('sun') ?? '').split(':').map(Number); + const sky = { ...SKIES[Number(params.get('sky') ?? 2)], ...(Number.isFinite(az) && Number.isFinite(el) ? { azimuth: az, elevation: el } : {}) }; return list.split(',').map((v) => { const [h, phi, r] = v.split(':').map(Number); return { ...sky, label: `h ${h} phi ${phi} r ${r}`, view: { h, phi, r } }; diff --git a/src/app/features/scene/README.md b/src/app/features/scene/README.md index 8fc215bd..8fa17001 100644 --- a/src/app/features/scene/README.md +++ b/src/app/features/scene/README.md @@ -5,14 +5,17 @@ config says `backgroundScene.style: 'raymarch'`; the tier flag still defaults to means "keep the CSS ground". Everything below this section describes the opt-in ray-march scene. - `ridge/Ridge.ts` `createRidgeScene({ canvas, tier, probe?, onProbe?, sky?, backdrop? })` 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`), the lit ridge cards (below) and, when it rains, tiled rain streaks slid down on the compositor (`ridge/rain.ts`). - With no cards (the load failed) 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 + null (tier `off`, no 2D context). It paints the sky (`ridge/physicalSky.ts`, from the `SkyColours` the host passes) into a sky plate (`ridge/skyTurn.ts`): one element over the host + canvas, the viewport's width plus 20 degrees of sky each side, centred on the heading `heading.ts` owns, holding the sky with the real stars, the moon and the lines baked into it and a + twinkle canvas for the swinging stars (`ridge/stars.ts`) over it. The sky is at infinity, so one animation slides the plate by the heading's turn at the cards' px per degree, on the + same keyframes as the cards; a residency tick or a reissue paints a new plate about the heading once it is within 14 degrees of the plate's edge and swaps it in the same tick + (the same sky at the same screen place, so nothing moves; the plate's backing store is capped at 3 Mpx, the pixel ratio lowering before the plate shrinks). Then come the lit ridge + cards (below) and, when it rains, tiled rain streaks slid down on the compositor (`ridge/rain.ts`). A sky with no physical model is a gradient in the host canvas. + With no cards (the load failed) the scene shows the sky, stars and weather only, the plate facing the place's rest azimuth and staying. No script runs per frame except the twinkle, at most every 50 ms. + The host canvas and its parent must be positioned and the parent must clip (the plate is wider than the viewport); 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. + `tier: 'still'` paints the sky (facing the heading its pose froze at) and stars into the host canvas and adds no plate, 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 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. @@ -37,7 +40,7 @@ means "keep the CSS ground". Everything below this section describes the opt-in what the baked resident count sustains, applied to the stored choice). `cameraState.ts` is the one owner of the viewer's mode, speed and offset in `ratatoskr.camera`; `heading.ts` owns the view's pose, the direction, the camera's angle over it and its offset, as one segment (module state: the pose at a clock, the mode and speed in force and the ease to the pose the choices owe; any change of a choice, a hold, a bound or reduced motion starts a new segment from the pose it has at that clock, `poseAt(t)` is a pure function of it, and a mode pick eases the angle and the offset one after the other, 300 ms each, in the order that keeps every pose inside the bound; `cameraState.ts` hands it each change synchronously before its listeners and keeps no log; `view.ts` `offsetRange`, given to it by the scene, is the one clamp; angles are normalized into [0, 360) before each stretch so nothing grows with uptime; a manual `hold` sets the mode to still, so a rebuild or a reload keeps it). The motion is one `Element.animate` per card (transform only, a keyframe each second for 30 s and every 50 ms while an ease runs, reissued at 80% and on any change; paused when the tab is hidden or motion is reduced, then constant); a 500 ms timer asks the backdrop for - the arc every pose of the next 30 s passes over (`view.ts` `sweepArc`, sampled four times a second, not its two ends) and mounts the tiles it has made. A still draws the tiles of the arc into the host canvas at the heading now. The sky does not turn with the heading. A failure + the arc every pose of the next 30 s passes over (`view.ts` `sweepArc`, sampled four times a second, not its two ends) and mounts the tiles it has made. A still draws the sky and the tiles of the arc into the host canvas at the heading now. A failure anywhere (404, a manifest that is not schema 3, no tile that will decode, no WebGL2, a lighting pass that throws) is the sky-only scene on `FALLBACK_VIEW`, told to the host by the live scene alone, through `onPlanesFail` when the live scene has no cards and `onPlanesOk` when a later one has them (never from a stale or disposed build); it is never `onCompileFail`. `vite.config.js` copies `public/ridge` into `dist/public/`.