@margoengine/headless 0.1.0 → 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.
@@ -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;