Ratatoskr/scripts/bake-sky.mjs
Void 0386065f2c
Some checks failed
Build pull request / Build pull request (pull_request) Failing after 3m38s
CLA Assistant / CLAssistant (pull_request_target) Failing after 1s
sky: bake an atmospheric-scattering table (half float) for a WebGL2 sky shader
scatter.js ray-marches a single-scattering Rayleigh+Mie atmosphere whose vertical optical depth is
sun.js's TAU, and bakes two tables into baked.scatter: transmittance to space by view elevation
(32x1) and sky radiance by azimuth from the sun x view elevation x sun elevation (7x32x12), RGB
half floats, little-endian base64, value x 64. Layout, exact decode and a GLSL sampler are in
src/sky/README.md. Tests pin layout, encoding, checksums and physical anchors (zenith transmittance
equals exp(-TAU); blue noon, red low sun toward the sun, black below the planet-shadow limit).

The per-sky sun {elevation_deg, azimuth_deg, color_linear}, ambient_linear and horizon_hex were
already baked in 7216456a; sun.js now exports TAU.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 20:57:22 +00:00

19 lines
769 B
JavaScript

// Bakes Midnight Sky and Noonday Sky from src/sky/sun.js into src/sky/baked.ts, with the
// atmospheric-scattering tables (src/sky/scatter.js) as `scatter`.
// Run `npm run bake:sky` after changing sun.js, skyTokens.js, scatter.js or a moment.
import { writeFileSync } from 'node:fs';
import { bakeSky } from '../src/sky/skyTokens.js';
import { bakeScatter } from '../src/sky/scatter.js';
const out = new URL('../src/sky/baked.ts', import.meta.url);
const baked = {
midnight: bakeSky('midnight'),
noonday: bakeSky('noonday'),
scatter: bakeScatter(),
};
writeFileSync(
out,
`// Generated by scripts/bake-sky.mjs from src/sky/sun.js. Do not edit.\n` +
`/* eslint-disable */\n` +
`export const baked = ${JSON.stringify(baked, null, 2)} as const;\n`
);