Language
Functions
Numeric built-in functions
Trigonometric
For all functions in this section, if the argument is a vector, the result is calculated per component.
fn degrees(e: T) -> TConverts radians to degrees, approximating e × 180 ÷ π.
fn radians(e: T) -> TConverts degrees to radians, approximating e × π ÷ 180.
fn cos(e: T) -> TReturns the cosine of e, where e is in radians. Component-wise when T is a vector.
fn cosh(e: T) -> TReturns the hyperbolic cosine of e, where e is a hyperbolic angle in radians.
fn acos(e: T) -> TReturns the principal value, in radians, of the inverse cosine of e.
fn acosh(e: T) -> TReturns the inverse hyperbolic cosine of e, as a hyperbolic angle in radians.
fn sin(e: T) -> TReturns the sine of e, where e is in radians. Component-wise when T is a vector.
fn sinh(e: T) -> TReturns the hyperbolic sine of e, where e is a hyperbolic angle in radians.
fn asin(e: T) -> TReturns the principal value, in radians, of the inverse sine of e.
fn asinh(e: T) -> TReturns the inverse hyperbolic sine of e, as a hyperbolic angle in radians.
fn tan(e: T) -> TReturns the tangent of e, where e is in radians.
fn tanh(e: T) -> TReturns the hyperbolic tangent of e, where e is a hyperbolic angle in radians.
fn atan(e: T) -> TReturns the principal value, in radians, of the inverse tangent of e.
fn atanh(e: T) -> TReturns the inverse hyperbolic tangent of e, as a hyperbolic angle in radians.
fn atan2(y: T, x: T) -> TReturns an angle, in radians, in the interval [-π, π] whose tangent is y÷x.
fn exp(e: T) -> TReturns the natural exponentiation of e. Component-wise when T is a vector.
fn exp2(e: T) -> TReturns 2 raised to the power e.
fn log(e: T) -> TReturns the natural logarithm of e.
fn log2(e: T) -> TReturns the base-2 logarithm of e.
fn pow(e1: T, e2: T) -> TReturns e1 raised to the power e2.
fn sqrt(e: T) -> TReturns the square root of e.
fn inverseSqrt(e: T) -> TReturns the reciprocal of sqrt(e).
Linear Algebra
fn cross(e1: vec3<T>, e2: vec3<T>) -> vec3<T>Returns the cross product of e1 and e2.
fn determinant(e: matCxC<T>) -> TReturns the determinant of e.
fn distance(e1: T, e2: T) -> SReturns the distance between e1 and e2, e.g. length(e1 - e2).
fn dot(e1: vecN<T>, e2: vecN<T>) -> TReturns the dot product of e1 and e2.
fn faceForward(e1: vecN<T>, e2: vecN<T>, e3: vecN<T>) -> vecN<T>Returns e1 if dot(e2, e3) is negative, and -e1 otherwise.
fn fma(e1: T, e2: T, e3: T) -> TFused multiply add, returns e1 * e2 + e3. Component-wise when T is a vector.
fn length(e: T) -> SReturns the 2-norm of e. Evaluates to the absolute value of e if T is scalar.
fn normalize(e: vecN<T> ) -> vecN<T>Returns a unit vector in the same direction as e.
fn reflect(e1: T, e2: T) -> TFor the incident vector e1 and surface orientation e2, returns the reflection direction e1 - 2 * dot(e2, e1) * e2.
fn refract(e1: T, e2: T, e3: I) -> TFor the incident vector e1 and surface normal e2, and the ratio of indices of refraction e3, let k = 1.0 - e3 * e3 * (1.0 - dot(e2, e1) * dot(e2, e1)). If k < 0.0, returns the refraction vector 0.0, otherwise return the refraction vector e3 * e1 - (e3 * dot(e2, e1) + sqrt(k)) * e2.
fn transpose(e: matRxC<T>) -> matCxR<T>Returns the transpose of e.
Round, Limit, Mix, Compare
For all functions in this section, if the argument is a vector, the result is calculated per component.
fn abs(e: T ) -> TThe absolute value of e. Component-wise when T is a vector.
fn sign(e: T) -> TReturns 1.0 when e > 0, 0.0 when e = 0, and -1.0 when e < 0.
fn fract(e: T) -> TReturns the fractional part of e, computed as e - floor(e).
fn trunc(e: T) -> TReturns the nearest whole number whose absolute value is less than or equal to e.
fn modf(e: T) -> __modf_resultSplits e into fractional and whole number parts. The fractional part is e % 1.0, and the whole part is e minus the whole part. Returns the __modf_result or __modf_result_f16 built-in structure.
fn ceil(e: T) -> TReturns the ceiling of e. Component-wise when T is a vector.
fn floor(e: T) -> TReturns the floor of e. Component-wise when T is a vector.
fn round(e: T) -> TReturns the integer k nearest to e, as a floating point value. When e lies
halfway between integers k and k + 1, the result is k when k is even, and
k+1 when k is odd.
fn clamp(e: T, low: T, high: T) -> TRestricts the value of e within a range. The result is min(max(e, low), high).
fn saturate(e: T) -> TReturns clamp(e, 0.0, 1.0).
fn step(edge: T, x: T) -> TReturns 1.0 if edge ≤ x, and 0.0 otherwise.
fn smoothstep(low: T, high: T, x: T) -> TReturns the smooth Hermite interpolation between 0 and 1. For scalar t,
the result is t * t * (3.0 - 2.0 * t), where t = clamp((x - low) / (high - low), 0.0, 1.0).
fn max(e1: T, e2: T) -> TReturns e2 if e1 is less than e2, and e1 otherwise.
fn min(e1: T, e2: T) -> TReturns e2 if e2 is less than e1, and e1 otherwise.
fn mix(e1: T, e2: T, e3: T) -> TReturns the (component-wise) linear blend of e1 and e2, e.g. e1 * (1 - e3) + e2 * e3).
fn frexp(e: T) -> __frexp_resultSplits e into a fraction and an exponent so that e = fraction * 2^exponent. The fraction is 0.0 or its magnitude is in the range [0.5, 1.0). Returns the __frexp_result or __frexp_result_f16 built-in structure.
fn ldexp(fraction: T, exponent: I) -> TReturns fraction * 2^exponent.
fn quantizeToF16(e: T) -> TQuantizes a 32-bit floating point value e as if e were converted to a IEEE 754 binary16 value, and then converted back to a IEEE 754 binary32 value.
Bit
fn countLeadingZeros(e: T) -> TThe number of consecutive 0 bits starting from the most significant bit of e.
fn countOneBits(e: T) -> TThe number of 1 bits in the representation of e, also known as “population count”.
fn countTrailingZeros(e: T) -> TThe number of consecutive 0 bits starting from the least significant bit of e.
fn extractBits(e: T, offset: u32, count: u32) -> TIf T is signed, reads bits with sign extension. Bits 0...c-1 of the result are copied from bits o...o+c-1 of e. Other bits of the result are the same as bit c-1 of the result.
If T is unsigned, reads bits without sign extension. Bits 0...c-1 of the result are copied from bits o...o+c-1 of e. Other bits of the result are 0.
fn firstLeadingBit(e: T) -> Tif T is signed: returns -1 if e is 0 or -1, otherwise the position of the most significant bit in e that is different from e’s sign bit.
If T is unsigned: returns T(-1) if e is zero, otherwise the position of the most significant 1 bit in e.
fn firstTrailingBit(e: T) -> TReturns T(-1) if e is zero, otherwise the position of the least significant 1 bit in e.
fn insertBits(e: T, newbits: T, offset: u32, count: u32) -> TSets bits in an integer. The result is e if c is 0. Otherwise, bits o...o+c-1 of the result are copied from bits 0...c-1 of newbits. Other bits of the result are copied from e.
fn reverseBits(e: T) -> TReverses the bits in e: The bit at position k of the result equals the bit at position 31 -k of e.