import { d } from './index'; import { Expr, GpuFragmentParams, KitTexture, GpuMediaTexture } from '../contract'; import { SurfacePatternMode } from './sdf3d'; export declare const SVG_SDF_SIZE = 512; /** Circle SDF. `radius` = circle radius in UV space. */ export declare const circleSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radius: d.F32) => d.F32>; /** * Regular polygon SDF. `radius` = inradius (center → nearest edge midpoint), `sides` = side * count. Nearest-sector half-plane formula: exact at edge midpoints and vertices for any convex * polygon. Caller applies rotation externally. */ export declare const polygonSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radius: d.F32, sides: d.F32) => d.F32>; /** * Flower SDF (N-petalled). `outerRadius` = center→petal-tip, `sides` = petals, `innerRatio` = * valley radius / outer radius. Triangular radial wave → distinct tips, clean V-shaped valleys. * Caller applies rotation externally. */ export declare const flowerSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, outerRadius: d.F32, sides: d.F32, innerRatio: d.F32) => d.F32>; /** * Star SDF (N-pointed) — exact segment-based star polygon. `outerRadius` = center→tip, `sides` = * points, `innerRatio` = inner vertex radius / outer radius. True Euclidean SDF: flat sides, * sharp corners. Caller applies rotation externally. */ export declare const starSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, outerRadius: d.F32, sides: d.F32, innerRatio: d.F32) => d.F32>; /** * Ring (annulus) SDF. `radius` = center→ring centerline, `thickness` = ring half-width. Inside = * the ring material. Rotationally symmetric (no rotation needed). */ export declare const ringSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radius: d.F32, thickness: d.F32) => d.F32>; /** * Cross (plus-sign) SDF — exact SDF of a horizontal ∪ vertical rectangle. `size` = arm * half-length, `thickness` = arm half-width, `rounding` = corner rounding offset. Caller applies * rotation externally. */ export declare const crossSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, size: d.F32, thickness: d.F32, rounding: d.F32) => d.F32>; /** * Rounded Rectangle SDF — exact SDF of a rectangle with uniformly rounded corners. `width`/ * `height` = half-extents, `rounding` = corner radius. Caller applies rotation externally. */ export declare const roundedRectSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, width: d.F32, height: d.F32, rounding: d.F32) => d.F32>; /** * Ellipse SDF (scaled-circle approximation — exact at the boundary). `radiusX`/`radiusY` = * semi-axes. The `min(a,b)` correction keeps |gradient| ≈ 1 near the edge (where smoothstep / * Glass refraction care about accuracy). Caller applies rotation externally. */ export declare const ellipseSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radiusX: d.F32, radiusY: d.F32) => d.F32>; /** * Vesica (lens) SDF — intersection of two overlapping circles. `radius` = circle radius, * `spread` = half-distance between centers as a fraction of radius (0 → single circle, 1 → * infinitely thin lens). Caller applies rotation externally. */ export declare const vesicaSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radius: d.F32, spread: d.F32) => d.F32>; /** * Crescent (moon) SDF — outer circle with an inner circle subtracted (iq's moon SDF). * `outerRadius` = outer circle radius, `innerRatio` = inner radius / outer radius, `offset` = * horizontal distance between the two centers. Caller applies rotation externally. */ export declare const crescentSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, outerRadius: d.F32, innerRatio: d.F32, offset: d.F32) => d.F32>; /** * Trapezoid SDF — exact SDF of an axis-aligned trapezoid centered at the origin. `r1` = bottom * half-width, `r2` = top half-width, `he` = half-height. Caller applies rotation externally. */ export declare const trapezoidSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, r1: d.F32, r2: d.F32, he: d.F32) => d.F32>; /** * Heart SDF (iq). `radius` scales the heart to fit within that radius. Works in iq's heart space * (point near origin, lobes around y≈1.2); screen-y is downward so `dy` is negated to put the * point at the bottom and lobes at the top, then a recenter + √-fit scale. Caller applies * rotation externally. */ export declare const heartSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radius: d.F32) => d.F32>; /** * Arc / pie sector SDF (iq's sdPie) — a filled circular wedge opening ±`halfAngle` about +y. * `radius` = sector radius, `halfAngle` = half the aperture (radians). Caller applies rotation * externally. */ export declare const arcSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radius: d.F32, halfAngle: d.F32) => d.F32>; /** * Teardrop SDF — a 2D rounded cone: a bulb of radius `radius` at the base tapering to a sharp * point a distance `h` away. `dy` negated so the bulb sits at the bottom, point up (screen-y is * down). Exact. Caller applies rotation externally. */ export declare const teardropSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, radius: d.F32, h: d.F32) => d.F32>; /** * Parallelogram SDF (iq). `wi` = half-width, `he` = half-height, `sk` = horizontal skew of the * top edge. Exact. Caller applies rotation externally. */ export declare const parallelogramSdf: import('typegpu').TgpuFn<(dx: d.F32, dy: d.F32, wi: d.F32, he: d.F32, sk: d.F32) => d.F32>; /** * Aspect-correct + rotate a screen UV into shape-local space centered on `center`. The shape * preamble: aspect-correct X (circular shapes stay circular), flip `center.y` back * (transformPosition stores `(x, 1 - y)`, so `1 - center.y` recovers the authored y), then rotate * the delta by `rotation` degrees. Pass `rotation = 0` for shapes with no rotation (the cos/sin * fold to identity). Returns the rotated `(dx, dy)` offset to feed an SDF primitive. */ export declare const shapeLocalCoords: import('typegpu').TgpuFn<(center: d.Vec2f, rotation: d.F32, uv: d.Vec2f, aspect: d.F32) => d.Vec2f>; /** The stroke/softness mask a shape's fragment builder mixes fill + stroke color with. */ export declare const ShapeMask: d.WgslStruct<{ overallMask: d.F32; strokeBlend: d.F32; }>; /** * Fill coverage + stroke blend factor from an SDF value. * `overallMask` fades the whole shape out at its outer edge (softness-wide smoothstep); `strokeBlend` * fades the fill color into the stroke color at the inner edge (0 when there's no stroke). Stroke * boundaries are expressed in SDF space (boundary at 0) — `strokePosition` 0=outside / 1=center / * 2=inside — so it works for any primitive (circles feed `distance - circleEdge`, which is exactly * `circleSdf`, so the same helper covers Circle too). */ export declare const strokeMaskFromSdf: import('typegpu').TgpuFn<(dist: d.F32, softness: d.F32, strokeThickness: d.F32, strokePosition: d.F32) => d.WgslStruct<{ overallMask: d.F32; strokeBlend: d.F32; }>>; /** * The shape fragment TAIL, at the Expr/builder level: take a `ShapeMask` (from * `strokeMaskFromSdf`) plus the fill and stroke colours, blend fill → stroke by `strokeBlend` in * the given colour space, and fade the whole shape by `overallMask`. * * `colorSpaceMode` is a COMPILE-TIME JS number (the `colorSpace` prop is `compileTime: true`), so * the variant is selected here in JS and only that variant's math is emitted — this is a builder, * not something to call from a `'use gpu'` body. The unknown-mode fallback is linear, matching * every shape's inline `?? mixColorsLinear`. * * Every analytic 2D shape shader shares this tail; `scaffolds/sdfShape.ts` calls it for the fleet, * and a shape that needs a custom fragment can call it directly instead of re-deriving the mix. */ export declare function fillStrokeColor(mask: Expr, fill: Expr, stroke: Expr, colorSpaceMode: number): Expr; /** * Fetch a pre-computed SDF binary from a URL and fill `sdfData` in place. Supports two formats * (detected by byte length): * - compact: Uint16, two bytes per pixel — decode [0, 65535] → [-1, 1] * - legacy: Float32, four bytes per pixel — copy directly * * The SVG-shape path uploads `sdfData` into an r16float DataTexture via * `textureManager.createDataTexture` (r16float is always linear-filterable; r32float requires the * optional `float32-filterable` feature), then samples it through the fn-arg / KitTexture path. */ export declare function loadSdfFromUrl(url: string, sdfData: Float32Array): Promise; /** * The shared single-channel SDF data texture: an `r16float` `SVG_SDF_SIZE²` field initialised to * 0.5 (outside — invisible until the async load lands), with the async `.bin` load + on-ready * re-upload scheduled via `params.onBeforeRender` (a `needsUpdate` flag), and disposal via * `params.onCleanup`. Returned as `{kitTexture, texture}` so the FLAT sampler samples `kitTexture` * in the fragment while the SVG-3D setup binds the raw `texture` into its compute march kernel. */ export declare function createSdfDataTexture(params: GpuFragmentParams, shapeSdfUrl: string): { kitTexture: KitTexture; texture: GpuMediaTexture; getVersion: () => number; }; /** * Flat SVG-SDF sampler. Backs the shape-effect shaders over a custom uploaded SVG shape. `.r` of * the returned vec4 is the signed distance (RedFormat → `.r`, matching what the effects read). * Returns `(uv) => sample` for use exactly like the analytic sampler. */ export declare function createSvgSdfSampler(params: GpuFragmentParams, shapeSdfUrl: string): (uv: Expr) => Expr; /** * Flat SVG-SDF sampler with BAKED forward-difference gradients. An `rgba16float` field: `.r` = * distance, `.g/.b` = the per-texel forward differences `(f(uv+ε)−f(uv))/ε` in x/y, precomputed * once on the CPU when the SDF loads (the field is static per URL). Effects that take finite * differences of the flat field read `.g/.b` of their single centre tap instead of paying two * extra texture samples. `.a` = 1 (matching the RedFormat sampler's implicit alpha). RGBA needs 4 * channels, so this uses a `createMediaTexture` (`rgba16float`) — `createDataTexture` is * single-channel only. */ export declare function createSvgSdfSamplerWithGradients(params: GpuFragmentParams, shapeSdfUrl: string): (uv: Expr) => Expr; /** The shape sub-prop accessor Exprs a consumer supplies to `createAnalyticSdfSampler`. Missing * keys default to 0.0; a shape only reads the sub-props its formula needs (see the switch). */ export interface AnalyticSubProps { radius?: Expr; sides?: Expr; rounding?: Expr; innerRatio?: Expr; rotation?: Expr; height?: Expr; offset?: Expr; aperture?: Expr; } /** * Aperture (full angle, degrees) → half-angle (radians): × π/360. Pre-folded module const, because * `Math.*` inside a `'use gpu'` body is unavailable. * * Exported for the Arc shader, whose body needs the same conversion. A body cannot read * `sdf.APERTURE_TO_HALFANGLE` directly (a member access inside `'use gpu'` is not proven to fold), * so Arc aliases it to a module-scope local at import time and references THAT. */ export declare const APERTURE_TO_HALFANGLE = 0.008726646259971648; /** * Build the compile-time `tgpu.fn` for `shapeType`: `(uv, radius, sides, rounding, innerRatio, * rotation, height, offset, aperture) => vec4(dist, 0, 0, 1)`. One primitive is selected by a * build-time JS branch (`shapeType` is a plain string), so only its math is emitted. Rotation is * applied to (dx, dy) once here — circle/ring are rotation-invariant so passing the rotated coords * is identical to the unrotated fast path. Exported (over the closure) so it is directly resolvable. */ export declare function buildAnalyticSdfFn(shapeType: string): import('typegpu').TgpuFn<(uv: d.Vec2f, r: d.F32, n: d.F32, round: d.F32, inner: d.F32, rot: d.F32, h: d.F32, off: d.F32, ap: d.F32) => d.Vec4f>; /** * Build the compile-time analytic 2D SDF sampler for `shapeType`. `patternMode` is accepted for * signature parity with the 3D path but has no effect on flat 2D shapes (they never fill the * surface-locked `.g/.b` pattern coords); it is documented here so a consumer can pass it * uniformly. */ export declare function createAnalyticSdfSampler(shapeType: string, sub: AnalyticSubProps, _patternMode?: SurfacePatternMode): (uv: Expr) => Expr; /** The eight analytic shape sub-prop fields a flat shape-effect shader declares as `extraFields` * (spread into the definition). Driven each frame by `driveAnalyticSubProps`. These are generic * defaults; the JSON drives the real values on the first `onBeforeRender`, before the first * render. */ export declare const ANALYTIC_SDF_EXTRA_FIELDS: Record; /** * Wire the per-frame CPU resolution of the analytic shape sub-props from the shape JSON and return * the `AnalyticSubProps` accessor Exprs for `createAnalyticSdfSampler`. The consumer MUST declare * `...ANALYTIC_SDF_EXTRA_FIELDS` in its definition's `extraFields`. `getShapeConfig` returns the * live `shape` prop value (JSON string or object) — pass `() => params.getCpuValue('shape')`. */ /** The CPU-resolved analytic shape sub-props (the JSON → sub-prop mapping, aliases included) — the * values `driveAnalyticSubProps` publishes as `_sa*` extraFields, for a consumer whose OWN compute * params carry them. */ export declare function analyticSubPropValues(cfg: Record): { radius: number; sides: number; rounding: number; innerRatio: number; rotation: number; height: number; offset: number; aperture: number; }; /** Parse the live `shape` prop (JSON string or object) into its config record. */ export declare function parseShapeConfigValue(raw: unknown): Record; export declare function driveAnalyticSubProps(params: GpuFragmentParams, getShapeConfig: () => unknown): AnalyticSubProps; //# sourceMappingURL=sdf.d.ts.map