GpuMath¶
Import: import system.gpu;
This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation. Shader-only declarations can be used only inside shader entry points and helpers reached from them; using them elsewhere is a compile error.
This type spans several pages: part 1 · part 2.
GpuMath¶
Math functions for shaders. Each works on float, float16, GpuVec2, GpuVec3 and GpuVec4, component by component, and returns the same type as its arguments. All of them except step, sign, floor, ceil, round and fract are differentiable inside @differentiable helpers. They exist only on the GPU; on the CPU use Math and the vector methods.
sin¶
Sine of x radians.
cos¶
Cosine of x radians.
tan¶
Tangent of x radians.
asin¶
Arcsine in radians, for x from -1 to 1.
acos¶
Arccosine in radians, for x from -1 to 1.
atan¶
Arctangent in radians.
atan2¶
The angle in radians of the point (x, y), from -π to π.
exp¶
e raised to x.
exp2¶
2 raised to x.
log¶
Natural logarithm, for positive x.
log2¶
Base-2 logarithm, for positive x.
pow¶
x raised to y, for non-negative x.
sqrt¶
Square root, for non-negative x.
rsqrt¶
1 / sqrt(x), usually faster than dividing.
abs¶
Absolute value.
sign¶
-1, 0 or 1 by the sign of x.
floor¶
Rounds down to a whole number.
ceil¶
Rounds up to a whole number.
round¶
Rounds to the nearest whole number, halves to even.
fract¶
x - floor(x), from 0 up to but excluding 1.
min¶
The smaller of a and b.
max¶
The larger of a and b.
clamp¶
x limited to the range low through high.