diff --git a/harness/scene/ridgeSheet.ts b/harness/scene/ridgeSheet.ts index d5cf3d00..a4f66637 100644 --- a/harness/scene/ridgeSheet.ts +++ b/harness/scene/ridgeSheet.ts @@ -1,12 +1,20 @@ -// Look sheet for the lit ridge cards: the Vienna bake lit for a grid of sky states x looks, each cell a small canvas at heading 0. Not shipped. +// Look sheet for the lit ridge cards: the Vienna bake lit for a grid of sky states (or pinned moments) x looks, each cell a small canvas at heading 0. Not shipped. // `?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). -// The sky behind a cell is the app's own: `makePhysicalSky` + `paintSky` upscaled smoothly, without the sun disc, stars or clouds. +// The sky behind a cell is the app's own: `makePhysicalSky` + `paintSky` upscaled smoothly, with the real stars and the moon (`nightBodies`), +// without the sun disc or clouds. Columns are the SKIES below (a sun elevation each, the stars and moon of the moment the sheet was opened), or: +// `?moments=2026-11-24T22:00Z,2026-12-09T20:00Z` explicit UTC moments: the sun, moon and stars are those of the moment, the state follows the sun's elevation +// `?night=1` the night set: the next new moon, first quarter and full moon from today (or from `?from=YYYY-MM-DD`), each at four night hours +// (`?hours=18,21,0,4` UTC), plus deep dusk (sun at -10 degrees) of the evening of the full moon +// `?lines=1` constellation lines over the stars, as the Sky menu's hidden toggle does (night cells only) import { DEFAULT_LOOK, PHYSICAL_LOOK, lightCards } from '../../src/app/features/scene/ridge/lightCards'; import type { RidgeLook } from '../../src/app/features/scene/ridge/lightCards'; import { parseManifest } from '../../src/app/features/scene/ridge/manifest'; import { makePhysicalSky, paintSky } from '../../src/app/features/scene/ridge/physicalSky'; import { windowFor } from '../../src/app/features/scene/ridge/view'; +import { nightBodies, paintNightBodies } from '../../src/app/features/scene/ridge/nightBodies'; +import { sunAt } from '../../src/app/features/scene/ridge/sunAt'; +import { moonPhase } from '../../src/sky/moon.js'; import { DAY_FROM } from '../../src/app/features/scene/skyState'; import type { FixedSkyState } from '../../src/app/features/scene/skyState'; @@ -20,8 +28,16 @@ type Override = Partial> & { reliefLight?: Partial; }; +interface Column { + label: string; + elevation?: number; + azimuth?: number; + /** A moment: the sun is the real one of it. */ + time?: Date; +} + /** Sun elevation and compass azimuth of each column; the cards look at 214 +- 36. Elevation picks the display budget (day from DAY_FROM, night below its negative). */ -const SKIES = [ +const SKIES: Column[] = [ { label: 'dawn 2 deg', elevation: 2, azimuth: 100 }, { label: 'morning 15 deg', elevation: 15, azimuth: 135 }, { label: 'noon 55 deg', elevation: 55, azimuth: 190 }, @@ -86,13 +102,68 @@ function parseLooks(raw: string): Override[] { } const q = new URLSearchParams(location.search); + +const HOUR = 3_600_000; +/** The first moment at or after `from` the moon's elongation passes `target` degrees (new 0, first quarter 90, full 180). */ +function nextPhase(from: Date, target: number): Date { + const err = (t: number) => ((moonPhase(t).elongationDeg - target + 540) % 360) - 180; + let t = from.getTime(); + while (!(err(t) < 0 && err(t + HOUR) >= 0)) t += HOUR; + let a = t; + let b = t + HOUR; + for (let i = 0; i < 20; i += 1) { + const m = (a + b) / 2; + if (err(m) < 0) a = m; + else b = m; + } + return new Date(b); +} + +/** The first evening moment (UTC hour steps of 10 minutes from `day`) the sun is at `deg` below the horizon, going down. */ +function sunDownTo(place: Parameters[0], day: Date, deg: number): Date { + let t = Date.UTC(day.getUTCFullYear(), day.getUTCMonth(), day.getUTCDate(), 12); + while (sunAt(place, new Date(t)).elevation > -deg) t += 10 * 60_000; + return new Date(t); +} + +const fmt = (d: Date) => d.toISOString().slice(0, 16).replace('T', ' ') + 'Z'; + +function momentsFrom(params: URLSearchParams, place: Parameters[0]): Column[] | undefined { + const list = params.get('moments'); + if (list) + return list.split(',').map((iso) => { + const time = new Date(iso.trim()); + if (Number.isNaN(time.getTime())) throw new Error(`moments=: ${iso} is not a date`); + return { label: fmt(time), time }; + }); + if (!params.get('night')) return undefined; + const from = params.get('from') ? new Date(`${params.get('from')}T00:00:00Z`) : new Date(); + const hours = (params.get('hours') ?? '18,21,0,4').split(',').map(Number); + const cols: Column[] = []; + const phases: [string, number][] = [['new', 0], ['first quarter', 90], ['full', 180]]; + phases.forEach(([name, deg]) => { + const peak = nextPhase(from, deg); + const day = Date.UTC(peak.getUTCFullYear(), peak.getUTCMonth(), peak.getUTCDate()); + hours.forEach((h) => { + // Hours before 12 belong to the night that ends the day of the phase, so the hours run on from the evening. + const time = new Date(day + (h < 12 ? 24 + h : h) * HOUR); + cols.push({ label: `${name} ${fmt(time)}`, time }); + }); + if (deg === 180) cols.push({ label: `deep dusk, full moon ${fmt(sunDownTo(place, peak, 10))}`, time: sunDownTo(place, peak, 10) }); + }); + return cols; +} const preset = q.get('preset'); +const pinned = q.get('moments') || q.get('night'); const rows = (q.get('looks') ? parseLooks(q.get('looks') as string) : preset && preset !== 'all' ? [PRESETS[preset] ?? PRESETS.physical] + : pinned + ? [PRESETS.painterly] // a night set is read in the default look unless a preset or looks say otherwise : Object.values(PRESETS) ).map(merge); +const withLines = q.get('lines') === '1'; const W = Number(q.get('w') ?? 480); const H = Math.round((W * 9) / 16); const root = document.getElementById('sheet') as HTMLElement; @@ -113,26 +184,29 @@ async function main() { const { view } = manifest; const win = windowFor(view, W, H); const now = new Date(); + const columns = momentsFrom(q, view.place) ?? SKIES; const table = document.createElement('table'); table.style.borderSpacing = '4px'; root.append(table); const head = table.insertRow(); head.insertCell(); - SKIES.forEach((s) => (head.insertCell().textContent = s.label)); + columns.forEach((c) => (head.insertCell().textContent = c.label)); const tr = rows.map((r) => { const row = table.insertRow(); row.insertCell().textContent = r.label; return row; }); - for (const sky of SKIES) { - const physical = makePhysicalSky(stateOf(sky.elevation), now, 0, view, { - elevation: sky.elevation, - azimuth: sky.azimuth, - time: now, - }); + for (const col of columns) { + const time = col.time ?? now; + const sun = + col.time !== undefined + ? sunAt(view.place, col.time) + : { elevation: col.elevation as number, azimuth: col.azimuth as number, time }; + const physical = makePhysicalSky(stateOf(sun.elevation), time, 0, view, sun); const px = paintSky(physical, W, H, win.camera); + const bodies = nightBodies(physical, px, withLines); const small = document.createElement('canvas'); small.width = px.w; small.height = px.h; @@ -155,6 +229,7 @@ async function main() { const ctx = cell.getContext('2d') as CanvasRenderingContext2D; ctx.imageSmoothingQuality = 'high'; ctx.drawImage(small, 0, 0, W, H); + paintNightBodies(ctx, bodies, W, H, 1); // As Ridge.ts paintCards at heading 0: farthest first, each card at its own scale about the horizon row of the plane. const s = win.plane.scale; const x0 = (W - win.plane.w) / 2; diff --git a/src/app/features/scene/ridge/nightSky.ts b/src/app/features/scene/ridge/nightSky.ts index 4bc63293..3137511d 100644 --- a/src/app/features/scene/ridge/nightSky.ts +++ b/src/app/features/scene/ridge/nightSky.ts @@ -42,9 +42,9 @@ export const NIGHT_LOOK = { /** Natural night-sky radiance at the zenith without moon or town, cd/m^2 (about 22 V mag/arcsec^2: 2.5e-4). */ export const AIRGLOW_CD = 2.5e-4; -/** Its colour, linear, luminance 1 (a faint cool green-blue). EYEBALLED. */ -const AIRGLOW_TINT: Vec3 = [0.8, 1, 1.35]; -const AIRGLOW_NORM = 0.2126 * 0.8 + 0.7152 + 0.0722 * 1.35; +/** Its colour, linear, luminance 1 (a faint cool grey). EYEBALLED. */ +const AIRGLOW_TINT: Vec3 = [0.95, 1, 1.1]; +const AIRGLOW_NORM = 0.2126 * 0.95 + 0.7152 + 0.0722 * 1.1; /** The airglow floor, per unit of sun irradiance, at view elevation sine `vz` (brighter toward the horizon, van Rhijn). */ export function airglow(vz: number, out: number[]): void { diff --git a/src/app/features/scene/ridge/toneMap.test.ts b/src/app/features/scene/ridge/toneMap.test.ts index 536c0b1c..d27cc979 100644 --- a/src/app/features/scene/ridge/toneMap.test.ts +++ b/src/app/features/scene/ridge/toneMap.test.ts @@ -79,7 +79,7 @@ describe('the night display', () => { }); it('reads the new-moon night darker than the full-moon night (partial adaptation), by the level of the budget', () => { - const med = (p: ReturnType) => applyCurve(p.fit.display.curve, 0.5); + const med = (p: ReturnType) => applyCurve(p.fit.display.curve, p.fit.display.curve.x[2]); // the median of the sky expect(med(newMoon)).toBeLessThan(0.6 * med(fullMoon)); }); diff --git a/src/app/features/scene/ridge/toneMap.ts b/src/app/features/scene/ridge/toneMap.ts index a33b7c92..c82379b2 100644 --- a/src/app/features/scene/ridge/toneMap.ts +++ b/src/app/features/scene/ridge/toneMap.ts @@ -150,7 +150,9 @@ export const BUDGET: Record = { floor: NIGHT_LIFT - 0.001, lift: NIGHT_LIFT, ceiling: NIGHT_CEILING, - key: 0.45, + // The key sits at the targets (not day's 0.45): the sky is exposed to where the curve wants it, so the curve is near the identity over it and + // the per-channel curve does not blow a small colour difference (the scotopic blue shift) up into a saturated sky. + key: 0.03, min: 4, max: 1e13, targets: [0.012, 0.03, 0.07],