/** * @file material.ts * @brief Material vectors and GPU block packing. * @details Packers write into caller-owned storage without allocating per shape. */ import { type Scheme } from "./layout.js"; /** @brief Straight-alpha color, channels in encoded (gamma-space) 0..1. */ export type Rgba = readonly [number, number, number, number]; /** @brief Opaque color, channels in encoded (gamma-space) 0..1. */ export type Rgb = readonly [number, number, number]; /** @brief Displacement of a backdrop lookup that grows towards the rim. */ export interface LensSpec { /** * @brief Displacement at the rim in points; negative reads from further inside (magnifies). */ readonly amount: number; /** * @brief Depth inside the rim over which the displacement falls to zero, in points; 0 keeps the * lookup in place. */ readonly height: number; } /** * @brief Luminance remap, chroma gain and a fill color laid over the result (a color matrix). */ export interface ToneSpec { /** @brief Output level for luminance 1 (default 1). */ readonly white?: number; /** @brief Output level for luminance 0 (default 0). */ readonly black?: number; /** @brief Chroma gain; 1 keeps the saturation (default 1). */ readonly saturation?: number; /** @brief Color laid over the remapped color with its alpha. */ readonly fill?: Rgba; } /** @brief Backdrop blur that changes with the distance from the rim. */ export interface BlurSpec { /** @brief Blur radius in points (twice the radius the lookup uses). */ readonly radius: number; /** @brief Blur weights at the four distances (default 1 1 1 1). */ readonly opacities?: readonly number[]; /** * @brief Four non-decreasing distances in points, negative inside (default 0 0 0 0). * @details The weights hold beyond the ends. */ readonly distances?: readonly number[]; } /** @brief Second, undisplaced backdrop lookup at a blur of its own, blended into the face. */ export interface BlurFillSpec { /** @brief Blur radius in points (twice the radius the lookup uses). */ readonly radius: number; /** @brief Share of the darker of face and fill, 0..1. */ readonly darken?: number; /** @brief Share of the lighter of face and fill, 0..1. */ readonly lighten?: number; /** @brief Mix towards the fill itself, 0..1. */ readonly normal?: number; } /** @brief Refraction across the body and the band mixed in at the rim. */ export interface RefractionSpec { readonly inner?: LensSpec; readonly outer?: LensSpec; /** @brief Opacity of the outer refraction over the inner one, 0..1. */ readonly outerOpacity?: number; /** * @brief Distances where the outer refraction starts and is fully shown (default -1, 0). */ readonly outerDistances?: readonly number[]; } /** @brief Face color: maximum luminance, then the color matrix. */ export interface FaceSpec extends ToneSpec { /** @brief Mix of the matrix result over the plain lookup, 0..1 (default 1). */ readonly opacity?: number; /** * @brief Luminance that white is brought down to before the matrix, 0..1 (default 1: none), at * full extended range. */ readonly maxLuminance?: number; /** @brief The same in standard dynamic range (default `maxLuminance`). */ readonly maxLuminanceStandard?: number; } /** @brief Wide-blur color bled in from the rim, weighted by the luminance of the face. */ export interface BleedSpec extends ToneSpec { /** @brief Strength, 0..1; 0 disables it. */ readonly opacity: number; /** @brief Lens of the lookup: displacement and depth in points. */ readonly amount: number; readonly height: number; /** @brief Blur radius in points (twice the radius the lookup uses). */ readonly radius: number; /** @brief Distances where the weight is 0 and 1 (default 1, 0). */ readonly distances?: readonly number[]; /** * @brief Weight by the luminance of the face (true: bright areas) instead of its inverse * (default false). */ readonly darken?: boolean; } /** @brief Soft shadow of the shape moved by an offset; its color can come from the backdrop. */ export interface ShadowSpec extends ToneSpec { /** @brief Peak alpha, 0..1; 0 disables it. */ readonly opacity: number; /** @brief Falloff radius in points; the shadow reaches twice this beyond its outline. */ readonly radius: number; /** @brief Offset in points, y down (default 0, 0). */ readonly offsetX?: number; readonly offsetY?: number; /** * @brief Lens of the backdrop lookup (default none) and the distance added before it is * evaluated. */ readonly amount?: number; readonly height?: number; readonly inset?: number; /** * @brief Blur radius of the backdrop lookup in points (twice the radius the lookup uses). */ readonly blur?: number; /** @brief Share of the color taken from the backdrop, 0..1 (default 0: the fill only). */ readonly backdropMix?: number; } /** @brief Blurred stroke just inside the shape moved down, laid over the glass in black. */ export interface RingShadowSpec { readonly opacity: number; /** @brief Blur radius in points. */ readonly radius: number; /** @brief Stroke width in points. */ readonly width: number; /** @brief Downward offset in points. */ readonly offset: number; /** @brief 1 keeps it inside the shape (default 1). */ readonly mask?: number; } /** * @brief Thin band at the rim that darkens (negative bias) or lightens the glass, in two opposite * lobes. */ export interface EdgeShadeSpec { /** @brief Brightness bias in (0, 1); 0.5 is linear. */ readonly amount: number; /** * @brief Direction of the lobes in radians: 0 points up, positive turns clockwise (default * pi/2). */ readonly angle?: number; /** @brief Color bias: c (1 + bias h (3 - 2 c)). */ readonly bias: number; /** * @brief Band height and offset in device pixels; an offset of minus the height draws a stroke * along the outline. */ readonly height: number; readonly offset?: number; /** * @brief Half width of each lobe in radians, at full extended range and in standard range * (default the same). */ readonly spread: number; readonly spreadStandard?: number; } /** @brief One bright rim light and the color matrix the glass under it is drawn through. */ export interface LightSpec extends ToneSpec { /** @brief Light alpha (default 1). */ readonly opacity?: number; /** @brief Brightness bias in (0, 1); 0.5 is linear (default 0.5). */ readonly amount?: number; /** @brief Width of the lit band inside the rim, in points. */ readonly height: number; /** @brief Half width of the lit arc in radians. */ readonly spread: number; /** @brief 0 keeps a flat band, 1 fades it linearly across its width (default 0). */ readonly curvature?: number; /** @brief Color dodge fill of the matrix. */ readonly dodge?: Rgba; } /** @brief Two rim lights: the key at its angle and the fill opposite to it. */ export interface RimSpec { readonly key: LightSpec; readonly fill: LightSpec; /** * @brief Direction of the key light in radians: 0 points up, positive turns clockwise (default * 0). */ readonly angle?: number; /** * @brief Wide band of each light: its height, spread and amount times these (default none). */ readonly diffuse?: { readonly amount: number; readonly height: number; readonly spread: number; }; /** @brief Added to the distance before the bands are evaluated, in points (default 0). */ readonly inset?: number; } /** * @brief Color fringes of the face lookup: red pulled outward, blue inward, along the normal turned * by the angle. */ export interface AberrationSpec { /** @brief Separation at the rim in points. */ readonly amount: number; readonly angle?: number; /** @brief Depth over which it falls to zero, in points (default 0: a constant band). */ readonly height?: number; /** @brief Depth of the band at full separation, in points (default 0). */ readonly offset?: number; } /** * @brief Lens layer over the glass: the unblurred backdrop with color fringes, faded towards the * rim. */ export interface LensLayerSpec { /** @brief Separation of the colors in points. */ readonly amount: number; readonly angle?: number; /** * @brief Depth over which the separation falls to zero beyond the inset (default 0: constant * inside the inset). */ readonly height?: number; /** @brief Depth of the band at full separation, in points. */ readonly inset?: number; /** * @brief Two distances and the opacities at them; linear between, held beyond (default -1 0 / 1 * 0). */ readonly distances?: readonly number[]; readonly opacities?: readonly number[]; } /** @brief Color held just inside the rim in standard range. */ export interface HoldSpec { readonly start: number; readonly end: number; readonly white: number; } /** * @brief Full material description. * @details Distances are points; colors are encoded (gamma-space) values. */ export interface MaterialSpec { /** @brief Backdrop texels per device pixel: 0.125, 0.25 (default), 1/3, 0.5 or 1. */ readonly backdropScale?: number; readonly blur?: BlurSpec; readonly blurFill?: BlurFillSpec; readonly refraction?: RefractionSpec; readonly face?: FaceSpec; readonly bleed?: BleedSpec; readonly shadow?: ShadowSpec; readonly ringShadow?: RingShadowSpec; readonly edgeShade?: EdgeShadeSpec; readonly rim?: RimSpec; readonly aberration?: AberrationSpec; readonly lens?: LensLayerSpec; readonly hold?: HoldSpec; /** @brief Output channel limit (default: from the face white); 0 disables it. */ readonly limit?: number; /** @brief Scale all channels to the limit instead of clamping each. */ readonly keepHue?: boolean; /** * @brief 0 keeps corner normals, 1 uses the ellipse direction of the shape (default 0.5 with a * bleed, else 0). */ readonly roundness?: number; /** @brief Extended-range share in [0, 1]; 0 for standard dynamic range output. */ readonly headroom?: number; /** @brief Extended-range share, 0..1; takes precedence over the legacy `headroom` name. */ readonly rangeShare?: number; /** * @brief Backdrop capture margin beyond the shape in points (default: how far the lookups * reach). */ readonly margin?: number; } export declare const X_FRINGE = 118; export declare const X_FRINGE_ANGLE: number; export declare const X_FRINGE_HEIGHT: number; export declare const X_FRINGE_OFFSET: number; export declare const X_HOLD_START: number; export declare const X_HOLD_END: number; export declare const X_HOLD_WHITE: number; export declare const X_LIMIT: number; export declare const X_KEEP_HUE: number; export declare const X_ROUNDNESS: number; export declare const X_HEADROOM: number; export declare const X_RIM_ANGLE: number; /** @brief Length of a material vector. */ export declare const X_BLEED_FILL_R: number; export declare const X_BLEED_FILL_A: number; export declare const VECTOR: number; /** @brief Largest short side (points) of glass that follows the backdrop luminance. */ export declare const ADAPTIVE_SIDE = 64; /** @brief Output limit for a face white above 1 (extended-range decode of the white level). */ export declare function limitOf(w: number): number; /** * @brief YCC color matrix: luminance to (white - black) Y + black, chroma times the * saturation, then a fill of straight color (r, g, b) at alpha a laid over it. * @details Writes 20 values (4 x 5, row major: RGBA out, RGBA in + constant) at `o`; the alpha row * keeps the input alpha. */ export declare function yccMatrix(out: Float64Array, o: number, white: number, black: number, saturation: number, r: number, g: number, b: number, a: number): void; /** * @brief Resolve the vibrant color matrix used by rim lights. * @details Applies the YCC tone, color fill and dodge composition, then rounds coefficients to * four decimal places with the specified Float32 operations. */ export declare function vibrantMatrix(out: Float64Array, o: number, white: number, black: number, saturation: number, fr: number, fg: number, fb: number, fa: number, dr: number, dg: number, db: number, da: number): void; /** * @brief Backdrop scale the blur allows (perceptual estimator): the first of the candidate scales * at which the blurred backdrop aliases less than `epsilon`, else the last one. * @details Float32 steps throughout. * @param blur Face blur radius of the lookup in points, times its weight at the rim. * @param fill Blur fill radius of the lookup in points. * @param faceFill Alpha of the face fill. * @param fillShare Blur fill mix towards itself. * @param pixelLength Points per device pixel; at a third or less the candidates gain 1/3. */ export declare function estimateScale(blur: number, fill: number, faceFill: number, fillShare: number, pixelLength: number): number; /** * @brief Resolve the mip levels and aligned capture region for variable blur. * @param out Receives seven integers at `o`: level count, texel alignment, x, y, width, height and * the first mip level needed by the smallest radius. * @param w Capture width in texels. * @param h Capture height. * @param x Capture origin x in texels. * @param y Capture origin y. * @param r0 Smallest blur radius in texels. * @param r1 Largest blur radius in texels. * @param scale Backdrop texels per device pixel. * @param six Six stable levels instead of seven when a blur fill is on. */ export declare function blurRegion(out: Int32Array, o: number, w: number, h: number, x: number, y: number, r0: number, r1: number, scale: number, six: boolean): void; /** * @brief Backdrop capture and blur pyramid of a shape, in texels on the grid from the bottom-left * corner of the target (y up). * @details The capture is the shape grown by the margin, rounded inwards to whole texels (an extent * under two texels keeps one), inside the target; the pyramid region is the capture grown by 2.8 * times the largest lookup radius and aligned outward (`blurRegion`). Its texture starts at the low * level, where it holds whole 64-texel steps (from 64 up) and whole texels of its coarsest level. * Writes capture x, y, w, h, region x, y, region w, h (base texels, the texture size times 2^low), * the level count and the low level (10 values) into `out` at `o`. * @param x Left edge of the shape in points. * @param y Top edge in points (y down). * @param w Width. * @param h Height. * @param margin Capture margin in points. * @param scale Device pixels per point. * @param texel Device pixels per texel. * @param r0 Smallest lookup radius in points. * @param r1 Largest lookup radius in points. * @param backdropScale Backdrop texels per device pixel. * @param six Whether a blur fill is on. * @param width Target width in pixels. * @param height Target height in pixels. * @param maxLevels Maximum number of pyramid levels. */ export declare function backdropRegion(out: Int32Array, o: number, x: number, y: number, w: number, h: number, margin: number, scale: number, texel: number, r0: number, r1: number, backdropScale: number, six: boolean, width: number, height: number, maxLevels: number): void; /** * @brief Backdrop luminance as adaptive glass sees it: rounded to 1/64, then to 1/32 (ties up), at * most 1. * @param y Mean luminance of the captured backdrop, 0..1. */ export declare function luminanceLevel(y: number): number; /** * @brief Scheme adaptive glass shows over a backdrop: 0 dark, 1 light. * @details In dark surroundings it turns light over a backdrop brighter than 0.9; in light * surroundings it turns dark over one darker than 0.1. * @param level Luminance level from `luminanceLevel`. * @param scheme Surroundings. */ export declare function adaptScheme(level: number, scheme: Scheme): number; /** * @brief Whether built-in glass follows the backdrop luminance in these surroundings (the tinted, * reduce-transparency and increase-contrast settings keep the scheme of the surroundings). */ export declare function adapts(environment: number): boolean; /** * @brief Extended-range share of a screen: 0 at a headroom of 1 (standard dynamic range), 1 from a * headroom of 1.2 up. * @param headroom Brightest value the screen shows, relative to the standard white. */ export declare function headroomShare(headroom: number): number; /** * @brief Pack a material vector into the material rows of a block (rows 0..41 and 47..49; the color * layer rows are left to `packTint`). * @param d Block storage. * @param o Float offset of the block. * @param info Receives six values at `io`: shadow spread beyond the shape, largest blur radius of a * lookup, capture margin (points), backdrop texels per device pixel, shadow offset x and y (points, * y down). * @param p Material vector (`VECTOR` values). * @param presence 1 for the material itself; below 1 blur, lenses, face, bleed, shadows, edge * shade, fringes and lens layer are blended in from plain glass (the rim lights keep their * strength). * @param share Extended-range share in [0, 1] (the vector's own headroom wins when it has one). * @param scale Device pixels per point. * @param estimate Take the backdrop scale from the blur (the regular recipe's estimator) instead of * the vector. * @returns Feature bits. */ export declare function packParams(d: Float32Array, o: number, info: Float32Array, io: number, p: Float64Array, presence: number, share: number, scale: number, estimate: boolean): number; /** * @brief Pack the color layer of a tint (rows 42..46): a matrix that maps the glass luminance onto * a gradient through two anchors of the tint hue, at the tint's alpha. * @param d Block storage. * @param o Float offset of the block. * @param r Tint red, 0..1. * @param g Tint green, 0..1. * @param b Tint blue, 0..1. * @param a Tint strength, 0..1. * @param mix Scheme: 0 dark, 1 light. * @returns The tint feature bit, or 0 when the strength is 0. */ export declare function packTint(d: Float32Array, o: number, r: number, g: number, b: number, a: number, mix: number): number; /** * @brief The material vector of a description (any value it leaves out is off). * @param p Receives `VECTOR` values. * @param headroom Use the description's own extended-range share (else the renderer's). */ export declare function vectorOf(p: Float64Array, sp: MaterialSpec): void; /** * @brief Opacity-to-margin extent factor: 0 up to 0.005, then 0.3 ln(2 (a * - 0.005)) + 1.65 (at least 0), from 0.505 a straight line to 1.7 at 1. */ export declare function extentFactor(opacity: number): number; /** * @brief Pack a material description (see `packParams` for the rows and `info`). * @param presence 1 for the material itself (default); below 1 it is blended in from plain glass. * @param share Extended-range share in [0, 1] when the description has no `headroom` of its own * (default 0). * @param scale Device pixels per point (default 2). * @returns Feature bits, or -1 when a list has the wrong length or a value is not finite (`d` and * `info` untouched). */ export declare function packMaterial(d: Float32Array, o: number, info: Float32Array, io: number, sp: MaterialSpec, presence?: number, share?: number, scale?: number): number; /** * @brief Describe the first invalid material field. * @returns A field path and diagnostic, or an empty string for a valid description. */ export declare function explainMaterial(sp: MaterialSpec): string;