import { Expr, GpuFragmentParams } from '../gpu/contract'; import { PropConfig } from '../types'; import { ArgSpec } from './invoke'; /** The WGSL types a bound name can have inside a body. */ export type WgslType = 'f32' | 'vec2f' | 'vec3f' | 'vec4f' | 'texture_2d' | 'sampler'; /** * One entry of `inputs`: the value to bind under a name — a prop `p('x')`, a context token * `ctx.time`, a `Scalar`, or a number — optionally with its WGSL type spelled out as * `{value, type}`. A prop takes its own type; a `Scalar` or a number is `f32`. */ export type WgslInput = ArgSpec | { readonly value: ArgSpec; readonly type: WgslType; }; /** The long form of a body: `wgsl({body, inputs, alpha, name})`. */ export interface WgslSpec { /** The WGSL statements. Must `return` a `vec4f` color. */ readonly body: string; /** Extra names to bind, on top of the props and context values bound automatically. */ readonly inputs?: Record; /** * Gather filters only: what alpha the returned color is in. `'premultiplied'` (default) * lets the engine unpremultiply it for you; `'straight'` returns it as-is. */ readonly alpha?: 'premultiplied' | 'straight'; /** A readable name for the generated WGSL function. Defaults to the definition's name. */ readonly name?: string; } /** What `wgsl` returns: a body ready to sit in `paint:` or `effect:`. */ export declare class WgslBody { readonly kind: "wgsl"; readonly spec: WgslSpec; /** The names the body refers to (comments stripped, member accesses excluded). */ readonly identifiers: ReadonlySet; /** Lowered `tgpu.fn`s, one per distinct parameter signature. */ private readonly fns; constructor(spec: WgslSpec); /** True when the body samples `childTexture`, which makes it a gather filter. */ get samplesChild(): boolean; /** @internal — the `tgpu.fn` for a parameter signature, created once per body. */ fnFor(signature: string, make: () => unknown): unknown; } /** * True when a value came from `wgsl`. * * @internal */ export declare function isWgslBody(value: unknown): value is WgslBody; /** * Write the per-pixel math by hand, as one WGSL function body that returns a `vec4f` color. * * Put it in `paint:` for a generator or `effect:` for a filter. Every name the body uses is * bound for you. The definition's props come by name: colors as `vec4f` in linear RGB with * alpha, positions as `vec2f` in uv, numbers and booleans as `f32`, select props as their * numeric value. The context comes as `uv` (0–1 across the canvas, y down), `time` (seconds; * the layer's own clock when `animatedTime` is declared, paused at speed 0), `aspect` (width * / height), `viewport` (the frame size in device pixels) and `pointer` (the mouse in uv). In * an `effect:` body `child` is the color of the layer inside at this pixel. Sample * `childTexture` with `childSampler` instead when you need neighbouring pixels (a blur, a * displacement): that gives the filter its own render pass and hands you premultiplied * color, which is unpremultiplied for you on the way out. Template values (`${OCTAVES}`) are * pasted in as text, so a constant can be a loop bound. * * Use the `{body, inputs, alpha}` form to bind extra names (`inputs: {t: ctx.time, k: 4}`) or * to say a gather body already returns straight alpha (`alpha: 'straight'`). * * @example * ```ts * paint: wgsl` * let d = length((uv - center) * vec2f(aspect, 1.0)) / radius; * return vec4f(mix(outer.rgb, inner.rgb, 1.0 - smoothstep(0.0, 1.0, d)), 1.0); * ` * ``` * @example * ```ts * // A gather filter: the layer inside, sampled at a rippled coordinate. * effect: wgsl` * let wave = sin(length(uv - center) * frequency - time * 4.0) * amplitude; * return textureSample(childTexture, childSampler, uv + wave); * ` * ``` * @tip The names `uv`, `time`, `aspect`, `viewport`, `pointer`, `child`, `childTexture` and `childSampler` belong to the body; a prop spelled the same is not bound, so rename the prop. * @see defineShader, ctx, p */ export declare function wgsl(spec: WgslSpec): WgslBody; export declare function wgsl(body: string): WgslBody; export declare function wgsl(strings: TemplateStringsArray, ...values: unknown[]): WgslBody; /** * @internal The identifiers a body references. Member accesses (`color.rgb` → `rgb`) are * skipped by the negative lookbehind, so a prop named like a swizzle is never bound by * accident. */ export declare function scanIdentifiers(source: string): ReadonlySet; /** * @internal The WGSL type a prop binds as, from its config — mirroring the uniform bridge's * packing rules so the parameter type always matches the struct field. `null` for a prop * that is CPU-only (never a struct field) or expands to arrays (color stops / lists). */ export declare function wgslTypeForProp(config: PropConfig): WgslType | null; /** Where a body runs: a generator's `paint:`, or a pointwise or gather filter's `effect:`. */ export type WgslHost = 'generator' | 'pointwise' | 'gather'; /** * Lower a body for a host. Returns the composition-time builder: it selects the bindings * the body references, builds (once per signature) the string-form `tgpu.fn`, and returns * the `call(...)` Expr. */ export declare function lowerWgsl(body: WgslBody, host: WgslHost, definition: { name: string; props: Record>; animatedTime?: { speed: string; }; }): (params: GpuFragmentParams) => Expr; //# sourceMappingURL=wgsl.d.ts.map