@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
68 lines • 2.65 kB
TypeScript
import type { Func1, Func2, Vec2Term } from "@thi.ng/shader-ast";
export interface FnSampleOpts {
/**
* Pixel radius per axis. The function will be sampled at ± N around the
* given base fragment position.
*
* @defaultValue 1
*/
radius: number;
/**
* Number of sub-fragment steps per axis. The function will be sampled at ±
* {@link FnSampleOpts.radius} around the given base fragment position.
*
* @defaultValue 4
*/
steps: number;
/**
* If true, the {@link functionSampler} will return 1.0 for the entire area
* below the curve (i.e. turns a line plot into an area plot). By default
* only the fragments touching the curve will produce non-zero results.
*
* @defaultValue false
*/
area: boolean;
/**
* Min X position (in function domain). The function will only be evaluated
* within the `[min,max]` domain.
*
* @defaultValue 0
*/
min: number;
/**
* Max X position (in function domain). The function will only be evaluated
* within the `[min,max]` domain.
*
* @defaultValue 1
*/
max: number;
}
/**
* Higher order function. Takes a unary 1D function `fn` to evaluate and plot
* within a given interval. Also takes a point mapping function `map` to
* transform fragment coordinates into the function domain. Returns a new
* specialized function, which then accepts 2x vec2 args: a fragment coordinate
* and overall viewport dimensions. It then transforms the point into the
* function domain and evaluates/samples the function `fn` in the sub-pixel
* region around the input position. Returns a coverage ratio of how many
* samples where on the curve.
*
* @remarks
* The function domain, sampling region & quality can be configured via options.
* See {@link FnSampleOpts} for details.
*
* See {@link functionDomainMapper} for a configurable point mapping function.
*/
export declare const functionSampler: (fn: Func1<"float", "float">, map: Func2<"vec2", "vec2", "vec2">, opts?: Partial<FnSampleOpts>) => import("@thi.ng/shader-ast").TaggedFn2<"vec2", "vec2", "float">;
/**
* Higher order helper function for {@link functionSampler} to map fragment
* coordinates within a screen rect (defined by `pos` & `size` in UV space) into
* the domain of the sampled function interval.
*
* @param amin
* @param amax
* @param bmin
* @param bmax
*/
export declare const functionDomainMapper: (amin: Vec2Term, amax: Vec2Term, bmin?: Vec2Term, bmax?: Vec2Term) => import("@thi.ng/shader-ast").TaggedFn2<"vec2", "vec2", "vec2">;
//# sourceMappingURL=function.d.ts.map