import { Expr } from '../gpu/contract'; type Val = Expr | number; /** * The sum of two values. * * Works on numbers and on vectors of the same size. * * @example * ```ts * const lifted = add(mul(noise, 0.5), 0.5) // a −1..1 signal moved into 0..1 * ``` * @see sub, mul */ export declare const add: (a: Val, b: Val) => Expr; /** * The first value minus the second. * * @example * ```ts * const outside = sub(1, coverage) // flip a 0..1 mask * ``` * @see add, neg */ export declare const sub: (a: Val, b: Val) => Expr; /** * The product of two values. * * Multiply a color by a 0..1 mask to fade it, or a coordinate by a prop to scale it. * * @example * ```ts * const rgb = mul(params.uniforms.color.member('rgb'), coverage) * ``` * @see div, add */ export declare const mul: (a: Val, b: Val) => Expr; /** * The first value divided by the second. * * Dividing by zero produces infinity on the GPU, so guard a prop with `max` first. * * @example * ```ts * const normalized = div(dist, max(params.uniforms.radius, 0.001)) * ``` * @see mul, max */ export declare const div: (a: Val, b: Val) => Expr; /** * The value with its sign flipped. * * @example * ```ts * const falloff = exp(neg(mul(dist, 4))) * ``` * @see sub, abs */ export declare const neg: (a: Val) => Expr; /** * The value without its sign. * * Turns a signed distance into a distance from the line, so a stroke covers both sides. * * @example * ```ts * const fromLine = abs(sub(uv.member('y'), 0.5)) * ``` * @see sign, neg */ export declare const abs: (x: Val) => Expr; /** * The value rounded down to a whole number. * * Gives the cell index when you tile a coordinate. * * @example * ```ts * const column = floor(mul(uv.member('x'), params.uniforms.columns)) * ``` * @see fract, ceil */ export declare const floor: (x: Val) => Expr; /** * The value rounded up to a whole number. * * @example * ```ts * const rows = ceil(div(height, cell)) * ``` * @see floor */ export declare const ceil: (x: Val) => Expr; /** * The fractional part of a value, 0..1. * * Repeats a coordinate every whole unit, which is how a pattern tiles. * * @example * ```ts * const inCell = fract(mul(uv, params.uniforms.tiles)) // 0..1 inside each tile * ``` * @see floor */ export declare const fract: (x: Val) => Expr; /** * The square root of a value. * * @example * ```ts * const dist = sqrt(add(mul(dx, dx), mul(dy, dy))) * ``` * @see length, pow */ export declare const sqrt: (x: Val) => Expr; /** * The first value raised to the power of the second. * * Shapes a 0..1 value: powers above 1 push it toward 0, powers below 1 toward 1. Keep the * base non-negative. * * @example * ```ts * const hardened = pow(coverage, params.uniforms.hardness) * ``` * @see sqrt, exp */ export declare const pow: (x: Val, y: Val) => Expr; /** * e raised to the value. * * With a negative argument it is the classic smooth falloff. * * @example * ```ts * const glow = exp(neg(mul(dist, params.uniforms.falloff))) * ``` * @see exp2, log, gaussBell */ export declare const exp: (x: Val) => Expr; /** * The natural logarithm of a value. * * @example * ```ts * const octave = log(max(scale, 1)) * ``` * @see exp */ export declare const log: (x: Val) => Expr; /** * The sine of an angle in radians, −1..1. * * @example * ```ts * const wave = sin(add(mul(uv.member('x'), 12), time)) * ``` * @tip A degrees prop needs `mul(angle, 0.017453292519943295)` first. * @see cos, tan */ export declare const sin: (x: Val) => Expr; /** * The cosine of an angle in radians, −1..1. * * @example * ```ts * const spun = rotate2(delta, cos(angle), sin(angle)) * ``` * @tip A degrees prop needs `mul(angle, 0.017453292519943295)` first. * @see sin, rotate2 */ export declare const cos: (x: Val) => Expr; /** * The tangent of an angle in radians. * * @example * ```ts * const slope = tan(mul(params.uniforms.tilt, 0.017453292519943295)) * ``` * @see sin, cos, atan2 */ export declare const tan: (x: Val) => Expr; /** * The angle of the point (x, y) in radians, −π..π. * * Takes y first. Turns an offset from a center into an angle around it. * * @example * ```ts * const angle = atan2(delta.member('y'), delta.member('x')) * ``` * @see sin, cos */ export declare const atan2: (y: Val, x: Val) => Expr; /** * The smaller of two values. * * @example * ```ts * const capped = min(brightness, 1) * ``` * @see max, clamp */ export declare const min: (a: Val, b: Val) => Expr; /** * The larger of two values. * * @example * ```ts * const safeRadius = max(params.uniforms.radius, 0.001) * ``` * @see min, clamp */ export declare const max: (a: Val, b: Val) => Expr; /** * The value limited to the range `lo`..`hi`. * * @example * ```ts * const alpha = clamp(add(body, ring), 0, 1) * ``` * @see min, max */ export declare const clamp: (x: Val, lo: Val, hi: Val) => Expr; /** * A blend from `a` to `b` by `t`, where 0 gives `a` and 1 gives `b`. * * Works on numbers and on colors. For two colors, pass `t` through `splat3` to blend every * channel by the same amount. * * @example * ```ts * const rgb = mix(params.uniforms.colorA.member('rgb'), params.uniforms.colorB.member('rgb'), splat3(coverage)) * ``` * @see smoothstep, splat3 */ export declare const mix: (a: Val, b: Val, t: Val) => Expr; /** * A hard edge: 0 when `x` is below `edge`, 1 from `edge` on. * * @example * ```ts * const lit = step(params.uniforms.threshold, brightness) * ``` * @see smoothstep */ export declare const step: (edge: Val, x: Val) => Expr; /** * A soft edge: 0 below `e0`, 1 above `e1`, an S-curve between. * * The everyday word for turning a distance into a soft mask. Swap `e0` and `e1` to fade the * other way. * * @example * ```ts * const coverage = sub(1, smoothstep(radius, add(radius, softness), dist)) // 1 inside, fading out * ``` * @see step, mix */ export declare const smoothstep: (e0: Val, e1: Val, x: Val) => Expr; /** * −1, 0 or 1 by the sign of the value. * * @example * ```ts * const side = sign(sub(uv.member('x'), 0.5)) * ``` * @see abs */ export declare const sign: (x: Val) => Expr; /** * The length of a vector. * * The distance from the origin, or from a center when you pass the offset from it. * * @example * ```ts * const dist = length(sub(uv, params.uniforms.center)) * ``` * @see distance, normalize */ export declare const length: (v: Val) => Expr; /** * The distance between two points. * * @example * ```ts * const toPointer = distance(uv, params.ctx.pointer) * ``` * @see length */ export declare const distance: (a: Val, b: Val) => Expr; /** * The dot product of two vectors. * * With two unit vectors it is the cosine of the angle between them, which is how a light * direction meets a surface normal. * * @example * ```ts * const facing = max(dot(normal, lightDir), 0) * ``` * @see normalize, cross */ export declare const dot: (a: Val, b: Val) => Expr; /** * The vector scaled to length 1. * * A zero vector gives NaN, so keep the input non-zero. * * @example * ```ts * const dir = normalize(sub(params.uniforms.target, params.uniforms.origin)) * ``` * @see length, dot */ export declare const normalize: (v: Val) => Expr; /** * The cross product of two 3D vectors. * * @example * ```ts * const normal = normalize(cross(tangentX, tangentY)) * ``` * @see dot, normalize */ export declare const cross: (a: Val, b: Val) => Expr; /** * A 2D point rotated around the origin. * * Pass the cosine and sine of the angle in radians, computed once, and the same pair * rotates every point. * * @example * ```ts * const spun = local(rotate2(delta, cos(angle), sin(angle)), 'spun') * ``` * @see cos, sin */ export declare const rotate2: (p: Val, cosA: Val, sinA: Val) => Expr; /** * The direction `i` bounced off a surface with unit normal `n`. * * @example * ```ts * const bounce = reflect(viewDir, normal) * ``` * @see refract, normalize */ export declare const reflect: (i: Val, n: Val) => Expr; /** * The direction `i` bent through a surface with unit normal `n`. * * `eta` is the ratio of refractive indices, about 0.66 going from air into glass. * * @example * ```ts * const bent = refract(viewDir, normal, 0.66) * ``` * @see reflect */ export declare const refract: (i: Val, n: Val, eta: Val) => Expr; /** * 2 raised to the value. * * @example * ```ts * const octaveScale = exp2(octave) * ``` * @see exp */ export declare const exp2: (x: Val) => Expr; /** * A random but stable angle in radians, 0..2π, from a seed. * * Use it to start each of several sine motions at a different point so they do not move in * step. `salt` is a pair of constants. Give each independent phase its own pair. * * @example * ```ts * const wobble = sin(add(mul(t, 0.7), hashPhase(params.uniforms.seed, {k: 53.7, big: 3847.2}))) * ``` * @see sin */ export declare const hashPhase: (seed: Val, salt: { k: number; big: number; }) => Expr; /** * True when `a` is less than `b`. * * A condition for `select`. * * @example * ```ts * const rgb = select(lt(dist, radius), insideRgb, outsideRgb) * ``` * @see le, gt, ge, select */ export declare const lt: (a: Val, b: Val) => Expr; /** * True when `a` is less than or equal to `b`. * * @example * ```ts * const inBand = select(le(abs(d), width), 1, 0) * ``` * @see lt, gt, ge, select */ export declare const le: (a: Val, b: Val) => Expr; /** * True when `a` is greater than `b`. * * @example * ```ts * const highlights = select(gt(luma, 0.5), luma, 0) * ``` * @see ge, lt, le, select */ export declare const gt: (a: Val, b: Val) => Expr; /** * True when `a` is greater than or equal to `b`. * * @example * ```ts * const rightHalf = select(ge(uv.member('x'), 0.5), 1, 0) * ``` * @see gt, lt, le, select */ export declare const ge: (a: Val, b: Val) => Expr; /** * `ifTrue` when the condition holds, otherwise `ifFalse`. * * Both values are computed at every pixel, so this picks rather than skips work. For a soft * transition use `mix` or `smoothstep` instead. * * @example * ```ts * const rgb = select(lt(dist, radius), params.uniforms.fill.member('rgb'), params.uniforms.background.member('rgb')) * ``` * @see lt, gt, mix */ export declare const select: (cond: Expr, ifTrue: Val, ifFalse: Val) => Expr; /** * A plain number as an expression. * * Rarely needed: every word here accepts numbers directly. Reach for it when something * wants an expression and you only have a constant. * * @example * ```ts * const half = float(0.5) * ``` * @see vec2, vec3, vec4 */ export declare const float: (n: number) => Expr; /** * A 2D vector from two values. * * @example * ```ts * const offset = vec2(params.uniforms.shiftX, params.uniforms.shiftY) * ``` * @see vec3, vec4 */ export declare const vec2: (x: Val, y: Val) => Expr; /** * A 3D vector from three values, often a color without alpha. * * @example * ```ts * const warmWhite = vec3(1, 0.96, 0.9) * ``` * @see vec2, vec4, splat3 */ export declare const vec3: (x: Val, y: Val, z: Val) => Expr; /** * A 4D vector, usually the final color with alpha. * * Takes four numbers, or a vec3 followed by alpha. Return one of these from `paint:`. * * @example * ```ts * return vec4(rgb, coverage) * ``` * @see vec3, vec2 */ export declare const vec4: (...parts: Val[]) => Expr; /** * One number copied into all three channels of a vec3. * * The usual way to blend two colors by a single amount with `mix`. * * @example * ```ts * const rgb = mix(darkRgb, lightRgb, splat3(brightness)) * ``` * @see mix, vec3 */ export declare const splat3: (x: Val) => Expr; /** * A value computed once per pixel and shared by everything that reads it. * * Wrap any expression you use twice or more. `hint` is a short name that appears in the * generated code and only has to be readable. * * @example * ```ts * const dist = local(length(sub(uv, params.uniforms.center)), 'dist') * ``` * @tip Without it, the same math is repeated at every place you use the value. */ export declare const local: (e: Expr, hint: string) => Expr; /** * A soft hinge: about 0 for values well below zero, about `x` above, rounded near zero. * * `k` is the width of the rounded corner. Use it where a hard `max(x, 0)` would show a * visible crease. * * @example * ```ts * const past = local(softPlus(sub(beam.along, beam.length), mul(softness, 0.6)), 'past') * ``` * @see max, smoothstep */ export declare const softPlus: (x: Expr, k: Val) => Expr; /** * A bell curve: 1 at zero, falling toward 0 on both sides. * * `k` sets the width. Larger values give a narrower bell. Pass a distance or a centered * coordinate as `x`. * * @example * ```ts * const profile = gaussBell(div(beam.across, beamWidth), 2.5) * ``` * @see exp, smoothstep */ export declare const gaussBell: (x: Expr, k: Val) => Expr; export {}; //# sourceMappingURL=math.d.ts.map