|
fennec
|
The Common Functions defined in the OpenGL 4.6 Shading Language Specification.
| Syntax | Description | ||
|---|---|---|---|
genIType abs(genIType x) genFType abs(genFType x) genDType abs(genDType x) |
We can express this as,
| ||
genIType sign(genIType x) genFType sign(genFType x) genDType sign(genDType x) |
We can express this as,
|
| Syntax | Description | ||
|---|---|---|---|
genFType floor(genFType x) genDType floor(genDType x) |
We can express this as,
| ||
genFType ceil(genFType x) genDType ceil(genDType x) |
We can express this as,
| ||
genFType round(genFType x) genDType round(genDType x) |
In C++, a fractional part of \(0.5\) will always round up.
| ||
genFType roundEven(genFType x) genDType roundEven(genDType x) |
In C++, a fractional part of \(0.5\) will always round to the nearest even integer.
| ||
genFType trunc(genFType x) genDType trunc(genDType x) |
We can express this as,
|
| Syntax | Description | ||||
|---|---|---|---|---|---|
genFType fract(genFType x) genDType fract(genDType x) |
We can express this as,
| ||||
genFType mod(genFType x, float y) genFType mod(genFType x, genFType y) genDType mod(genDType x, double y) genDType mod(genDType x, genDType y) |
We can express this as,
| ||||
genFType modf(genFType x, out genFType i) genDType modf(genDType x, out genDType i) |
We can express this as,
| ||||
genBType isnan(genFType x) genBType isnan(genDType x) |
\(NaN\) is a concept unique to computing. It strictly means, and more specifically, floating point values can only represent real numbers. This is why some functions, like sqrt(), return \(NaN\) when an expression would return a value in a different coordinate space. There are other cases, such as \(\frac{1}{x}\), where \(x=0\) is undefined, and respectively the return value is also \(NaN\). To learn more, see IEEE 754
| ||||
genBType isinf(genFType x) genBType isinf(genDType x) |
\(\inf\), or \(\infty\), is used to express any function that is boundless, endless, or larger than any natural number. This function has applications in Set Theory and Mathematical Analysis.
| ||||
genFType frexp(genFType x, out genIType exp) genDType frexp(genDType x, out genIType exp) |
The significand is returned by the function and the exponent is returned in the parameter \(exp\). For a floating-point value of zero, the significand and exponent are both zero. If an implementation supports signed zero, an input value of minus zero should return a significand of minus zero. For a floating-point value that is an infinity or is not a number, the results are undefined. If the input \(x\) is a vector, this operation is performed in a component-wise manner; the value returned by the function and the value written to \(exp\) are vectors with the same number of components as \(x\).
| ||||
genFType ldexp(genFType x, genIType exp) genDType ldexp(genDType x, genIType exp) |
Builds a floating-point number from x and the corresponding integral exponent of two in exp, returning: \({x}\cdot{2^{exp}}\). If this product is too large to be represented in the floating-point type, the result is undefined. If exp is greater than +128 (single-precision) or +1024 (double-precision), the value returned is undefined. If exp is less than -126 (single-precision) or -1022 (double-precision), the value returned may be flushed to zero. Additionally, splitting the value into a significand and exponent using frexp() and then reconstructing a floating-point value using ldexp() should yield the original input for zero and all finite non-subnormal values. If the input x is a vector, this operation is performed in a component-wise manner; the value passed in exp and returned by the function are vectors with the same number of components as x.
|
| Syntax | Description | ||
|---|---|---|---|
genIType floatBitsToInt(genType value) genUType floatBitsToUint(genType value) |
we can express this in set theory, i.e.
| ||
genFType intBitsToFloat(genIType value) genFType uintBitsToFloat(genUType value) |
we can express this in set theory, i.e.
|
| Syntax | Description | ||||||
|---|---|---|---|---|---|---|---|
step(float edge, genFType x) step(genFType edge, genFType x) step(double edge, genDType x) step(genFType edge, genDType x) |
We can express this as,
| ||||||
smoothstep(float edge0, float edge1, genFType x) smoothstep(genFType edge0, genFType edge1, genFType x) smoothstep(double edge0, double edge1, genDType x) smoothstep(genFType edge0, genFType edge1, genDType x) |
This is useful in cases where you would want a threshold function with a smooth transition. genFType t;
t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
| ||||||
mix(genFType x, genFType y, float a) mix(genFType x, genFType y, genFType a) mix(genDType x, genDType y, double a) mix(genDType x, genDType y, genDType a) |
We can express this as,
| ||||||
mix(genBType x, genBType y, genBType a) mix(genIType x, genIType y, genBType a) mix(genUType x, genUType y, genBType a) mix(genFType x, genFType y, genBType a) mix(genDType x, genDType y, genBType a) |
We can express this as,
|