This page lists all builtin functions in the root namespace.
Function parameters enclosed in square brackets mean they are optional, and the function can be called without specifying that parameter.
The #
character used when specifying types can either mean ‘any type’ when it is used alone, or ‘any dimension’ if it is after a scalar type.
For example, float# lerp(float# a, float# b, float #t)
means the following overloads of lerp
are available:
float lerp(float a, float b, float t); float2 lerp(float2 a, float2 b, float2 t); float3 lerp(float3 a, float3 b, float3 t); float4 lerp(float4 a, float4 b, float4 t);
Most functions on that page will appear with that notation, as they can be used with multiple types.
Interpolation
Return type | Description | |
float# | step(float# x, float# y) Step function. evaluates to [-∞, +∞] ⟶ [0, 1] | |
float# | linearstep(float# a, float# b, float# x) Linearstep function. linearly evaluates between [-∞, +∞] ⟶ [0, 1] | |
float# | smoothstep(float# a, float# b, float# x) Smoothstep function. smoothly evaluates between [-∞, +∞] ⟶ [0, 1] | |
float# | lerp(float# a, float# b, float# t) Lineary blends between Ex: | |
float# | smoothlerp(float# a, float# b, float# t) Smoothly blends between Ex: Equivalent to lerp(a, b, smoothstep(0, 1, t)); Or lerp(a, b, 3*t*t - 2*t*t*t); |
Random numbers
Return type | Description | |||||||||||||||||
float# | rand(a, b) Random function, returns a random value
| |||||||||||||||||
# # | randsel(a, b) randsel(a, b, float# k) Randomly returns The two-argument version of select(a, b, rand(0,1) < k); | |||||||||||||||||
float float# | randsign() randsign(float# k) Randomly returns select(-1.0, 1.0, rand(0,1) < k); | |||||||||||||||||
float3 float3 float3 | vrand() vrand(float inner, float outer) vrand(float inner, float outer, curveResource probabilityCurve) Random function, stands for “vector-rand”, returns a random
|
Noise
Return type | Description | |
float float | noise(float# t) fast.noise(float# t) Evaluates a coherent noise field. All functions return a single
| |
float# float# | dnoise(float# t) fast.dnoise(float# t) Evaluates the derivative of the coherent noise field returned by The returned value is a vector of the same dimension as |
Math constants
Type | Description |
float | pi Constant pi |
float | phi Constant phi |
float | infinity infinity: +∞ |
Math functions
Return type | Description | |||
float | dot(float# u, float# v) vector dot-product | |||
float3 | cross(float3 u, float3 v) 3D vector cross-product | |||
float3 | reflect(float3 v,float3 n) Reflects (mirrors) the vector | |||
# | abs(x) Returns the absolute value of | |||
# | sign(x) Sign function. If x is a floating-point scalar or vector, returns -1.0 when x <= -0.0 , and +1.0 when x >= +0.0 If x is an integer scalar or vector, returns -1 when x < 0 , and +1 when x >= 0 ![]() [-∞, +∞] ⟶ [-1], [+1] | |||
float# | ceil(float# x) Ceiling rounding: rounds to the closest integer value >= x ![]() [-∞, +∞] ⟶ [-∞, +∞] | |||
float# | floor(float# x) Floor rounding: rounds to the closest integer value <= x ![]() [-∞, +∞] ⟶ [-∞, +∞] | |||
float# | frac(float# x) Extracts the fractional part of x ![]() [-∞, +∞[ ⟶ [0, 1[ | |||
float# | fracSign(float# x) Extracts the fractional part of x , preserving the sign.![]() [0, +∞[ ⟶ [0, 1[ ]-∞, 0[ ⟶ ]-1, 0] | |||
float# | wavesq(float# x) Square wave function ![]() ]-∞, +∞[ ⟶ [-1, 1] | |||
float# | wavetri(float# x) Triangular wave function ![]() ]-∞, +∞[ ⟶ [0, 1] | |||
float# | wavesaw(float# x) Sawtooth wave function ![]() ]-∞, +∞[ ⟶ [0, 1] | |||
float# | discretize(float# x, float# y) Discretization function, snaps | |||
# | min(x,y) Minimization function: if | |||
# | max(x,y) Maximization function: if | |||
float# | clamp(x,a,b) Clamp function: if | |||
float# | saturate(float# x) Clamps | |||
float# float# float# | sqrt(float# x) fast.sqrt(float# x) accurate.sqrt(float# x) Square-root function The fast version is faster, but gives a lower precision result.![]() [0, +∞] ⟶ [0, +∞] | |||
float# float# float# | rsqrt(float# x) fast.rsqrt(float #x) accurate.rsqrt(float #x) Reverse square-root The fast version is faster, but gives a lower precision result.![]() [0, +∞] ⟶ [0, +∞] | |||
float# float# float# | cbrt(float# x) fast.cbrt(x) accurate.cbrt(x) Cube root The fast version is faster, but gives a lower precision result.![]() [0, +∞] ⟶ [0, +∞] | |||
float float float | length(float# v) fast.length(float# v) accurate.length(float# v) Returns the length of vector v . Works with vectors from 1 to 4 dimensions.The fast version is faster, but gives a lower precision result.[-∞, +∞] ⟶ [0, +∞] | |||
float# float# float# | normalize(float# v) fast.normalize(float# v) accurate.normalize(float# v) Normalizes vector v (returns the unit vector pointing in the same direction). Works with vectors from 1 to 4 dimensions.The fast version is faster, but gives a lower precision result.[-∞, +∞] ⟶ [-1, 1] | |||
float# float# float# | exp(float# x) fast.exp(float# x) accurate.exp(float# x) Natural exponential. Uses the fast namespace by default. The fast version is faster, but gives a lower precision result.[-∞, +∞] ⟶ [0, +∞] | |||
float# float# float# | exp2(float# x) fast.exp2(float# x) accurate.exp2(float# x) Base-2 exponential. Uses the fast namespace by default. The fast version is faster, but gives a lower precision result.[-∞, +∞] ⟶ [0, +∞] | |||
float# float# float# | pow(float# x, float# y) fast.pow(float# x,float# y) accurate.pow(float# x,float# y) Power function. The fast version is faster, but gives a lower precision result.{[0, +∞], [-∞, +∞]} ⟶ [-∞, +∞] | |||
float# float# float# | log(float# x) fast.log(float# x) accurate.log(float# x) Natural logarithm. The fast version is faster, but gives a lower precision result.[-∞, +∞] ⟶ [-∞, +∞] | |||
float# float# float# | log2(float# x) fast.log2(float# x) accurate.log2(float# x) Base-2 logarithm. The fast version is faster, but gives a lower precision result.[-∞, +∞] ⟶ [-∞, +∞] | |||
float# float# float# | rcp(float# x) fast.rcp(float# x) accurate.rcp(float# x) Reciprocal function. The fast version is faster, but gives a lower precision result.[-∞, +∞] ⟶ [-∞, +∞] | |||
# | within(x, lower, upper) Returns
Ex: | |||
float# float# | remap(value, newMin, newMax) remap(value, oldMin, oldMax, newMin, newMax) Remaps | |||
bool | all(bool# c) Returns
Ex: | |||
bool | any(bool# c) Returns
Ex: | |||
# | bias(float# x, float# e) De-linearizes the input
| |||
float# float# | safe_normalize(v[, vz, epsilon]) fast.safe_normalize(v[, vz, epsilon]) Normalizes the input vector
Ex: | |||
float3 float3 float3 float3 | float3suf(side, up, forward) float3suf(...) float3sfu(side, forward, up) float3sfu(...) Takes the float3suf(0, 18, 0);
float3 vec = float3(1, 2, 3); res = float3suf(vec);
| |||
bool# | isfinite(float# v) Useful to detect infinite or invalid values.
isfinite(42); --> true isfinite(1.0/0.0); --> false isfinite(0.0/0.0); --> false
This function can be used to check the return values of some functions that return infinite values as a way to report en empty result. float4 isec = scene.intersect(pos, dir, len); float3 reflPos = pos + dir * isec.w + reflect(dir, isec.xyz) * (len - isec.w); // Bounced pos, will be invalid if no collision, as isec.w will be +inf float3 endPos = pos + dir * len; // Unblocked end pos pos = select(endPos, reflPos, isfinite(isec.w)); // If invalid, fallback to unblocked end pos | |||
bool# | isinf(float# v) Useful to detect infinite or invalid values. isinf(42); --> false isinf(1.0/0.0); --> true isinf(0.0/0.0); --> false
This function can be used to check the return values of some functions that return infinite values as a way to report en empty result. float4 isec = scene.intersect(pos, dir, len); float3 reflPos = pos + dir * isec.w + reflect(dir, isec.xyz) * (len - isec.w); // Bounced pos, will be invalid if no collision, as isec.w will be +inf float3 endPos = pos + dir * len; // Unblocked end pos pos = select(reflPos, endPos, isinf(isec.w)); // If invalid, fallback to unblocked end pos | |||
bool# | isnan(float# v) Useful to detect infinite or invalid values. isnan(42); --> false isnan(1.0/0.0); --> false isnan(0.0/0.0); --> true
| |||
float# | asfloat(v) Reinterprets the input as a float. If given a float, does nothing. If given an int, will reinterpret its bits as if it was a float.
asfloat(0x3F800000); --> 1.0 asfloat(42.0); --> 42.0 asfloat(int4(0x40490FDB, 0, 0xC0200000, -1071644672)) --> float4(3.141593, 0, -2.5, -2.5) | |||
int# | asint(v) Reinterprets the input as an int. If given an int, does nothing. If given a float, will reinterpret its bits as if it was an int.
asint(1.0); --> 0x3F800000 asint(42); --> 42 asint(float4(3.141593, 0, -2.5, -2.5)) --> int4(0x40490FDB, 0, 0xC0200000, 0xC0200000) | |||
orientation | asorientation(float4 v) Reinterprets the input as an orientation. If given an orientation, does nothing. If given a float4, will reinterpret its bits as if it was an orientation. |
Trigonometric functions
All trigonometric functions below are also available in the fast
and accurate
namespaces. fast
versions are faster, but give a lower precision result. accurate
versions are slower but give a higher-precision results. Functions in the root namespace without an explicit precision namespace will use the accurate namespace unless otherwise stated.
All trigonometric functions below are also available in the degrees
and radians sub-namespaces
, and will use the corresponding angle units. If an angle namespace isn’t explicitly specified, the functions will use degrees
by default.
Return type | Description |
float# | sin(float# x) Sine function. Uses the fast namespace by default. |
float# | cos(float# x) Cosine function Uses the fast namespace by default. |
float# | tan(float# x) Tangent function. |
float# | asin(float# x) Arc-sine : returns the inverse of the |
float# | acos(float# x) Arc-cosine : returns the inverse of the |
float# | atan(float# x) Arc-tangent : returns the inverse of the |
float# | atan2(float# x,float# y) Signed arc-tangent: like |
Rotation, orientation, & angles
Return type | Description | |
float3 float3 float3 | rotate(float3 v, float3 axis, float angle) degrees.rotate(float3 v, float3 axis, float angle) radians.rotate(float3 v, float3 axis, float angle) Returns the vector | |
float# | deg2rad(float# angle)
| |
float# | rad2deg(float# angle)
| |
orientation | orientation_mult(orientation a, orientation b) Combines orientations float3 x = rotate(v, orientation_mult(a, b));
// Is equivalent to:
float3 x = rotate(rotate(v, b), a); It is useful to combine orientations coming from different sources, for example: orientation a = scene.orientation_f(Velocity); // rotation to orient "forward" to point towards "Velocity" orientation b = scene.orientation_ea(float3suf(0, self.lifeRatio * 360*4, 0)); // spin along the Y axis over the lifetime of the particle orientation x = orientation_mult(a, b); // combine both to get the final orientation To create orientations, see the scene namespace. | |
orientation | orientation_invert(orientation a) Inverts orientations |
Colors
Return type | Description | |||||||
float# float# float# float# | linear2srgb(c) srgb2linear(c) fast.linear2srgb(c) fast.srgb2linear(c)
The ‘fast’ versions use an approximation (the absolute precision is under 0.001), whereas the non-fast versions use the real sRGB piecewise-curve conversion.Works for both | |||||||
float# float# | rgb2hsv(c) hsv2rgb(c) .rgb2hsv(c) converts the input color c from RGB space to HSV space.hsv2rgb(v) converts the input color c from HSV space to RGB space.The converters support HDR values.For the HSV color-space, the H-value (hue) is wrapped from 0 to 1 (1 means 360°), the S-value (saturation) is clipped from 0 to 1 and the V-value (intensity) is positive.Works for both float3 RGB and float4 RGBA values. | |||||||
float3 float3 | blackbody(t) fast.blackbody(t) Returns the normalized RGB chromaticity color of the emission spectrum of a blackbody at the specified temperatureThe input value should be a temperature in degrees kelvin. For example, 800 will give a red color, 3000 will give an orange/yellow color, 5000/6000 will give a white color, and higher temperatures will give a blue color. RGB colors returned are in linear space‘, not in sRGB space. The ‘fast’ version uses a different algorithm (a polynomial fit on the final RGB curves) than the regular version (which uses a polynomial fit of the chromaticity-space planckian locus), is roughly twice faster, but much less precise (although it’s probably fine for most applications).
Here’s the RGB comparison between the regular and fast versions:
The two are virtually identical. Only when plotting the actual RGB curves you start seeing a difference:
|
Conditional selection
Return type | Description | |
# | select(a, b, bool# c) Returns
Ex: | |
# | iif(bool# c, b, a)
|
Z-order curves
Return type | Description | |
int | morton_encode2(int2 a) Returns the 32-bit integer morton-encoded (z-order) representation of the 2D integer vector | |
int | morton_encode3(int3 a) Returns the 32-bit integer morton-encoded (z-order) representation of the 3D integer vector | |
int2 | morton_decode2(int a) Returns the 2D integer vector resulting from decoding the morton-encoded (z-order) 32-bit integer value | |
int3 | morton_decode3(int a) Returns the 3D integer vector resulting from decoding the morton-encoded (z-order) 32-bit integer value |
Derivation & integration
Return type | Description | |
float# | dxdt(float# a) Returns the analytical time-based partial derivative of Treats Example: Plugging the particle position into a script node, and doing If the compiler isn’t able to analytically derive | |
float# | dxdT(float# a) Returns the finite-difference time-based partial derivative of Treats Creates an additional per-particle storage to store the previous frame’s value of | |
float# | dxdF(float# a) Returns the frame-based partial derivative of Returns the value of Example: Plugging the particle position into a script node, and doing Creates an additional per-particle storage to store the previous frame’s value of | |
float# | ixdt(float# a) Returns the analytical time-based integral of If the compiler isn’t able to analytically integrate | |
float# | ixdT(float# a) Returns the time-based integral of Creates an additional per-particle storage to store the accumulator. |