Harness: ridge look sheet (sky states x looks, four art-direction presets)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d4be09c2b2
commit
fa8f2a163b
3 changed files with 217 additions and 0 deletions
|
|
@ -20,3 +20,27 @@ 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 look sheet
|
||||
|
||||
Renders the Vienna cards (`public/ridge/vienna-6815bb9dca99`) lit for six sky states (dawn 2, morning 15, noon 55, golden 6, dusk -3, night -30 degrees of sun)
|
||||
by a set of looks (`RidgeLook`, `src/app/features/scene/ridge/lightCards.ts`, the one owner of look values), one 480x270 canvas per cell at heading 0. The sky
|
||||
behind a cell is the app's own (`makePhysicalSky` + `paintSky`, upscaled), without the sun disc, stars or clouds. Not shipped.
|
||||
|
||||
npx vite --port 5199 # from the repo root; the app's vite config serves the page and public/
|
||||
http://localhost:5199/harness/scene/ridgeSheet.html # four presets x six skies
|
||||
...ridgeSheet.html?preset=swiss # one preset (physical|swiss|poster|painterly)
|
||||
...ridgeSheet.html?looks=%5B%7B%22label%22%3A%22no-ink%22%2C%22inkScale%22%3A0%7D%2C%7B%22label%22%3A%22hazy%22%2C%22hazeScale%22%3A8%7D%5D
|
||||
...?w=640 # cell width
|
||||
|
||||
`looks=` is a url-encoded or base64 JSON array of `{label, ...partial RidgeLook}` and replaces the preset rows (`inkKeep` and `reliefLight` merge by key).
|
||||
A cell costs one WebGL2 context and a card decode, so the full sheet takes tens of seconds (much longer in a background tab).
|
||||
|
||||
Presets (`PRESETS` in `ridgeSheet.ts`; every key not named is `DEFAULT_LOOK`), chosen by reasoning, not by eye, for Self to tune:
|
||||
|
||||
| preset | values |
|
||||
| --- | --- |
|
||||
| physical | DEFAULT_LOOK |
|
||||
| swiss | reliefLight {mix 0.7, azimuthDeg -45, elevationDeg 40}, contrastByDistance 0.9, hazeScale 6, hazeTint [0, 0.05, 0.25], nearWarm 0.5, inkScale 0.6 |
|
||||
| poster | reliefWeight 0.15, cardToneStep 0.25, cardGradient 0.5, inkKeep {edge 0.25, occlude 0.9, crease 1}, hazeScale 4 |
|
||||
| painterly | groundNoise 0.35, cloudShadows 0.5, nearWarm 0.6, hazeScale 2, inkScale 0.4 |
|
||||
|
|
|
|||
8
harness/scene/ridgeSheet.html
Normal file
8
harness/scene/ridgeSheet.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Ridge look sheet</title>
|
||||
<body style="margin:0;background:#111;color:#ddd;font:12px monospace">
|
||||
<div id="sheet" style="padding:8px"></div>
|
||||
<script type="module" src="./ridgeSheet.ts"></script>
|
||||
</body>
|
||||
185
harness/scene/ridgeSheet.ts
Normal file
185
harness/scene/ridgeSheet.ts
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
// 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.
|
||||
// `?preset=all|physical|swiss|poster|painterly` (default all: the four rows); `?looks=<JSON array, url-encoded or base64>` 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.
|
||||
import { DEFAULT_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 { DAY_FROM } from '../../src/app/features/scene/skyState';
|
||||
import type { FixedSkyState } from '../../src/app/features/scene/skyState';
|
||||
|
||||
const DIR = '/public/ridge/vienna-6815bb9dca99/';
|
||||
|
||||
type Override = Partial<Omit<RidgeLook, 'inkKeep' | 'reliefLight'>> & {
|
||||
label: string;
|
||||
inkKeep?: Partial<RidgeLook['inkKeep']>;
|
||||
reliefLight?: Partial<RidgeLook['reliefLight']>;
|
||||
};
|
||||
|
||||
/** 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 = [
|
||||
{ label: 'dawn 2 deg', elevation: 2, azimuth: 100 },
|
||||
{ label: 'morning 15 deg', elevation: 15, azimuth: 135 },
|
||||
{ label: 'noon 55 deg', elevation: 55, azimuth: 190 },
|
||||
{ label: 'golden 6 deg', elevation: 6, azimuth: 244 },
|
||||
{ label: 'dusk -3 deg', elevation: -3, azimuth: 262 },
|
||||
{ label: 'night -30 deg', elevation: -30, azimuth: 0 },
|
||||
];
|
||||
|
||||
/** The art directions, chosen by reasoning, not by eye: Self tunes them (values listed in harness/scene/README.md). */
|
||||
const PRESETS: Record<string, Override> = {
|
||||
physical: { label: 'physical' },
|
||||
swiss: {
|
||||
label: 'swiss',
|
||||
reliefLight: { mix: 0.7, azimuthDeg: -45, elevationDeg: 40 },
|
||||
contrastByDistance: 0.9,
|
||||
hazeScale: 6,
|
||||
hazeTint: [0, 0.05, 0.25],
|
||||
nearWarm: 0.5,
|
||||
inkScale: 0.6,
|
||||
},
|
||||
poster: {
|
||||
label: 'poster',
|
||||
reliefWeight: 0.15,
|
||||
cardToneStep: 0.25,
|
||||
cardGradient: 0.5,
|
||||
inkKeep: { edge: 0.25, occlude: 0.9, crease: 1 },
|
||||
hazeScale: 4,
|
||||
},
|
||||
painterly: {
|
||||
label: 'painterly',
|
||||
groundNoise: 0.35,
|
||||
cloudShadows: 0.5,
|
||||
nearWarm: 0.6,
|
||||
hazeScale: 2,
|
||||
inkScale: 0.4,
|
||||
},
|
||||
};
|
||||
|
||||
const merge = (o: Override): { label: string; look: RidgeLook } => {
|
||||
const { label, inkKeep, reliefLight, ...rest } = o;
|
||||
return {
|
||||
label,
|
||||
look: {
|
||||
...DEFAULT_LOOK,
|
||||
...rest,
|
||||
inkKeep: { ...DEFAULT_LOOK.inkKeep, ...inkKeep },
|
||||
reliefLight: { ...DEFAULT_LOOK.reliefLight, ...reliefLight },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
function parseLooks(raw: string): Override[] {
|
||||
const tries = [() => decodeURIComponent(raw), () => atob(raw.replace(/-/g, '+').replace(/_/g, '/'))];
|
||||
for (const t of tries) {
|
||||
try {
|
||||
const v = JSON.parse(t());
|
||||
if (Array.isArray(v)) return v.map((e, i) => ({ label: `look ${i + 1}`, ...e }));
|
||||
} catch {
|
||||
// try the next encoding
|
||||
}
|
||||
}
|
||||
throw new Error('looks= is neither a url-encoded nor a base64 JSON array');
|
||||
}
|
||||
|
||||
const q = new URLSearchParams(location.search);
|
||||
const preset = q.get('preset');
|
||||
const rows = (q.get('looks')
|
||||
? parseLooks(q.get('looks') as string)
|
||||
: preset && preset !== 'all'
|
||||
? [PRESETS[preset] ?? PRESETS.physical]
|
||||
: Object.values(PRESETS)
|
||||
).map(merge);
|
||||
const W = Number(q.get('w') ?? 480);
|
||||
const H = Math.round((W * 9) / 16);
|
||||
const root = document.getElementById('sheet') as HTMLElement;
|
||||
|
||||
const stateOf = (el: number): FixedSkyState =>
|
||||
el >= DAY_FROM ? 'day' : el <= -DAY_FROM ? 'night' : 'dusk';
|
||||
|
||||
async function main() {
|
||||
const manifest = parseManifest(await (await fetch(`${DIR}manifest.json`)).json(), DIR);
|
||||
const blobs = await Promise.all(
|
||||
manifest.cards.map(async (c) => ({
|
||||
colour: await (await fetch(`${DIR}${c.colour}`)).blob(),
|
||||
geometry: await (await fetch(`${DIR}${c.geometry}`)).blob(),
|
||||
}))
|
||||
);
|
||||
const decode = (b: Blob) =>
|
||||
createImageBitmap(b, { premultiplyAlpha: 'none', colorSpaceConversion: 'none' });
|
||||
const { view } = manifest;
|
||||
const win = windowFor(view, W, H);
|
||||
const now = new Date();
|
||||
|
||||
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));
|
||||
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,
|
||||
});
|
||||
const px = paintSky(physical, W, H, win.camera);
|
||||
const small = document.createElement('canvas');
|
||||
small.width = px.w;
|
||||
small.height = px.h;
|
||||
const sctx = small.getContext('2d') as CanvasRenderingContext2D;
|
||||
const img = sctx.createImageData(px.w, px.h);
|
||||
img.data.set(px.data);
|
||||
sctx.putImageData(img, 0, 0);
|
||||
|
||||
for (let r = 0; r < rows.length; r += 1) {
|
||||
const bitmaps = await Promise.all(
|
||||
blobs.map(async (b) => ({
|
||||
colour: await decode(b.colour),
|
||||
geometry: await decode(b.geometry),
|
||||
}))
|
||||
);
|
||||
const cards = lightCards(manifest, bitmaps, physical, rows[r].look);
|
||||
const cell = document.createElement('canvas');
|
||||
cell.width = W;
|
||||
cell.height = H;
|
||||
const ctx = cell.getContext('2d') as CanvasRenderingContext2D;
|
||||
ctx.imageSmoothingQuality = 'high';
|
||||
ctx.drawImage(small, 0, 0, W, H);
|
||||
// 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;
|
||||
const planeTop = H - win.plane.h;
|
||||
const ox = x0 + win.plane.w / 2;
|
||||
const oy = planeTop + view.horizonRow * s;
|
||||
for (let k = cards.length - 1; k >= 0; k -= 1) {
|
||||
ctx.save();
|
||||
ctx.translate(ox, oy);
|
||||
ctx.scale(cards[k].scale, cards[k].scale);
|
||||
ctx.drawImage(
|
||||
cards[k].canvas,
|
||||
x0 - ox,
|
||||
planeTop + cards[k].top * s - oy,
|
||||
win.plane.w,
|
||||
cards[k].h * s
|
||||
);
|
||||
ctx.restore();
|
||||
}
|
||||
tr[r].insertCell().append(cell);
|
||||
}
|
||||
}
|
||||
document.title = 'ridge look sheet: done';
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
root.textContent = `ridge look sheet failed: ${e}`;
|
||||
});
|
||||
Loading…
Reference in a new issue