UNPKG

@motion-core/motion-gpu

Version:

Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.

149 lines 4.65 kB
/// <reference types="@webgpu/types" /> import { type MaterialLineMap } from '../core/material-preprocess.js'; import type { MaterialDefines, MaterialIncludes } from '../core/material.js'; export interface PingPongShaderPassOptions<TDefineKey extends string = string, TIncludeKey extends string = string> { /** * Fragment WGSL source containing `fn frag(uv: vec2f) -> vec4f`. * * The generated shader exposes `motiongpuPreviousSampler` and * `motiongpuPrevious` for reading the previous ping-pong state. */ fragment: string; /** * Material texture key that will receive the latest ping-pong output. */ target: string; /** * Explicit simulation texture width. If omitted, derived from canvas width * scale. */ width?: number; /** * Explicit simulation texture height. If omitted, derived from canvas height * scale. */ height?: number; /** * Canvas-relative scale for implicit dimensions. */ scale?: number; /** * Ping-pong render texture format. Default: `rgba16float`. */ format?: GPUTextureFormat; /** * Previous-state sampler filter. Default: `linear`. */ filter?: GPUFilterMode; /** * Previous-state sampler U address mode. Default: `clamp-to-edge`. */ addressModeU?: GPUAddressMode; /** * Previous-state sampler V address mode. Default: `clamp-to-edge`. */ addressModeV?: GPUAddressMode; /** * Number of fragment iterations per frame. Default: 1. */ iterations?: number; /** * Color used to initialize/reset both ping-pong textures. Default: transparent black. */ clearColor?: [number, number, number, number]; /** * Optional compile-time define constants injected before the fragment. */ defines?: MaterialDefines<TDefineKey>; /** * Optional WGSL include chunks used by `#include <name>` directives. */ includes?: MaterialIncludes<TIncludeKey>; /** * Enables/disables this pass. */ enabled?: boolean; } /** * Fragment-shader feedback pass for iterative GPU simulations. * * The renderer owns two render textures, alternates read/write direction per * iteration, then exposes the latest texture view through the declared material * texture slot. */ export declare class PingPongShaderPass { /** * Enables/disables this pass without removing it from graph. */ enabled: boolean; /** * Discriminant flag for render graph to identify fragment feedback passes. */ readonly isPingPongShader: true; private fragment; private fragmentLineMap; private target; private width; private height; private scale; private format; private filter; private addressModeU; private addressModeV; private iterations; private clearColor; private totalIterations; private resetPending; constructor(options: PingPongShaderPassOptions); /** * Replaces fragment source and updates define/include preprocessing. */ setFragment(fragment: string, options?: { defines?: MaterialDefines; includes?: MaterialIncludes; }): void; /** * Updates iteration count. */ setIterations(count: number): void; /** * Updates explicit dimensions. Passing `undefined` returns that axis to scale-based sizing. */ setDimensions(width?: number, height?: number): void; /** * Updates canvas-relative scale used for implicit dimensions. */ setScale(scale: number): void; /** * Requests both ping-pong textures to be cleared before the next iteration. */ reset(clearColor?: [number, number, number, number]): void; /** * Returns and clears the pending reset color for renderer use. */ consumeResetColor(): [number, number, number, number] | null; /** * Returns the texture key holding the latest result. */ getCurrentOutput(): string; /** * Advances the iteration accumulator by the current iteration count. */ advanceFrame(): void; resolveSize(canvasSize: { width: number; height: number; }): { width: number; height: number; }; getTarget(): string; getFragment(): string; getFragmentLineMap(): MaterialLineMap; getIterations(): number; getFormat(): GPUTextureFormat; getFilter(): GPUFilterMode; getAddressModeU(): GPUAddressMode; getAddressModeV(): GPUAddressMode; getClearColor(): [number, number, number, number]; dispose(): void; } //# sourceMappingURL=PingPongShaderPass.d.ts.map