---
title: "Builtins, a category in the TypeShade API reference"
description: "Builtins in the TypeShade API reference. IR builder functions for math, vector and texture operations. Each returns an IR node."
url: https://typeshade.dev/api/builtins/
language: en
---

# Builtins

96 members

IR builder functions for math, vector and texture operations. Each returns an IR node. A shader file calls the builtins that the language reference lists.

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

**[`abs`](https://typeshade.dev/api/abs/) Function**

`abs(x)`: absolute value, component-wise.

**[`acos`](https://typeshade.dev/api/acos/) Function**

`acos(x)`: arccosine of x, returning radians in \[0, π\], component-wise.

**[`acosh`](https://typeshade.dev/api/acosh/) Function**

`acosh(x)`: inverse hyperbolic cosine, component-wise.

**[`add`](https://typeshade.dev/api/add/) Function**

a + b as a free function, the spelling for an expression whose left operand is a literal.

**[`asin`](https://typeshade.dev/api/asin/) Function**

`asin(x)`: arcsine of x, returning radians in \[-π/2, π/2\], component-wise.

**[`asinh`](https://typeshade.dev/api/asinh/) Function**

`asinh(x)`: inverse hyperbolic sine, component-wise; defined over all reals.

**[`atan`](https://typeshade.dev/api/atan/) Function**

`atan(x)`: single-argument arctangent, returning radians in (-π/2, π/2), component-wise.

**[`atan2`](https://typeshade.dev/api/atan2/) Function**

`atan2`(y, x): two-argument arctangent, resolving the full angle in \[-π, π\] from a (y, x) pair.

**[`atanh`](https://typeshade.dev/api/atanh/) Function**

`atanh(x)`: inverse hyperbolic tangent, component-wise.

**[`bitcastF32`](https://typeshade.dev/api/bitcastf32/) Function**

Reinterpret the bit pattern of a `u32` as an `f32`, the inverse of bitcastU32.

**[`bitcastU32`](https://typeshade.dev/api/bitcastu32/) Function**

Reinterpret the bit pattern of an `f32` as a `u32`.

**[`ceil`](https://typeshade.dev/api/ceil/) Function**

`ceil(x)`: round toward +∞, component-wise.

**[`clamp`](https://typeshade.dev/api/clamp/) Function**

`clamp(x, lo, hi)`: restricts x to \[lo, hi\], component-wise.

**[`cos`](https://typeshade.dev/api/cos/) Function**

`cos(x)`: cosine of x in radians, component-wise.

**[`cosh`](https://typeshade.dev/api/cosh/) Function**

`cosh(x)`: hyperbolic cosine, component-wise; the even partner of sinh.

**[`cross`](https://typeshade.dev/api/cross/) Function**

`cross(a, b)`: 3-D cross product of two `vec3<f32>` values.

**[`degrees`](https://typeshade.dev/api/degrees/) Function**

`degrees(rad)`: radians to degrees, component-wise, with the built-in's exact 180/π; the inverse of radians.

**[`distance`](https://typeshade.dev/api/distance/) Function**

`distance(a, b)`: |a − b|, vector to scalar; the built-in form of length(a.sub(b)).

**[`div`](https://typeshade.dev/api/div/) Function**

a / b as a free function, for a literal numerator: div(1, x) is the reciprocal, and emits (1.0 / x).

**[`dot`](https://typeshade.dev/api/dot/) Function**

`dot(a, b)`: dot product, vector to scalar.

**[`dpdx`](https://typeshade.dev/api/dpdx/) Function**

`dpdx(x)`: the screen-space partial derivative of x along the X axis, component-wise.

**[`dpdy`](https://typeshade.dev/api/dpdy/) Function**

`dpdy(x)`: the screen-space partial derivative of x along the Y axis, component-wise; the partner of dpdx, with the same GPU-only and fragment-only constraints.

**[`exp`](https://typeshade.dev/api/exp/) Function**

`exp(x)`: eˣ, component-wise. `exp2` is the base-2 form.

**[`exp2`](https://typeshade.dev/api/exp2/) Function**

`exp2`(x): 2ˣ, component-wise; the inverse of `log2`.

**[`f64FromParts`](https://typeshade.dev/api/f64fromparts/) Function**

Assemble an `f64` from its (hi, lo) `f32` halves, the shader-side counterpart of splitF64 for a value that arrives as two `f32` components.

**[`f64GuardOne`](https://typeshade.dev/api/f64guardone/) Function**

The anti-fast-math guard value of the `f64` emulation: a 1.0 the GPU compiler cannot see through, emitted per target as a texel fetch from the guard texture that fp64Guard declares.

**[`f64Parts`](https://typeshade.dev/api/f64parts/) Function**

The (hi, lo) pair of an `f64` as a plain `vec2<f32>`, for storing an `f64` into a `vec2` buffer field or stage output.

**[`floor`](https://typeshade.dev/api/floor/) Function**

`floor(x)`: round toward −∞, component-wise.

**[`fma`](https://typeshade.dev/api/fma/) Function**

`fma(a, b, c)`: multiply-add, a·b + c, component-wise for vectors.

**[`fract`](https://typeshade.dev/api/fract/) Function**

`fract(x)`: fractional part, x − `floor(x)`, component-wise.

**[`fwidth`](https://typeshade.dev/api/fwidth/) Function**

`fwidth(x)`: abs(`dpdx(x)`) + abs(`dpdy(x)`), the screen-space derivative magnitude, component-wise.

**[`insideRange`](https://typeshade.dev/api/insiderange/) Function**

In-range predicate: x >= lo && x <= hi.

**[`inverseSqrt`](https://typeshade.dev/api/inversesqrt/) Function**

`inverseSqrt`(x): 1/√x, component-wise.

**[`length`](https://typeshade.dev/api/length/) Function**

`length(v)`: Euclidean vector magnitude, |v|.

**[`log`](https://typeshade.dev/api/log/) Function**

`log(x)`: natural logarithm, component-wise.

**[`log2`](https://typeshade.dev/api/log2/) Function**

`log2`(x): base-2 logarithm, component-wise; the inverse of `exp2`.

**[`madd`](https://typeshade.dev/api/madd/) Function**

Multiply-add, a\*b + c, written as the plain a.mul(b).add(c) chain.

**[`mat2f64`](https://typeshade.dev/api/mat2f64/) Function**

An emulated-double `mat2x2<f64>` constructor, column-major: one `vec2<f64>` argument per column, the same convention as WGSL's `mat2x2`.

**[`mat3f64`](https://typeshade.dev/api/mat3f64/) Function**

An emulated-double `mat3x3<f64>` constructor, column-major, the 3×3 sibling of mat2f64; that entry has the column-argument convention and the transform helpers.

**[`mat4f64`](https://typeshade.dev/api/mat4f64/) Function**

An emulated-double `mat4x4<f64>` constructor, column-major, the 4×4 sibling of mat2f64; that entry has the column-argument convention and the transform helpers.

**[`max`](https://typeshade.dev/api/max/) Function**

`max(a, b)`: component-wise maximum, the partner of `min(/api/min/)`.

**[`min`](https://typeshade.dev/api/min/) Function**

`min(a, b)`: component-wise minimum.

**[`mix`](https://typeshade.dev/api/mix/) Function**

`mix(a, b, t)`: linear interpolation a + t·(b − a), component-wise, keyed by a.

**[`mod`](https://typeshade.dev/api/mod/) Function**

Floor modulo: x - y \* `floor(x / y)`, with identical semantics on both targets.

**[`mul`](https://typeshade.dev/api/mul/) Function**

a \* b as a free function, for a literal left operand: mul(2, x) emits (2.0 \* x).

**[`mulMat64`](https://typeshade.dev/api/mulmat64/) Function**

matNxN<`f64`> × matNxN<`f64`> → matNxN<`f64`>: the emulated-double matrix product.

**[`normalize`](https://typeshade.dev/api/normalize/) Function**

`normalize(v)`: v/|v|, keeping the vector key.

**[`optBarrier`](https://typeshade.dev/api/optbarrier/) Function**

An optimization barrier on one `f32` value, the shader equivalent of C's volatile.

**[`outsideRange`](https://typeshade.dev/api/outsiderange/) Function**

Out-of-range predicate: x < lo || x > hi.

**[`pack2x16float`](https://typeshade.dev/api/pack2x16float/) Function**

Pack a `vec2<f32>` into a `u32` as two IEEE-754 binary16 (half) values, component 0 in the 16 low bits.

**[`pack2x16snorm`](https://typeshade.dev/api/pack2x16snorm/) Function**

Pack a `vec2<f32>` into a `u32` as two 16-bit snorm values, ⌊0.5 + 32767·`clamp(x, -1, 1)`⌋ per component in two's complement, component 0 in the 16 low bits.

**[`pack2x16unorm`](https://typeshade.dev/api/pack2x16unorm/) Function**

Pack a `vec2<f32>` into a `u32` as two 16-bit unorm values, ⌊0.5 + 65535·`clamp(x, 0, 1)`⌋ per component, component 0 in the 16 low bits.

**[`pack4x8unorm`](https://typeshade.dev/api/pack4x8unorm/) Function**

Pack a `vec4<f32>` into a `u32` RGBA8.

**[`pow`](https://typeshade.dev/api/pow/) Function**

pow(a, b): a raised to the power b, component-wise.

**[`radians`](https://typeshade.dev/api/radians/) Function**

`radians(deg)`: degrees to radians, component-wise, with the built-in's exact π/180.

**[`round`](https://typeshade.dev/api/round/) Function**

`round(x)`: nearest integer, ties to even, component-wise, on both targets.

**[`saturate`](https://typeshade.dev/api/saturate/) Function**

`saturate(x)`: `clamp(x, 0, 1)`, component-wise, the standard normalized-range clamp for colour channels, interpolation factors and coverage.

**[`select`](https://typeshade.dev/api/select/) Function**

select: the free-function form of ReadonlyNode.select.

**[`sign`](https://typeshade.dev/api/sign/) Function**

`sign(x)`: -1, 0 or 1 per component, according to the sign of x.

**[`sin`](https://typeshade.dev/api/sin/) Function**

`sin(x)`: sine of x in radians, component-wise.

**[`sinh`](https://typeshade.dev/api/sinh/) Function**

`sinh(x)`: hyperbolic sine, component-wise.

**[`smoothstep`](https://typeshade.dev/api/smoothstep/) Function**

`smoothstep(e0, e1, x)`: Hermite interpolation from 0 at x = e0 to 1 at x = e1, component-wise.

**[`sqrt`](https://typeshade.dev/api/sqrt/) Function**

`sqrt(x)`: square root, component-wise.

**[`step`](https://typeshade.dev/api/step/) Function**

`step(edge, x)`: 0 where x < edge, else 1, component-wise.

**[`sub`](https://typeshade.dev/api/sub/) Function**

a - b as a free function.

**[`tan`](https://typeshade.dev/api/tan/) Function**

`tan(x)`: tangent of x in radians, component-wise.

**[`tanh`](https://typeshade.dev/api/tanh/) Function**

`tanh(x)`: hyperbolic tangent, component-wise; `sinh(x)`/`cosh(x)`, saturating to ±1 as x → ±∞.

**[`textureDimensions`](https://typeshade.dev/api/texturedimensions/) Function**

Texture extent in texels, as a `vec2<u32>`.

**[`textureLoad`](https://typeshade.dev/api/textureload/) Function**

Load one texel from a 2D texture at integer coordinates, returning `vec4<f32>`, `vec4<u32>` or `vec4<i32>` to match the texture's element.

**[`textureNumLayers`](https://typeshade.dev/api/texturenumlayers/) Function**

How many layers a 2D array texture has, as a `u32`.

**[`textureSample`](https://typeshade.dev/api/texturesample/) Function**

Sample a 2D texture, returning `vec4<f32>`.

**[`textureSampleLevel`](https://typeshade.dev/api/texturesamplelevel/) Function**

Sample a 2D texture at an explicit mip level, returning `vec4<f32>`.

**[`toF32`](https://typeshade.dev/api/tof32/) Function**

Convert to `f32`. On an `f64` argument this is the explicit, precision-losing narrow, computed as the sum of the hi and lo halves; `f64` never narrows implicitly.

**[`toF64`](https://typeshade.dev/api/tof64/) Function**

Widen `f32` to `f64`, exactly (the result is the pair (x, 0.0)).

**[`toI32`](https://typeshade.dev/api/toi32/) Function**

Convert to `i32`: the explicit numeric cast, where `i32`(/api/`i32`/) builds a literal from a JS number.

**[`toU32`](https://typeshade.dev/api/tou32/) Function**

Convert to `u32`: the explicit numeric cast, where `u32`(/api/`u32`/) builds a literal from a JS number.

**[`transformMat4`](https://typeshade.dev/api/transformmat4/) Function**

`mat4x4<f32>` × `vec4<f32>` → `vec4<f32>`: the matrix-vector product, as in a model-view-projection transform.

**[`transformMat64`](https://typeshade.dev/api/transformmat64/) Function**

matNxN<`f64`> × vecN<`f64`> → vecN<`f64`>: the emulated-double matrix-vector product.

**[`transpose64`](https://typeshade.dev/api/transpose64/) Function**

Transpose of an emulated-double matrix.

**[`trunc`](https://typeshade.dev/api/trunc/) Function**

`trunc(x)`: round toward zero, component-wise.

**[`unpack2x16float`](https://typeshade.dev/api/unpack2x16float/) Function**

Unpack a `u32` into a `vec2<f32>` of two binary16 (half) values, the exact inverse of `pack2x16float`.

**[`unpack2x16snorm`](https://typeshade.dev/api/unpack2x16snorm/) Function**

Unpack a `u32` of two 16-bit snorm values into a `vec2<f32>` in -1,1 (max per component), the inverse of `pack2x16snorm`.

**[`unpack2x16unorm`](https://typeshade.dev/api/unpack2x16unorm/) Function**

Unpack a `u32` of two 16-bit unorm values into a `vec2<f32>` in 0,1, the inverse of `pack2x16unorm`.

**[`unpack4x8unorm`](https://typeshade.dev/api/unpack4x8unorm/) Function**

Unpack a `u32` RGBA8 into a `vec4<f32>`.

**[`vec2`](https://typeshade.dev/api/vec2/) Function**

A `vec2<f32>` constructor, WGSL-style: `vec2`(x, y).

**[`vec2f64`](https://typeshade.dev/api/vec2f64/) Function**

An emulated-double `vec2<f64>` constructor.

**[`vec2i`](https://typeshade.dev/api/vec2i/) Function**

A `vec2<i32>` constructor, WGSL-style: `vec2i`(x, y).

**[`vec2u`](https://typeshade.dev/api/vec2u/) Function**

A `vec2<u32>` constructor, WGSL-style: `vec2u`(x, y).

**[`vec3`](https://typeshade.dev/api/vec3/) Function**

A `vec3<f32>` constructor, WGSL-style: `vec3`(x, y, z).

**[`vec3f64`](https://typeshade.dev/api/vec3f64/) Function**

An emulated-double `vec3<f64>` constructor, the three-component sibling of `vec2f64`; that entry has the splat, split and widen rules every vecNf64 constructor shares.

**[`vec3i`](https://typeshade.dev/api/vec3i/) Function**

A `vec3<i32>` constructor, WGSL-style: `vec3i`(x, y, z).

**[`vec3u`](https://typeshade.dev/api/vec3u/) Function**

A `vec3<u32>` constructor, WGSL-style: `vec3u`(x, y, z).

**[`vec4`](https://typeshade.dev/api/vec4/) Function**

A `vec4<f32>` constructor, WGSL-style: `vec4`.

**[`vec4f64`](https://typeshade.dev/api/vec4f64/) Function**

An emulated-double `vec4<f64>` constructor, the four-component sibling of `vec2f64`; that entry has the splat, split and widen rules every vecNf64 constructor shares.

**[`vec4i`](https://typeshade.dev/api/vec4i/) Function**

A `vec4<i32>` constructor, WGSL-style: `vec4i`.

**[`vec4u`](https://typeshade.dev/api/vec4u/) Function**

A `vec4<u32>` constructor, WGSL-style: `vec4u`.
