@margoengine/headless 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1231 -2
- package/dist/accumulate.d.ts +123 -0
- package/dist/accumulate.js +198 -0
- package/dist/avc-range.d.ts +15 -0
- package/dist/compare.d.ts +97 -0
- package/dist/compare.js +320 -0
- package/dist/crc32-Cc3b8qnn.js +23 -0
- package/dist/errors-CDgOgzCd.js +7 -0
- package/dist/ffmpeg-colour-B_r-2O-e.js +15 -0
- package/dist/ffmpeg-colour.d.ts +6 -0
- package/dist/ffmpeg-files.d.ts +129 -0
- package/dist/ffmpeg-files.js +406 -0
- package/dist/ffmpeg.d.ts +164 -0
- package/dist/ffmpeg.js +402 -0
- package/dist/formats.d.ts +46 -0
- package/dist/formats.js +685 -0
- package/dist/frames.d.ts +33 -0
- package/dist/frames.js +70 -0
- package/dist/gif.d.ts +20 -0
- package/dist/gif.js +7 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +1 -0
- package/dist/look-base.d.ts +87 -0
- package/dist/look-motion.d.ts +175 -0
- package/dist/look.d.ts +775 -0
- package/dist/look.js +1963 -0
- package/dist/null.d.ts +39 -0
- package/dist/null.js +61 -0
- package/dist/readback-HJLttuJt.js +122 -0
- package/dist/readback.d.ts +55 -0
- package/dist/src-VufTH2fo.js +154 -0
- package/dist/stage.d.ts +52 -0
- package/dist/stage.js +106 -0
- package/dist/tiles.d.ts +38 -0
- package/dist/tiles.js +79 -0
- package/dist/video-mux.d.ts +77 -0
- package/dist/video.d.ts +176 -0
- package/dist/video.js +1114 -0
- package/dist/yuv420-pool.d.ts +26 -0
- package/dist/yuv420-pool.js +73 -0
- package/dist/yuv420.d.ts +33 -0
- package/dist/yuv420.js +186 -0
- package/package.json +128 -4
package/dist/frames.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { n as e, t } from "./errors-CDgOgzCd.js";
|
|
2
|
+
import { a as n, i as r, n as i, r as a } from "./readback-HJLttuJt.js";
|
|
3
|
+
//#region src/frames.ts
|
|
4
|
+
function o(o, { depth: s = 3, signal: c } = {}) {
|
|
5
|
+
if (!Number.isInteger(s) || s < 1 || s > 16) throw e("createFrameReader depth is a whole number from 1 to 16", "headless");
|
|
6
|
+
c?.throwIfAborted();
|
|
7
|
+
let l = [], u = [], d = /* @__PURE__ */ new Set(), f = !1, p = () => {
|
|
8
|
+
if (c?.throwIfAborted(), f) throw t("state", "The frame reader is disposed", "headless");
|
|
9
|
+
}, m = (e) => {
|
|
10
|
+
d.delete(e), e.destroy();
|
|
11
|
+
}, h = () => {
|
|
12
|
+
if (!f) {
|
|
13
|
+
f = !0, c?.removeEventListener("abort", h);
|
|
14
|
+
for (let e of d) e.destroy();
|
|
15
|
+
d.clear(), l.length = u.length = 0;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
c?.addEventListener("abort", h, { once: !0 });
|
|
19
|
+
let g = (e, t) => {
|
|
20
|
+
for (let n = u.pop(); n; n = u.pop()) {
|
|
21
|
+
if (n.device === e && n.size === t) return n;
|
|
22
|
+
m(n.buffer);
|
|
23
|
+
}
|
|
24
|
+
let n = a(e, t);
|
|
25
|
+
return d.add(n), {
|
|
26
|
+
buffer: n,
|
|
27
|
+
device: e,
|
|
28
|
+
size: t
|
|
29
|
+
};
|
|
30
|
+
}, _ = async ({ buffer: e, device: t, size: r, copy: i, mapped: a }) => {
|
|
31
|
+
try {
|
|
32
|
+
await a, p();
|
|
33
|
+
let o = n(e.getMappedRange(), i);
|
|
34
|
+
return e.unmap(), u.push({
|
|
35
|
+
buffer: e,
|
|
36
|
+
device: t,
|
|
37
|
+
size: r
|
|
38
|
+
}), {
|
|
39
|
+
width: i.width,
|
|
40
|
+
height: i.height,
|
|
41
|
+
data: o
|
|
42
|
+
};
|
|
43
|
+
} catch (t) {
|
|
44
|
+
throw m(e), p(), t;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
depth: s,
|
|
49
|
+
get pending() {
|
|
50
|
+
return l.length;
|
|
51
|
+
},
|
|
52
|
+
async push() {
|
|
53
|
+
p();
|
|
54
|
+
let e = r(o, "createFrameReader"), t = g(e.device, e.size), n = i(e, t.buffer), a = t.buffer.mapAsync(1);
|
|
55
|
+
return a.catch(() => {}), l.push({
|
|
56
|
+
...t,
|
|
57
|
+
copy: n,
|
|
58
|
+
mapped: a
|
|
59
|
+
}), l.length >= s ? _(l.shift()) : void 0;
|
|
60
|
+
},
|
|
61
|
+
async *drain() {
|
|
62
|
+
p();
|
|
63
|
+
for (let e = l.shift(); e; e = l.shift()) yield await _(e);
|
|
64
|
+
},
|
|
65
|
+
dispose: h,
|
|
66
|
+
[Symbol.dispose]: h
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { o as createFrameReader };
|
package/dist/gif.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
2
|
+
import { type GIFOptions } from '@margoengine/exporters/capture';
|
|
3
|
+
import type { HeadlessPixels } from './index.js';
|
|
4
|
+
/** GIF frame: RGBA pixels and optionally a per-frame delay. */
|
|
5
|
+
export interface GIFFrame extends HeadlessPixels {
|
|
6
|
+
/** Seconds, 0.02..655.35. Default 1/fps. */
|
|
7
|
+
duration?: number;
|
|
8
|
+
}
|
|
9
|
+
/** Options for animated GIF output. */
|
|
10
|
+
export interface EncodeGIFOptions extends GIFOptions {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Encodes renderFrames output or any sync/async RGBA stream to GIF89a bytes.
|
|
14
|
+
* Defaults: fps 30, no dithering, loop 0 (forever), no signal. loop -1 plays
|
|
15
|
+
* once; positive values repeat that many times. Explicit frame durations take
|
|
16
|
+
* precedence over fps. Pixels below alpha 128 are transparent; others opaque.
|
|
17
|
+
* Uses the same quantization as @margoengine/exporters/palette and the existing
|
|
18
|
+
* exporter LZW writer, keeping at most one raw frame plus compressed output.
|
|
19
|
+
*/
|
|
20
|
+
export declare function encodeGIF(frames: AsyncIterable<GIFFrame> | Iterable<GIFFrame>, options?: EncodeGIFOptions): Promise<Uint8Array>;
|
package/dist/gif.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Engine } from '@margoengine/core';
|
|
2
|
+
/** The part of a WebGPU implementation {@link installGPU} needs. `getPreferredCanvasFormat` is optional because Node
|
|
3
|
+
* bindings have no canvas to prefer a format for. */
|
|
4
|
+
export interface GPUBinding {
|
|
5
|
+
requestAdapter(options?: GPURequestAdapterOptions): Promise<GPUAdapter | null>;
|
|
6
|
+
getPreferredCanvasFormat?(): GPUTextureFormat;
|
|
7
|
+
readonly wgslLanguageFeatures?: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Options of {@link installGPU}. */
|
|
10
|
+
export interface InstallGPUOptions {
|
|
11
|
+
/** The WebGPU implementation to render with: `create([])` from a Node binding, or `navigator.gpu` in a browser. */
|
|
12
|
+
gpu: GPUBinding;
|
|
13
|
+
/** Globals the binding exports (`GPUBufferUsage` and so on). A name already on `globalThis` stays as it is; a flag
|
|
14
|
+
* table neither has gets the specification's values. Default none. */
|
|
15
|
+
globals?: Readonly<Record<string, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
/** What {@link installGPU} returns. `dispose()` (or `using`) restores `navigator.gpu` and removes the added globals. */
|
|
18
|
+
export interface InstalledGPU {
|
|
19
|
+
/** The object now at `navigator.gpu`. */
|
|
20
|
+
readonly gpu: GPU;
|
|
21
|
+
/** Restores what was there before. Safe to call twice. */
|
|
22
|
+
dispose(): void;
|
|
23
|
+
/** `dispose()`, for `using`. */
|
|
24
|
+
[Symbol.dispose](): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Makes `gpu` the WebGPU implementation core sees: sets `navigator.gpu` and the `GPU*` flag globals a runtime without
|
|
28
|
+
* WebGPU lacks, and supplies `getPreferredCanvasFormat` (`'rgba8unorm'`) when the binding has none. Call it before
|
|
29
|
+
* `Engine.create`; nothing happens on import.
|
|
30
|
+
*/
|
|
31
|
+
export declare function installGPU({ gpu, globals }: InstallGPUOptions): InstalledGPU;
|
|
32
|
+
/** Options of {@link createHeadlessCanvas}. */
|
|
33
|
+
export interface HeadlessCanvasOptions {
|
|
34
|
+
/** Width of the image in pixels, a whole number from 1. Required. */
|
|
35
|
+
width: number;
|
|
36
|
+
/** Height of the image in pixels, a whole number from 1. Required. */
|
|
37
|
+
height: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A stand-in for `Engine.create`'s canvas: `width`, `height`, `clientWidth` and `clientHeight` (0, so core keeps
|
|
41
|
+
* `width` and `height` as the image size) and `getContext('webgpu')`. It has no other element members, so use it with
|
|
42
|
+
* `Engine` and packages that take an engine, not with `createStage`, which needs a page.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createHeadlessCanvas({ width, height }: HeadlessCanvasOptions): HTMLCanvasElement;
|
|
45
|
+
/** RGBA pixels from {@link readPixels}: 8 bits per channel, straight alpha, top row first, no padding. */
|
|
46
|
+
export interface HeadlessPixels {
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
data: Uint8Array;
|
|
50
|
+
}
|
|
51
|
+
/** Options of {@link readPixels} and {@link toPNG}. */
|
|
52
|
+
export interface HeadlessReadOptions {
|
|
53
|
+
/** Stops waiting for the GPU; the promise rejects with the signal's reason. Default none. */
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reads the last frame of an engine on a {@link createHeadlessCanvas} canvas. Call `engine.render()` first; this draws
|
|
58
|
+
* nothing itself. A context configured `opaque` (the default) reads alpha 255, as a page would show it. The readback
|
|
59
|
+
* buffer stays on the canvas for the next read of the same size. To read every frame of a film without waiting for the
|
|
60
|
+
* GPU after each one, use `createFrameReader` from `@margoengine/headless/frames`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function readPixels(engine: Engine, { signal }?: HeadlessReadOptions): Promise<HeadlessPixels>;
|
|
63
|
+
/** Encodes RGBA pixels as an 8-bit PNG file (each row filtered against the one above). */
|
|
64
|
+
export declare function encodePNG({ width, height, data }: HeadlessPixels): Promise<Uint8Array>;
|
|
65
|
+
/** The last frame of an engine on a {@link createHeadlessCanvas} canvas as PNG file bytes. See {@link readPixels}. */
|
|
66
|
+
export declare function toPNG(engine: Engine, options?: HeadlessReadOptions): Promise<Uint8Array>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as createHeadlessCanvas, n as encodePNG, r as installGPU, i as readPixels, a as toPNG } from "./src-VufTH2fo.js";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { HeadlessPixels } from './index.js';
|
|
2
|
+
/** An 8-bit sRGB frame: RGBA, straight alpha, top row first, as `readPixels` and `decodePNG` give. */
|
|
3
|
+
export type LookImage = HeadlessPixels;
|
|
4
|
+
/** A mask: one byte per pixel, or RGBA where the first channel counts. 128 and above is inside. */
|
|
5
|
+
export interface LookMask {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
data: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
/** A float frame, RGBA: `Float32Array`, or `Uint16Array` of half-float bits as an `rgba16float` readback holds them. */
|
|
11
|
+
export interface FloatFrame {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
data: Float32Array | Uint16Array;
|
|
15
|
+
}
|
|
16
|
+
/** A bound from a shot file's `lookBounds`: a number is the largest value that passes, `[low, high]` a range. */
|
|
17
|
+
export type LookBound = number | readonly [number, number];
|
|
18
|
+
/** The name of a look check, as `lookBounds` names it. */
|
|
19
|
+
export type LookCheckName = 'skyClip' | 'grain' | 'speckle' | 'banding' | 'flat' | 'blocks' | 'horizonSeam' | 'waterSeam' | 'lights' | 'foamEdges' | 'crush' | 'flicker' | 'shimmer' | 'nan' | 'backends' | 'reference' | 'penumbra' | 'penumbraPlants' | 'stairs' | 'colourEdges' | 'chromaSmear' | 'shimmerMoving' | 'motionBlur' | 'silhouette' | 'silhouetteShape' | 'bounce' | 'shadowTint' | 'nightLuma' | 'nightPeak';
|
|
20
|
+
/** What a check gives back. */
|
|
21
|
+
export interface LookResult {
|
|
22
|
+
/** The check's name. */
|
|
23
|
+
check: LookCheckName | string;
|
|
24
|
+
/** The measured value, in `unit`. NaN when the check could not run (`missing`), which never passes. */
|
|
25
|
+
value: number;
|
|
26
|
+
/** `[low, high]`: the value passes when inside, ends included. */
|
|
27
|
+
bound: [number, number];
|
|
28
|
+
pass: boolean;
|
|
29
|
+
unit: string;
|
|
30
|
+
/** Set when the check could not run: what was missing. */
|
|
31
|
+
missing?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Set with `missing` when the check could not run because the frame holds too little of what it measures, as
|
|
34
|
+
* counted against what it needs: T6 with fewer than 30 (`GROUND_MIN_PIXELS`) umbra or lit ground pixels (a shot whose sun
|
|
35
|
+
* casts no full shadow in frame). The row is never a pass (`pass` stays false, `value` NaN); the report shows it as
|
|
36
|
+
* "not run" with `missing`, and a probe's verdict leaves it out as it leaves out a family check with no input. A bound
|
|
37
|
+
* the shot names itself for the check turns it into a failure (KB-LOOK-TV-POOLFAILS1, rail-line).
|
|
38
|
+
*/
|
|
39
|
+
notRun?: true;
|
|
40
|
+
/**
|
|
41
|
+
* Set when the check ran over a mask with no pixels in it, so it measured nothing: for example `0 sky pixels` for
|
|
42
|
+
* a shot with no sky in view. The row passes, and the report says what it measured, so the pass is never silent.
|
|
43
|
+
*/
|
|
44
|
+
empty?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The mask the check measured inside, by name, when {@link checkProbe} chose one: `sky` (the page's sky mask),
|
|
47
|
+
* `sky-coverage` (the pixels `@margoengine/sky` drew, when there is no `sky` mask) or `frame` (the whole frame).
|
|
48
|
+
* Set on `skyClip`; the report says which.
|
|
49
|
+
*/
|
|
50
|
+
mask?: string;
|
|
51
|
+
/** Further numbers the check measured, for the report. */
|
|
52
|
+
detail: Record<string, number>;
|
|
53
|
+
}
|
|
54
|
+
/** Each check's default bound, its unit and what it measures. A shot's `lookBounds` replaces the bound by name. */
|
|
55
|
+
export declare const LOOK_CHECKS: Readonly<Record<LookCheckName, {
|
|
56
|
+
bound: [number, number];
|
|
57
|
+
unit: string;
|
|
58
|
+
about: string;
|
|
59
|
+
}>>;
|
|
60
|
+
export declare const finite: (value: unknown) => value is number;
|
|
61
|
+
/** The `[low, high]` of a bound: a number is the high end, with no low end. */
|
|
62
|
+
export declare function lookBound(bound: LookBound): [number, number];
|
|
63
|
+
export declare function result(check: LookCheckName, value: number, bound: LookBound | undefined, detail?: Record<string, number>): LookResult;
|
|
64
|
+
/** A row for a check that could not run, which fails: an asked-for check that did not run is not a pass. */
|
|
65
|
+
export declare function missingResult(check: LookCheckName | string, missing: string, bound?: LookBound): LookResult;
|
|
66
|
+
export declare function checkImage(image: LookImage, what?: string): void;
|
|
67
|
+
export declare function sameSize(a: {
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
}, b: {
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
}, what: string): void;
|
|
74
|
+
/** Inside flags of a mask, one per pixel, or all inside when no mask is given. */
|
|
75
|
+
export declare function maskBits(frame: {
|
|
76
|
+
width: number;
|
|
77
|
+
height: number;
|
|
78
|
+
}, mask: LookMask | undefined, what: string, least?: number): Uint8Array;
|
|
79
|
+
/** Luma of each pixel on 0 to 255: BT.709 weights on the encoded values. */
|
|
80
|
+
export declare function luma(image: LookImage): Float32Array;
|
|
81
|
+
export declare const percent: (part: number, whole: number) => number;
|
|
82
|
+
/** Options of {@link flicker} and {@link shimmer}. */
|
|
83
|
+
export interface FlickerOptions {
|
|
84
|
+
/** Only pixels inside this mask count. */
|
|
85
|
+
mask?: LookMask;
|
|
86
|
+
bound?: LookBound;
|
|
87
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { type FlickerOptions, type LookImage, type LookResult } from './look-base.js';
|
|
2
|
+
/** Per pixel motion of a frame to the next, in pixels: x then y of each pixel, `width * height * 2` floats. */
|
|
3
|
+
export interface LookMotion {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
data: Float32Array;
|
|
7
|
+
}
|
|
8
|
+
/** One float per pixel: each pixel's distance from the eye, `width * height` floats, any unit. */
|
|
9
|
+
export interface LookDistance {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
data: Float32Array;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* How much farther than a surface moved by the camera alone a pixel must be for that surface's motion blur to reach
|
|
16
|
+
* it: 1.25 times its distance, a depth step (a near trunk over the forest behind it), never the slope of one surface
|
|
17
|
+
* across the few pixels of a trail (KB-LOOK-TV-POOLFAILS1).
|
|
18
|
+
*/
|
|
19
|
+
export declare const PARALLAX_STEP = 1.25;
|
|
20
|
+
/** A moving probe: the frame after this one and where each pixel of this one went. */
|
|
21
|
+
export interface MovingFrames {
|
|
22
|
+
next: LookImage;
|
|
23
|
+
motion: LookMotion;
|
|
24
|
+
/**
|
|
25
|
+
* Each pixel of `next` moved back to this frame, the same way as `motion`: with it `shimmerMoving` leaves out the
|
|
26
|
+
* pixels the next frame covers or uncovers (the forward-backward test).
|
|
27
|
+
*/
|
|
28
|
+
back?: LookMotion;
|
|
29
|
+
/**
|
|
30
|
+
* The engine's own motion of each pixel of this frame from the frame before, the same way as `motion` (pixels over
|
|
31
|
+
* one frame, TAA's velocity with its jitter removed): with it `shimmerMoving` leaves out a pixel whose surface moves
|
|
32
|
+
* other than the camera moves it, by more than half a pixel (a swaying branch, a flame, a wave), which changes on
|
|
33
|
+
* purpose, including what such a surface leaves behind, and `motionBlur` judges each edge by its surface's own travel.
|
|
34
|
+
*/
|
|
35
|
+
velocity?: LookMotion;
|
|
36
|
+
/** The same for each pixel of `next`: `shimmerMoving` also leaves out a pixel that lands where such a surface moved. */
|
|
37
|
+
nextVelocity?: LookMotion;
|
|
38
|
+
/**
|
|
39
|
+
* The shutter angle the frame was exposed with, in degrees (more than 0, up to 360), for `motionBlur`. Default 180,
|
|
40
|
+
* the film standard: a frame drawn without sub-frames is still judged against a 180 degree smear.
|
|
41
|
+
*/
|
|
42
|
+
shutter?: number;
|
|
43
|
+
/**
|
|
44
|
+
* The longest blur radius the shot's motion blur draws, in pixels (`MotionBlur` `maxBlur`), for `shimmerMoving`'s
|
|
45
|
+
* blur reach. Default 32, `MotionBlur`'s default.
|
|
46
|
+
*/
|
|
47
|
+
maxBlur?: number;
|
|
48
|
+
/**
|
|
49
|
+
* How many sub-frames over the open shutter the frame is the mean of (the shot tool's kept frames), 1 to 4096.
|
|
50
|
+
* Default 1: one frame drawn with its motion blur centred on its velocity. With more, `velocity` is the last
|
|
51
|
+
* sub-frame's (the shot tool records it so), and a moving surface's trail over the shutter lies behind it, which
|
|
52
|
+
* `shimmerMoving`'s blur reach follows (KB-SCATTER-FRINGEVEL1).
|
|
53
|
+
*/
|
|
54
|
+
subframes?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Each pixel's distance from the eye in this frame (the shot tool's `probes/<name>.distance.f32`). With it and
|
|
57
|
+
* `velocity`, a surface the camera alone moves on screen smears too: its blur over a surface at least
|
|
58
|
+
* {@link PARALLAX_STEP} times as far that moves otherwise is left out, as a near trunk's trail over the forest behind
|
|
59
|
+
* it when the camera runs past (KB-LOOK-TV-POOLFAILS1). A surface never smears over a nearer one.
|
|
60
|
+
*/
|
|
61
|
+
distance?: LookDistance;
|
|
62
|
+
/** The same for `next`, with `nextVelocity` and `back`. */
|
|
63
|
+
nextDistance?: LookDistance;
|
|
64
|
+
/**
|
|
65
|
+
* How `shimmerMoving` warps a pixel the engine moves by under half a pixel of its own (the ones it still counts):
|
|
66
|
+
* `'velocity'` (the default where `velocity` and `nextVelocity` are given) lands it where the engine's motion takes it,
|
|
67
|
+
* when that motion passes {@link velocityLanding}'s per-pixel tests, and where the camera takes it otherwise;
|
|
68
|
+
* `'camera'` always lands it where the camera takes it, as before 2026-11-29. Grass swaying a quarter of a pixel a
|
|
69
|
+
* frame is motion, not shimmer, and a temporal-stability measure reprojects along the motion vectors (KB-LOOK-TV-POOLFAILS1).
|
|
70
|
+
*/
|
|
71
|
+
reproject?: 'velocity' | 'camera';
|
|
72
|
+
/**
|
|
73
|
+
* Where water is the surface drawn in this frame (`Water.surfaceTexture`, the shot's `water-surface` AOV, 0 to 255):
|
|
74
|
+
* a pixel marked at least half is compared after a local gain, the next frame's warped mean over this frame's mean
|
|
75
|
+
* across the water pixels within {@link WATER_GAIN_RADIUS} of it. A water surface's reflection changes smoothly with
|
|
76
|
+
* the view angle (Fresnel, falling as a camera running low over a creek looks ever more steeply down at it), which
|
|
77
|
+
* is a brightness slope across the surface, not shimmer; the gain takes it as a multiplicative brightness field (M. A.
|
|
78
|
+
* Gennert and S. Negahdaripour, "Relaxing the Brightness Constancy Assumption in Computing Optical Flow", MIT AI
|
|
79
|
+
* Memo 975, 1987), while a sparkle, a flickering crest or any change finer than the window still counts. Fire and
|
|
80
|
+
* smoke over the water are not in the mask. Unset, nothing is gained (KB-LOOK-TV-CREEKWATER1).
|
|
81
|
+
*/
|
|
82
|
+
waterSurface?: LookImage;
|
|
83
|
+
/**
|
|
84
|
+
* Where a flame is drawn in this frame and in the next (`watchFlameCoverage` of `@margoengine/vfx/flame`, the shot's
|
|
85
|
+
* `flame` AOV, 0 to 255): a pixel whose flame mask is above zero here, or at its landing in the next frame, is the
|
|
86
|
+
* flame's own animation, not a surface, and is left out. Above zero is the flame's own drawn coverage, so no threshold
|
|
87
|
+
* is chosen; smoke, embers and the glow are not in the mask, so a surface seen through them still counts. An all-zero
|
|
88
|
+
* mask (no fire) changes nothing (KB-LOOK-TV-FLAMEMASK1).
|
|
89
|
+
*/
|
|
90
|
+
flame?: LookImage;
|
|
91
|
+
/** The next frame's flame mask, as `flame`. */
|
|
92
|
+
nextFlame?: LookImage;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The half width in pixels of the window `shimmerMoving` fits a water pixel's gain over ({@link MovingFrames.waterSurface}):
|
|
96
|
+
* 8, a 17 x 17 window. Derived from the Fresnel gain field itself (KB-LOOK-TV-CREEKWATER1): on the timber-valley creek's
|
|
97
|
+
* mid probe (camera about 1 m over the water at 8 m/s, the steepest gain change a shot has shown) the gain's screen
|
|
98
|
+
* gradient times the pixel's luma is at most 0.37 codes a pixel for 99.9 percent of the water pixels, so over a radius of
|
|
99
|
+
* 8 a window's gain differs from its centre's by under 3 codes, half the 6-code threshold; the largest radius that holds
|
|
100
|
+
* that is taken, since a wider window absorbs less of any flicker. The guards (a sparkle, crests flickering a pixel
|
|
101
|
+
* apart, the same dimming off the water) fail at every radius from 1 to 10, so they set no tighter bound.
|
|
102
|
+
*/
|
|
103
|
+
export declare const WATER_GAIN_RADIUS = 8;
|
|
104
|
+
/**
|
|
105
|
+
* T4 while moving: frame n is warped onto n + 1 by its motion (`reprojectionMotion` makes it from the depth and the two
|
|
106
|
+
* view-projections), and the percent of pixels whose luma falls more than `threshold` (6 codes) outside [min, max] of
|
|
107
|
+
* the four pixels of the next frame around where it lands is the shimmer (see `outsideTaps`: a blend of those four is
|
|
108
|
+
* the warp resampling an edge, not a change). Pixels whose target leaves the frame are not counted. With `velocity`,
|
|
109
|
+
* a pixel a moving surface's motion blur reaches is left out too (`blurReach`: McGuire, Hennessy, Bukowski and Osman
|
|
110
|
+
* 2012 tile-max, capped at `maxBlur`), and with `nextVelocity` and `back` a pixel landing where the next frame's
|
|
111
|
+
* movers smear, counted in `detail.blurred`.
|
|
112
|
+
* @throws RangeError for a shutter not more than 0 and up to 360 degrees, a maxBlur not 1 to 128 pixels, or subframes
|
|
113
|
+
* not a whole number from 1 to 4096.
|
|
114
|
+
*/
|
|
115
|
+
export declare function shimmerMoving(frame: LookImage, { next, motion, back, velocity, nextVelocity, shutter, maxBlur, subframes, distance, nextDistance, reproject, waterSurface, flame, nextFlame, }: MovingFrames, { mask, bound, threshold }?: FlickerOptions & {
|
|
116
|
+
threshold?: number;
|
|
117
|
+
}): LookResult;
|
|
118
|
+
/**
|
|
119
|
+
* Two column-major view-projections moved to an origin at `eye` (the eye `viewProjection` was made from), so that
|
|
120
|
+
* {@link reprojectionMotion} between them carries no float32 rounding of their translations (KB-SHOT-SUBVEL1). An
|
|
121
|
+
* engine hands its matrices over in float32, and far from the origin their translation, about the eye's distance in
|
|
122
|
+
* size, rounds differently for each camera: 1.6 km out a still surface 3 m away moved about 0.02 px a frame from that
|
|
123
|
+
* alone, pixels once a short step's motion is scaled to a frame. The projection's own translation K (the matrix times
|
|
124
|
+
* [eye, 1]) is taken once, from `viewProjection`, and used for both, so its rounding leaves the motion
|
|
125
|
+
* ("relative to eye": Ohlarik, "Precisions, Precisions", AGI, 2008; Cozzi and Ring, "3D Engine Design for Virtual
|
|
126
|
+
* Globes", CRC Press, 2011, chapter 5). Both matrices must share their projection (an unjittered pair, or one jitter):
|
|
127
|
+
* K is the same for both only then. Positions are then relative to `eye`; NDC depths are unchanged.
|
|
128
|
+
* @throws RangeError unless both matrices have 16 finite values and both eyes 3.
|
|
129
|
+
*/
|
|
130
|
+
export declare function relativeViewProjections(viewProjection: ArrayLike<number>, eye: ArrayLike<number>, nextViewProjection: ArrayLike<number>, nextEye: ArrayLike<number>): {
|
|
131
|
+
viewProjection: Float64Array;
|
|
132
|
+
nextViewProjection: Float64Array;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* The motion of every pixel of a still world seen by a moving camera: each pixel's depth (NDC z, in the convention of the
|
|
136
|
+
* matrices) takes it back to the world by the inverse of `viewProjection`, and `nextViewProjection` takes it forward to
|
|
137
|
+
* where it lands in the next frame. Column-major matrices. Pixels with no depth (`NaN`) move by 0.
|
|
138
|
+
* @throws RangeError for a singular matrix or a depth that is not `width * height` floats.
|
|
139
|
+
*/
|
|
140
|
+
export declare function reprojectionMotion(depth: Float32Array, viewProjection: ArrayLike<number>, nextViewProjection: ArrayLike<number>, width: number, height: number): LookMotion;
|
|
141
|
+
/**
|
|
142
|
+
* The NDC depth of every pixel of a frame from its distance to the eye, in the convention of `viewProjection`, for
|
|
143
|
+
* {@link reprojectionMotion}: the pixel's ray (the line through the unprojected points at depth 0 and 1, pointing away
|
|
144
|
+
* from `eye`) is walked `distance` metres from `eye` and the point is projected back. A pixel with no distance (not
|
|
145
|
+
* finite or not above 0) takes `options`: where `water` is 128 or more its ray meets the plane y = `plane` (the sea
|
|
146
|
+
* level), and any other pixel is `far` metres away (a sky); with neither it gives `NaN` (no depth). Column-major matrix.
|
|
147
|
+
* @throws RangeError for a singular matrix, an eye that is not 3 numbers or a distance that is not `width * height` floats.
|
|
148
|
+
*/
|
|
149
|
+
export declare function depthFromDistance(distance: ArrayLike<number>, eye: ArrayLike<number>, viewProjection: ArrayLike<number>, width: number, height: number, options?: {
|
|
150
|
+
water?: ArrayLike<number>;
|
|
151
|
+
plane?: number;
|
|
152
|
+
far?: number;
|
|
153
|
+
}): Float32Array;
|
|
154
|
+
/**
|
|
155
|
+
* T8: of the edge centres of pixels moving more than `minimum` (8) pixels a frame, the percent whose edge is narrower
|
|
156
|
+
* than half the smear the shutter gives them: strobing spray, rain or debris. A shutter of `shutter` degrees (default
|
|
157
|
+
* 180) is open for shutter / 360 of the frame interval, so it smears an edge across that share of its travel to the
|
|
158
|
+
* next frame: half the travel at 180 degrees, and the check calls an edge sharp under a quarter of it
|
|
159
|
+
* (KB-LOOK-TV-MOTIONBLUR1: the whole travel was taken as the smear, so a correct 180 degree frame read as sharp).
|
|
160
|
+
* An edge centre is a pixel whose luma profile along its motion (one travel wide, centred on it, spanning over 24 codes)
|
|
161
|
+
* crosses the middle value within one pixel of the pixel itself; the edge's width is the run of the profile round that
|
|
162
|
+
* crossing between 10 and 90 percent of its range. A hard edge is under a pixel wide, a blurred one as wide as its smear.
|
|
163
|
+
* A mover narrower than its smear ramps over its own width however well it is blurred, so for one the ramp plus the
|
|
164
|
+
* plateau it holds before coming back is its smear, judged at the same share (`edgeSpan`, KB-LOOK-TV-MBNARROW1).
|
|
165
|
+
* With `velocity` (the engine's own motion of each pixel, as `MovingFrames.velocity`) each pixel's travel is its
|
|
166
|
+
* surface's real motion, not the camera's alone: a leaf swaying against the camera's sweep moves less than the camera
|
|
167
|
+
* moves the place it covers, and is smeared by what it moves (KB-LOOK-TV-MBVEL1).
|
|
168
|
+
* An edge whose ramp is a staircase of sharp copies (`stepped`, one per sub-frame) is sharp too (KB-LOOK-TV-SUBSTEP1).
|
|
169
|
+
* @throws RangeError for a shutter that is not more than 0 and up to 360 degrees.
|
|
170
|
+
*/
|
|
171
|
+
export declare function motionBlur(frame: LookImage, motion: LookMotion, { mask, bound, minimum, shutter, velocity, }?: FlickerOptions & {
|
|
172
|
+
minimum?: number;
|
|
173
|
+
shutter?: number;
|
|
174
|
+
velocity?: LookMotion;
|
|
175
|
+
}): LookResult;
|