1. Functions related to angle
The following is the function related to the angle
function |
parameter |
describe |
sin(x) |
radian |
sine function |
cos(x) |
radian |
cosine function |
tan(x) |
radian |
Tangent function |
asin(x) |
radian |
arcsine function |
acos(x) |
radian |
arccosine function |
time(x) |
radian |
arctangent function |
radians(x) |
angle |
Angles to radians |
degrees(x) |
radian |
Convert radians to degrees |
2. Mathematical functions
This type is mainly for the operation of exponential logarithmic power function
function |
describe |
pow(x,y) |
x to the yth power. If x is less than 0, the result is undefined. Likewise, if x=0 and y<=0, the result is undefined. |
exp(x) |
e to the xth power |
log(x) |
Computes the value of y such that x is equal to e raised to the yth power. If the value of x is less than 0, the result is undefined. |
exp2(x) |
Calculate 2 to the power of x |
log2(x) |
Calculates the value of y such that x is equal to 2 to the power of y. If the value of x is less than 0, the result is undefined. |
sqrt(x) |
Computes the square root of x. If x is less than 0, the result is undefined. |
inversesqrt(x) |
Computes the value of one of the roots of x. If x is less than or equal to 0, the result is undefined. |
3. Common functions
Here are commonly used functions, similar to built-in functions in js
function |
describe |
abs(x) |
returns the absolute value of x |
sign(x) |
If x>0, return 1.0; if x=0, return 0, if x<0, return -1.0 |
floor(x) |
Returns the largest integer value less than or equal to x |
ceil(x) |
Returns the smallest integer value greater than or equal to x |
fract(x) |
Returns x-floor(x), which returns the fractional part of x |
mod(x, y) |
Returns the modulus of x and y |
min(x, y) |
Returns the lesser value of x and y. |
max(x, y) |
Returns the greater of x and y. |
clamp(x, minVal, maxVal) |
Clamp the x value between minVal and maxVal, which means return minVal when x<minVal, return maxVal when x>maxVal, and return x when x is between minVal and maxVal |
mix(x, y, a) |
Returns a linear mixture of x and y, such as: x*(1−a)+y*a |
step(edge, x) |
If x < edge, return 0.0, otherwise return 1.0 |
smoothstep(edge0, edge1, x) |
If x <= edge0, return 0.0; if x >= edge1 return 1.0; if edge0 < x < edge1, perform a smooth Hermitian difference between 0 and 1. If edge0 >= edge1, the result is undefined. |
4. Geometric functions
Here are functions related to lengths, distances, vectors, etc.
length(x) |
Returns the length of the vector x |
distance(p0,p1) |
Calculate the distance between vectors p0, p1 |
dot |
Dot product between vectors x, y |
cross(x, y) |
Cross product between vectors x, y |
normalize(x) |
Normalizes a vector, returning a vector with the same direction as x but length 1 |
faceforward(N, I, Nref) |
If the dot product of Nref and I is less than 0, return N; otherwise, return -N; |
reflect(I, N) |
return reflection vector |
refract(I, N, eta) |
Returns the refraction vector |