Math functions

Beyond the functions defined on the numeric types, there are other methods which works on most types. These are wrapping functions defined in the GLSL standard library. This page does not describe what each method does. Please see GLSL documentation to learn what they do if it is not clear by their signature.

Import functions like this:

import { dot, radians, saturate } from "@hology/core/shader-nodes"

Trigonometry functions

radians<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
degrees<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
sin<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
cos<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
tan<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
asin<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
acos<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
atan<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(yOverX: T): T

Exponential functions

exp<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
log<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
exp2<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
log2<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
sqrt<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
inversesqrt<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
pow<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T, y: T): T

Geometric functions

length<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): FloatNode
normalize<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T

Common functions

abs<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
sign<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
floor<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
fract<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
ceil<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T

mix<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(x: T, y: T, a: U): T

step<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(edge: U, x: T): T

smoothstep<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(edge0: U, edge1: U, x: T): T

clamp<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(x: T, minVal: U, maxVal: U): T

saturate<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(a: T): T

Vector functions

dot<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T, y: T): FloatNode

Matrix functions

inverse<T extends Mat2Node | Mat3Node | Mat4Node>(x: T): T
transpose<T extends Mat2Node | Mat3Node | Mat4Node>(x: T): T

Last updated