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 v on the plane defined by the normal n.
]-∞, +∞[ ⟶ ]-∞, +∞[
|
#
|
abs(x)
Returns the absolute value of x

[-∞, +∞] ⟶ [0, +∞]
|
#
|
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 x to the nearest step, given a step size y
 [-∞, +∞] ⟶ [-∞, +∞]
|
#
|
min(x,y)
Minimization function: if x < y, returns x, otherwise, returns y
 [-∞, +∞] ⟶ [-∞, y]
|
#
|
max(x,y)
Maximization function: if x > y, returns x, otherwise, returns y
 [-∞, +∞] ⟶ [y, +∞]
|
float#
|
clamp(x,a,b)
Clamp function: if x < a, returns a, otherwise, if x > b, returns b, otherwise, returns x
 [-∞, +∞] ⟶ [a, b]
|
float#
|
saturate(float x)#
Clamps x in the [0, 1] range
 [-∞, +∞] ⟶ [0, 1]
|
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 1.0 if x is within the [lower, upper] range, returns 0.0 otherwise.
All the function’s arguments can be either scalars, or vectors. if some arguments are vectors, they must have the same dimension. The return value will be a vector as large as the largest input vector.
IE: you cannot call within(float2, float3, float4), but you can call within(float, float, float4) or within(float3, float, float3)
Ex:
within(0.5, -1.2, 3.0); will return 1.0.
within(float3(-2,0,2.5), -1.2, 3.0); will return float3(0.0, 1.0, 1.0).
within(1.5, -1.0, float4(0,1,2,3)); will return float4(0.0, 0.0, 1.0, 1.0).
|
float#
float#
|
remap(value, newMin, newMax)
remap(value, oldMin, oldMax, newMin, newMax)Remaps value from the [oldMin, oldMax] range to the [newMin, newMax] range.
all the function’s arguments can be either scalars, or vectors. If some arguments are vectors, they must have the same dimension. The return value will be a vector as large as the largest input vector.
IE: you cannot call remap(float2, float3, float4), but you can call remap(float, float, float4) or remap(float3, float, float3)
the version that has no 'oldMin' and 'oldMax' assumes the original range is [0,1]`Ex:
`remap(0.5, 1.0, 3.0); will return 2.0.
remap(0.5, 0, 0.5, 1.0, 3.0); will return 3.0.
|
bool
|
all(bool c)#
Returns true if ALL elements of vector c are true
c can be a boolean scalar or vector of any dimension.
Ex:
all(float3(0) < float3(1,2,3)); will return true.
all(float3(0) < float3(1,-2,3)); will return false.
|
bool
|
any(bool c)#
Returns true if ANY element of vector c is true
c can be a boolean scalar or vector of any dimension.
Ex:
any(float3(0) > float3(1,2,3)); will return false.
any(float3(0) > float3(1,-2,3)); will return true.
|
#
|
bias(float x, float# e)#
De-linearizes the input x by applying a power function based on value e.
x is expected to be in the [0,1] range, e has to be in the [-1,1] range.

|
e = 0 : black (x)
e = +-0.3 : green
e = +-0.6 : yellow
e = +-0.85 : orange
e = +-0.99 : red
|
|
float#
float#
|
safe_normalize(v[, vz, epsilon])
fast.safe_normalize(v[, vz, epsilon])Normalizes the input vector v and returns the resulting unit-vector. Unlike the normalize and safe_normalize builtins, these safe versions check for null vectors.
This will prevent normalizing a null vector and getting an Infinity or NaN vector in return.
Works on any vector dimensions.Ex:
safe_normalize(vector3); returns normalize(vector3), but if length(vector3) < 1.0e-8, returns float3(0,0,0).
safe_normalize(vector3, float3(0,1,0)); returns normalize(vector3), but if length(vector3) < 1.0e-8, returns float3(0,1,0).
safe_normalize(vector3, float3(0,1,0), 1.0e-6); returns normalize(vector3), but if length(vector3) < 1.0e-6, returns float3(0,1,0).safe_normalize(vector3)
is equivalent to:
select(normalize(vector3), float3(0), length(vector3) < 1.0e-8);
|
float3
float3
float3
float3
|
float3suf(side, up, forward)
float3suf(…)
float3sfu(side, forward, up)
float3sfu(…)Takes the side, up, and forward components and permutes/swizzles them based on the current axis-System.
Accepts the same kind of arguments as the regular float3 construction: you can pass a float2 and a float, a float3, or three floats.Ex:
-
Y-Up axis-system: float3(0, 18, 0);
-
Z-Up axis-system: float3(0, 0, 18);
float3 vec = float3(1, 2, 3);
res = float3suf(vec);
-
Y-Up axis-system: res = vec; (no changes)
-
Z-Up axis-system: res = vec.xzy; (so: float3(1, 3, 2))
|
bool#
|
isfinite(float v)#
Useful to detect infinite or invalid values.
isfinite(v) returns true if v is a finite value, false if not.
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.
For example, scene raycasts:
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(v) returns true if v is an infinite value, false if not (either finite or NaN).
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.
For example, scene raycasts:
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(v) returns true if v is a NaN value (NaN = "Not a Number"), false if not.
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.
works on any vector, float to float4, int to int4, or orientation.
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.
works on any vector, float to float4, int to int4.
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.
|