Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
内置函数
Godot 支持很多内置函数,大致遵循 GLSL ES 3.0 规范。
备注
以下类型别名仅在文档中使用,目的是为了减少重复的函数声明。它们各自可以指代多种实际的类型。
别名 |
实际类型 |
glsl 文档中的别名 |
|---|---|---|
vec_type |
float、vec2、vec3 或 vec4 |
genType |
vec_int_type |
int、ivec2、ivec3 或 ivec4 |
genIType |
vec_uint_type |
uint、uvec2、uvec3 或 uvec4 |
genUType |
vec_bool_type |
bool、bvec2、bvec3 或 bvec4 |
genBType |
mat_type |
mat2、mat3 或 mat4 |
mat |
gvec4_type |
vec4、ivec4 或 uvec4 |
gvec4 |
gsampler2D |
sampler2D、isampler2D 或 uSampler2D |
gsampler2D |
gsampler2DArray |
sampler2DArray、isampler2DArray 或 uSampler2DArray |
gsampler2DArray |
gsampler3D |
sampler3D、isampler3D 或 uSampler3D |
gsampler3D |
如果这些(类型别名)被用于多个参数,那么它们的实际类型必须保持一致,除非文档另有说明。
备注
许多接受一个或多个向量或矩阵作为参数的函数,会对向量/矩阵的每一个分量(component)分别执行所描述的操作。举几个例子:
运算 |
等价标量运算 |
|---|---|
|
|
|
|
|
|
|
|
|
|
GLSL 语言规范 在第 5.10 节向量和矩阵运算中指出:
除少数情况外,大多数运算都是按分量进行的。通常,当运算符作用于向量或矩阵时,它会以按分量的方式独立地作用于向量或矩阵的每个分量。[...] 例外情况包括矩阵乘以向量、向量乘以矩阵以及矩阵乘以矩阵。这些运算不是按分量进行的,而是执行正确的线性代数乘法。
这些函数描述改编自 Khronos Group 最初在 Open Publication License 下发布的 official OpenGL documentation ,并经过了相应的修改。每个函数的描述都附带了链接,可以直接跳转到对应的官方 OpenGL 文档。关于本页面的修改历史记录,可以在 GitHub 上查看。
三角函数
返回类型 |
函数 |
描述/返回值 |
|---|---|---|
vec_type |
radians(vec_type degrees) |
将度数转换为弧度。 |
vec_type |
degrees(vec_type radians) |
将弧度转换为度数。 |
vec_type |
sin(vec_type x) |
正弦。 |
vec_type |
cos(vec_type x) |
余弦。 |
vec_type |
tan(vec_type x) |
正切。 |
vec_type |
asin(vec_type x) |
反正弦。 |
vec_type |
acos(vec_type x) |
反余弦。 |
vec_type
vec_type
|
反正切。 |
|
vec_type |
sinh(vec_type x) |
双曲正弦。 |
vec_type |
cosh(vec_type x) |
双曲余弦。 |
vec_type |
tanh(vec_type x) |
双曲正切。 |
vec_type |
asinh(vec_type x) |
反双曲正弦。 |
vec_type |
acosh(vec_type x) |
反双曲余弦。 |
vec_type |
atanh(vec_type x) |
反双曲正切。 |
三角函数说明
vec_type radians(vec_type degrees) 🔗
将指定的角度值转换为弧度值,使用公式
度 * (PI / 180)。
- 参数:角度(以度为单位):
要转换为弧度的角度值。
- return:
将输入的
degrees转换为弧度。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/radians.xhtml
vec_type degrees(vec_type radians) 🔗
将弧度值转换为角度值,使用公式
弧度 * (180 / PI)
- 参数:弧度:
需要被转换为角度的弧度值。
- return:
将输入的
radians(弧度)转换为角度(度数)。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/degrees.xhtml
vec_type sin(vec_type angle) 🔗
返回
angle(角度)的三角正弦值。
- 参数:角度:
需要返回其正弦值的那个弧度值。
- return:
angle(角度)的正弦值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sin.xhtml
vec_type cos(vec_type angle) 🔗
返回
angle(角度)的三角余弦值。
- 参数:角度:
需要返回其余弦值的那个弧度值。
- return:
angle(角度)的余弦值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/cos.xhtml
vec_type tan(vec_type angle) 🔗
返回
angle(角度)的三角正切值。
- 参数:角度:
需要返回其正切值的那个弧度值。
- return:
angle(角度)的正切值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/tan.xhtml
vec_type asin(vec_type x) 🔗
反正弦,或称反三角正弦。用于计算正弦值为
x的角度,其结果范围在[-PI/2, PI/2](即 -90° 到 90°)之间。如果x < -1或x > 1,则结果无定义。
- 参数:x:
需要返回其反正弦值的那个数值。
- return:
其三角正弦值为
x的那个角度。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/asin.xhtml
vec_type acos(vec_type x) 🔗
反余弦,或称反三角余弦。用于计算余弦值为
x的角度,其结果范围在[0, PI](即 0° 到 180°)之间。如果
x < -1或x > 1,则结果未定义。
- 参数:x:
需要返回其反余弦值的那个数值。
- return:
其三角余弦值为
x的那个角度。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/acos.xhtml
vec_type atan(vec_type y_over_x) 🔗
根据
y/x的正切值来计算反正切。备注
由于存在符号模糊性,函数仅凭正切值无法确定角度究竟落在哪一个象限。如果你需要知道具体的象限,请使用 atan(vec_type y, vec_type x)。
- 参数:y 除以 x 的值(即 y/x):
需要返回其反正切值的那个分数(即 y/x 的比值)。
- return:
y_over_x的三角反正切值,其结果范围在[-PI/2, PI/2]之间。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/atan.xhtml
vec_type atan(vec_type y, vec_type x) 🔗
根据给定的分子和分母来计算反正切。
y和x的正负号会被用来判断该角度所在的象限。如果x == 0,则结果未定义。等价于 GDScript 的 atan2()。
- 参数 y:
需要返回其反正切值的分数的分子。
- 参数:x:
需要返回其反正切值的分数的分母。
- return:
y/x的三角反正切值,其结果范围在[-PI, PI]之间。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/atan.xhtml
vec_type sinh(vec_type x) 🔗
使用公式
(e^x - e^-x)/2来计算双曲正弦。
- 参数:x:
需要返回其双曲正弦值的那个数值。
- return:
x的双曲正弦值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sinh.xhtml
vec_type cosh(vec_type x) 🔗
使用公式
(e^x + e^-x)/2来计算双曲余弦。
- 参数:x:
返回其双曲余弦值的那个数值。
- return:
x的双曲余弦值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/cosh.xhtml
vec_type tanh(vec_type x) 🔗
使用
sinh(x)/cosh(x)来计算双曲正切。
- 参数:x:
返回其双曲正切值的那个数值。
- return:
x的双曲正切值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/tanh.xhtml
vec_type asinh(vec_type x) 🔗
计算
x的反双曲正弦值,也就是sinh的逆运算。
- 参数:x:
返回其反双曲正弦值的那个数值。
- return:
x的反双曲正弦值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/asinh.xhtml
vec_type acosh(vec_type x) 🔗
计算
x的反双曲余弦值,也就是cosh的非负逆运算。如果x < 1,则结果未定义。
- 参数:x:
返回其反双曲余弦值的那个数值。
- return:
x的反双曲余弦值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/acosh.xhtml
vec_type atanh(vec_type x) 🔗
计算
x的反双曲正切值,也就是tanh的逆运算。如果abs(x) > 1(即 x 的绝对值大于 1),则结果未定义。
- 参数:x:
返回其反双曲正切值的那个数值。
- return:
x的反双曲正切值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/atanh.xhtml
指数与数学函数
返回类型 |
函数 |
描述/返回值 |
|---|---|---|
vec_type |
pow(vec_type x, vec_type y) |
幂( |
vec_type |
exp(vec_type x) |
基数 e 的指数。 |
vec_type |
exp2(vec_type x) |
基数 2 的指数。 |
vec_type |
log(vec_type x) |
自然对数(基数 e)。 |
vec_type |
log2(vec_type x) |
基数 2 的对数。 |
vec_type |
sqrt(vec_type x) |
平方根。 |
vec_type |
inversesqrt(vec_type x) |
反平方根。 |
vec_type
vec_int_type
|
绝对值(如果为负数,则返回正值)。 |
|
vec_type |
sign(vec_type x) |
如果是正数则返回 |
vec_int_type |
sign(vec_int_type x) |
如果是正数则返回 |
vec_type |
floor(vec_type x) |
向下舍入为整数。 |
vec_type |
round(vec_type x) |
舍入到最接近的整数。 |
vec_type |
roundEven(vec_type x) |
舍入到最接近的偶数。 |
vec_type |
trunc(vec_type x) |
截断。 |
vec_type |
ceil(vec_type x) |
向上舍入为整数。 |
vec_type |
fract(vec_type x) |
分数(返回 |
vec_type
vec_type
|
模(除法余数)。 |
|
vec_type |
modf(vec_type x, out vec_type i) |
|
vec_type
vec_type
vec_int_type
vec_int_type
vec_uint_type
vec_uint_type
|
|
|
vec_type
vec_type
vec_int_type
vec_int_type
vec_uint_type
vec_uint_type
|
|
|
vec_type
vec_type
vec_int_type
vec_int_type
vec_uint_type
vec_uint_type
|
将 |
|
vec_type
vec_type
vec_type
|
根据 |
|
vec_type |
fma(vec_type a, vec_type b, vec_type c) |
融合乘加运算: |
vec_type
vec_type
|
|
|
vec_type
vec_type
|
smoothstep(vec_type a, vec_type b, vec_type c)
smoothstep(float a, float b, vec_type c)
|
根据 |
vec_bool_type |
isnan(vec_type x) |
如果标量或向量分量是 |
vec_bool_type |
isinf(vec_type x) |
如果标量或向量分量是 |
vec_int_type |
floatBitsToInt(vec_type x) |
将 |
vec_uint_type |
floatBitsToUint(vec_type x) |
将 |
vec_type |
intBitsToFloat(vec_int_type x) |
将 |
vec_type |
uintBitsToFloat(vec_uint_type x) |
将 |
指数函数与数学函数说明
vec_type pow(vec_type x, vec_type y) 🔗
计算
x的y次幂。“如果
x < 0,或者x == 0且y <= 0,则结果是未定义的。
- 参数:x:
将被提升至
y次幂的数值。- 参数 y:
x将被提升到的幂次。- return:
x的y次幂的值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/pow.xhtml
vec_type exp(vec_type x) 🔗
计算
e的x次幂,也就是自然指数运算。等同于
pow(e, x)。
- 参数:x:
进行指数运算的数值。
- return:
x的自然指数(运算结果)。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/exp.xhtml
vec_type exp2(vec_type x) 🔗
计算
2的x次幂。等同于
pow(2.0, x)。
- 参数:x:
2将被提升到的幂次。- return:
2的 x 次幂。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/exp2.xhtml
vec_type log(vec_type x) 🔗
返回
x的自然对数,也就是满足x == pow(e, y)的值y。如果x <= 0,则结果未定义。
- 参数:x:
求自然对数的那个数值。
- return:
x的自然对数。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/log.xhtml
vec_type log2(vec_type x) 🔗
返回
x以 2 为底的对数,即满足x == pow(2, y)的值y。如果x <= 0,则结果未定义。
- 参数:x:
求以 2 为底的对数的那个数值。
- return:
x以 2 为底的对数。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/log2.xhtml
vec_type sqrt(vec_type x) 🔗
返回
x的平方根。如果x < 0,则结果未定义。
- 参数:x:
求平方根的那个数值。
- return:
x的平方根。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sqrt.xhtml
vec_type inversesqrt(vec_type x) 🔗
返回
x的平方根的倒数,也就是1.0 / sqrt(x)。如果x <= 0,则结果未定义。
- 参数:x:
取平方根的倒数。
- return:
x的平方根的倒数。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/inversesqrt.xhtml
vec_type abs(vec_type x) 🔗
vec_int_type abs(vec_int_type x) 🔗
返回
x的绝对值。如果x是正数,则返回x;否则,返回-1 * x。
- 参数:x:
绝对值。
- return:
x的绝对值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/abs.xhtml
vec_type sign(vec_type x) 🔗
vec_int_type sign(vec_int_type x) 🔗
如果
x < 0则返回-1,如果x == 0则返回0,如果x > 0则返回1。
- 参数:x:
提取符号。
- return:
x的符号。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sign.xhtml
vec_type floor(vec_type x) 🔗
返回一个等于最接近、且小于或等于
x的整数的值。
- 参数:x:
向下取整。
- return:
最接近、且小于或等于
x的整数。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/floor.xhtml
vec_type round(vec_type x) 🔗
将
x四舍五入到最接近的整数。备注
对于小数部分恰好为
0.5的数值,其舍入方式取决于具体的实现。 这也意味着,round(x)在所有x的取值下,都有可能返回与roundEven(x)完全相同的结果。
- 参数:x:
四舍五入。
- return:
绑定值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/round.xhtml
vec_type roundEven(vec_type x) 🔗
将
x四舍五入到最接近的整数。如果小数部分刚好是0.5,则始终向最近的偶数取整。例如,3.5和4.5都会四舍五入为4.0。
- 参数:x:
四舍五入。
- return:
绑定值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/roundEven.xhtml
vec_type trunc(vec_type x) 🔗
截断
x。返回一个最接近x的整数,且该整数的绝对值不大于x的绝对值。
- 参数:x:
要进行计算的数值。
- return:
截断后的值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/trunc.xhtml
vec_type ceil(vec_type x) 🔗
返回一个等于最接近 x 且大于或等于
x的整数。
- 参数:x:
要进行计算的数值。
- return:
向上取整后的值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/ceil.xhtml
vec_type fract(vec_type x) 🔗
返回
x的小数部分。计算方法为
x - floor(x)。
- 参数:x:
要进行计算的数值。
- return:
x的小数部分。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fract.xhtml
vec_type mod(vec_type x, vec_type y) 🔗
vec_type mod(vec_type x, float y) 🔗
返回
x 对 y 取模的值。取余数。计算方法为
x - y * floor(x/y)。
- 参数:x:
要进行计算的数值。
- return:
x modulo y(或余数)。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mod.xhtml
vec_type modf(vec_type x, out vec_type i) 🔗
将一个浮点数值
x拆分为整数部分和小数部分。函数会返回该数字的小数部分。而整数部分(以浮点数的形式)则会通过输出参数
i返回。
- 参数:x:
需要拆分(或分离)的数值。
- param out i:
一个接收
x整数部分的变量。- return:
数字的小数部分。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/modf.xhtml
vec_type min(vec_type a, vec_type b) 🔗
vec_type min(vec_type a, float b) 🔗
vec_int_type min(vec_int_type a, vec_int_type b) 🔗
vec_int_type min(vec_int_type a, int b) 🔗
vec_uint_type min(vec_uint_type a, vec_uint_type b) 🔗
vec_uint_type min(vec_uint_type a, uint b) 🔗
返回两个值
a和b中的最小值。如果
b < a则返回b,否则返回a。
- param a:
要比较的第一个值。
- 参数 b:
要比较的第二个值。
- return:
最小值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/min.xhtml
vec_type max(vec_type a, vec_type b) 🔗
vec_type max(vec_type a, float b) 🔗
vec_uint_type max(vec_uint_type a, vec_uint_type b) 🔗
vec_uint_type max(vec_uint_type a, uint b) 🔗
vec_int_type max(vec_int_type a, vec_int_type b) 🔗
vec_int_type max(vec_int_type a, int b) 🔗
a和b中的较大值。如果
b > a则返回b,否则返回a。
- param a:
要比较的第一个值。
- 参数 b:
要比较的第二个值。
- return:
最大值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/max.xhtml
vec_type clamp(vec_type x, vec_type minVal, vec_type maxVal) 🔗
vec_type clamp(vec_type x, float minVal, float maxVal) 🔗
vec_int_type clamp(vec_int_type x, vec_int_type minVal, vec_int_type maxVal) 🔗
vec_int_type clamp(vec_int_type x, int minVal, int maxVal) 🔗
vec_uint_type clamp(vec_uint_type x, vec_uint_type minVal, vec_uint_type maxVal) 🔗
vec_uint_type clamp(vec_uint_type x, uint minVal, uint maxVal) 🔗
返回将
x限制在minVal到maxVal范围内的值。返回值的计算方法为
min(max(x, minVal), maxVal)。
- 参数:x:
要约束的值。
- param minVal:
x约束范围的下限。- 参数 maxVal:
x约束范围的上限。- return:
限制后的值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/clamp.xhtml
vec_type mix(vec_type a, vec_type b, vec_type c) 🔗
vec_type mix(vec_type a, vec_type b, float c) 🔗
使用
c作为权重,在a和b之间进行线性插值。计算方式为
a * (1 - c) + b * c。等价于 GDScript 中的 lerp()。
- param a:
插值范围的起始值。
- 参数 b:
插值范围的结束值。
- 参数 c:
用于在
a和b之间进行插值的数值。- return:
插值后的值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mix.xhtml
vec_type mix(vec_type a, vec_type b, vec_bool_type c) 🔗
根据
c的值,来选择返回a还是b。如果c的某个分量为假(false),则返回a对应的分量;如果c的某个分量为真(true),则返回b对应的分量。此外,a和b中那些没被选中的分量,允许是无效的浮点数值(比如 NaN 或无穷大),并且不会对最终结果产生任何影响。如果
a、b和c都是向量类型,该操作会按分量( component-wise)进行。也就是说,mix(vec2(42, 314), vec2(9.8, 6e23), bvec2(true, false)))将会返回vec2(9.8, 314)。
- param a:
当
c为假(false)时返回的值。- 参数 b:
当
c为真(true)时返回的值。- 参数 c:
用于在
a和b之间进行选择的那个值。- return:
插值后的值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mix.xhtml
vec_type fma(vec_type a, vec_type b, vec_type c) 🔗
在条件允许的情况下,执行‘融合乘加’(fused multiply-add)运算,返回
a * b + c的结果。在那些返回值最终被一个声明为 precise(精确)的变量所消费(使用)的使用场景中:
fma()被视为一次(单一)运算,而被声明为 precise 的变量所消费的表达式a * b + c,则被视为两次运算。
fma()的精度,可能会与表达式a * b + c的精度不同。
fma()的计算精度,将与被 precise 变量使用的任何其他fma()保持一致,从而保证在 a、b 和 c 的输入值相同时,得出的结果也是恒定不变的。否则,在没有被 precise 变量消费(使用)的情况下,对于运算的次数,或者
fma()与表达式a * b + c之间的精度差异,就没有任何特殊的约束了。
- param a:
第一个乘数。
- 参数 b:
第二个乘数。
- 参数 c:
与积相加的值。
- return:
a * b + c的值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fma.xhtml
vec_type step(vec_type a, vec_type b) 🔗
vec_type step(float a, vec_type b) 🔗
通过将 b 与 a 进行比较,来生成一个阶跃函数。
它等价于
if (b < a) { return 0.0; } else { return 1.0; }。对于返回值中的第 i 个元素,如果 b[i] < a[i],则返回 0.0;否则返回 1.0。
- param a:
阶跃函数边缘的位置。
- 参数 b:
用于生成阶跃函数的那个值。
- return:
0.0或1.0。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/step.xhtml
vec_type smoothstep(vec_type a, vec_type b, vec_type c) 🔗
vec_type smoothstep(float a, float b, vec_type c) 🔗
当 a < c < b 时,在
0和1之间执行平滑的埃尔米特(Hermite)插值。这在需要带有平滑过渡效果的阈值函数时非常有用。Smoothstep 等同于:
vec_type t; t = clamp((c - a) / (b - a), 0.0, 1.0); return t * t * (3.0 - 2.0 * t);如果
a >= b,则结果未定义。
- param a:
埃尔米特(Hermite)函数的下边缘值。
- 参数 b:
埃尔米特(Hermite)函数的上边缘值。
- 参数 c:
用于插值的源值。
- return:
插值后的值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/smoothstep.xhtml
vec_bool_type isnan(vec_type x) 🔗
对于结果中的每个元素 i,如果 x[i] 是正数或负数的 NaN(Not a Number,非数字),则返回
true,否则返回 false。
- 参数:x:
要与 NaN 比较的值。
- return:
true或false。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/isnan.xhtml
vec_bool_type isinf(vec_type x) 🔗
对于结果中的每一个元素 i,如果 x[i] 是正无穷大或负无穷大的浮点数,则返回
true,否则返回 false。
- 参数:x:
要检查是否无穷的值。
- return:
true或false。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/isinf.xhtml
vec_int_type floatBitsToInt(vec_type x) 🔗
返回浮点参数的编码值,类型为
int。浮点数的位级表示被保留。
- 参数:x:
要返回其浮点编码的值。
- return:
x的浮点编码。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/floatBitsToInt.xhtml
vec_uint_type floatBitsToUint(vec_type x) 🔗
返回浮点参数的编码值,类型为
uint。浮点数的位级表示被保留。
- 参数:x:
要返回其浮点编码的值。
- return:
x的浮点编码。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/floatBitsToInt.xhtml
vec_type intBitsToFloat(vec_int_type x) 🔗
将位编码转换为浮点数值。是 floatBitsToInt<shader_func_floatBitsToInt> 的逆操作
如果传入的
x是一个NaN的编码,它将不会触发信号,并且产生的结果值将是未定义的。如果传入的参数
x是一个浮点数无穷大的编码,那么产生的浮点数值将是相应的(正或负)浮点数无穷大。
- 参数:x:
要以浮点数值形式返回的那个位编码。
- return:
浮点值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/intBitsToFloat.xhtml
vec_type uintBitsToFloat(vec_uint_type x) 🔗
将位编码转换为浮点数值。是 floatBitsToUint<shader_func_floatBitsToUint> 的逆操作
如果传入的
x是一个NaN的编码,它将不会触发信号,并且产生的结果值将是未定义的。如果传入的参数
x是一个浮点数无穷大的编码,那么产生的浮点数值将是相应的(正或负)浮点数无穷大。
- 参数:x:
要以浮点数值形式返回的那个位编码。
- return:
浮点值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/intBitsToFloat.xhtml
几何函数
float |
length(vec_type x) |
向量长度。 |
float |
distance(vec_type a, vec_type b) |
向量的间距,即 |
float |
dot(vec_type a, vec_type b) |
点积。 |
vec3 |
cross(vec3 a, vec3 b) |
叉积。 |
vec_type |
normalize(vec_type x) |
归一化为单位长度。 |
vec3 |
reflect(vec3 I, vec3 N) |
反射。 |
vec3 |
refract(vec3 I, vec3 N, float eta) |
折射。 |
vec_type |
faceforward(vec_type N, vec_type I, vec_type Nref) |
如果 |
mat_type |
matrixCompMult(mat_type x, mat_type y) |
矩阵分量乘法。 |
mat_type |
outerProduct(vec_type column, vec_type row) |
矩阵外积。 |
mat_type |
transpose(mat_type m) |
转置矩阵。 |
float |
determinant(mat_type m) |
矩阵行列式。 |
mat_type |
inverse(mat_type m) |
逆矩阵。 |
几何函数描述
float length(vec_type x) 🔗
返回向量的长度。即
sqrt(x[0] * x[0] + x[1] * x[1] + ... + x[n] * x[n])
- 参数:x:
向量
- return:
向量的长度。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/length.xhtml
float distance(vec_type a, vec_type b) 🔗
返回 a、b 两点之间的距离。
即
length(b - a);
- param a:
第一个点。
- 参数 b:
第二个点。
- return:
两点之间的标量距离
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/distance.xhtml
float dot(vec_type a, vec_type b) 🔗
返回向量
a和b的点积,即a.x * b.x + a.y * b.y + ...
- param a:
第一个向量。
- 参数 b:
第二个向量。
- return:
点积。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/dot.xhtml
vec3 cross(vec3 a, vec3 b) 🔗
返回两个向量的叉积。即:
vec2( a.y * b.z - b.y * a.z, a.z * b.x - b.z * a.x, a.x * b.z - b.x * a.y)
- param a:
第一个向量。
- 参数 b:
第二个向量。
- return:
a和b的叉积。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/cross.xhtml
vec_type normalize(vec_type x) 🔗
返回与
x方向相同但长度为1.0的向量。
- 参数:x:
要归一化的向量。
- return:
归一化的向量。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/normalize.xhtml
vec3 reflect(vec3 I, vec3 N) 🔗
计算入射向量的反射方向。
对于给定的入射向量
I和表面法线N,reflect 函数返回的反射方向是通过I - 2.0 * dot(N, I) * N计算得出的。备注
N应当被归一化,才能得到理想的结果。
- param I:
事件向量。
- param N:
法向量。
- return:
反射向量。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/reflect.xhtml
vec3 refract(vec3 I, vec3 N, float eta) 🔗
计算入射向量的折射方向。
对于给定的入射向量
I、表面法线N以及折射率之比eta,refract 函数会返回折射向量R。
R的计算公式如下:k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I)); if (k < 0.0) R = genType(0.0); // or genDType(0.0) else R = eta * I - (eta * dot(N, I) + sqrt(k)) * N;备注
输入参数 I 和 N 应当被归一化,才能得到理想的结果。
- param I:
事件向量。
- param N:
法向量。
- 参数 eta:
折射率之比。
- return:
折射矢量 。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/refract.xhtml
vec_type faceforward(vec_type N, vec_type I, vec_type Nref) 🔗
返回指向与另一个向量相同方向的向量。
修改向量的朝向,让其远离由法线定义的表面。如果
dot(Nref, I) < 0,faceforward 返回N,否则返回-N。
- param N:
要修改朝向的向量。
- param I:
事件向量。
- param Nref:
参考向量。
- return:
修改朝向后的向量。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/faceforward.xhtml
mat_type matrixCompMult(mat_type x, mat_type y) 🔗
对两个矩阵执行 component-wise 乘法。
对两个矩阵进行逐元素相乘,得到一个结果矩阵。其中每个元素
result[i][j]都是通过计算x[i][j]和y[i][j]的标量积得出的。
- 参数:x:
第一个矩阵乘数。
- 参数 y:
第二个矩阵乘数。
- return:
结果矩阵。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/matrixCompMult.xhtml
mat_type outerProduct(vec_type column, vec_type row) 🔗
计算两个向量的外积。
是否执行线性代数中的矩阵乘法
column * row,其结果矩阵的行数等于column(列向量)的分量个数,列数等于row(行向量)的分量个数。
- param column:
乘法中的列向量。
- param row:
乘法中的行向量。
- return:
外积矩阵。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/outerProduct.xhtml
mat_type transpose(mat_type m) 🔗
计算矩阵的转置。
- param m:
要转置的矩阵。
- return:
输入矩阵
m的转置矩阵,这是一个新的矩阵。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/transpose.xhtml
float determinant(mat_type m) 🔗
计算矩阵的行列式。
- param m:
矩阵。
- return:
输入矩阵
m的行列式。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/determinant.xhtml
mat_type inverse(mat_type m) 🔗
计算矩阵的逆矩阵。
如果矩阵
m是奇异的,或者状态很差(接近奇异),那么返回的矩阵中的数值将是未定义的。
- param m:
要求逆的矩阵。
- return:
一个新的矩阵,它是输入矩阵
m的逆矩阵。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/inverse.xhtml
比较函数
vec_bool_type |
lessThan(vec_type x, vec_type y) |
Bool vector 对比 < int/uint/float vectors。 |
vec_bool_type |
greaterThan(vec_type x, vec_type y) |
Bool vector 对比 > int/uint/float vectors。 |
vec_bool_type |
lessThanEqual(vec_type x, vec_type y) |
Bool vector 对比 <= int/uint/float vectors。 |
vec_bool_type |
greaterThanEqual( vec_type x, vec_type y) |
Bool vector 对比 >= int/uint/float vectors。 |
vec_bool_type |
equal(vec_type x, vec_type y) |
Bool vector 对比 == int/uint/float vectors。 |
vec_bool_type |
notEqual(vec_type x, vec_type y) |
Bool vector 对比 != int/uint/float vectors。 |
bool |
any(vec_bool_type x) |
任意分量为 |
bool |
all(vec_bool_type x) |
所有分量均为 |
vec_bool_type |
not(vec_bool_type x) |
反转布尔向量。 |
比较函数描述
vec_bool_type lessThan(vec_type x, vec_type y) 🔗
对两个向量执行按分量( component-wise )的‘小于’比较。
- 参数:x:
要比较的第一个向量。
- 参数 y:
要比较的第二个向量。
- return:
一个布尔向量,分量
i的计算方法为x[i] < y[i]。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/lessThan.xhtml
vec_bool_type greaterThan(vec_type x, vec_type y) 🔗
对两个向量执行按分量的 component-wise 比较。
- 参数:x:
要比较的第一个向量。
- 参数 y:
要比较的第二个向量。
- return:
一个布尔向量,分量
i的计算方法为x[i] > y[i]。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/greaterThan.xhtml
vec_bool_type lessThanEqual(vec_type x, vec_type y) 🔗
component-wise 对两个向量进行逐分量的小于等于(less-than-or-equal)比较。
- 参数:x:
要比较的第一个向量。
- 参数 y:
要比较的第二个向量。
- return:
一个布尔向量,分量
i的计算方法为x[i] <= y[i]。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/lessThanEqual.xhtml
vec_bool_type greaterThanEqual(vec_type x, vec_type y) 🔗
component-wise 对两个向量进行逐分量的大于等于(greater-than-or-equal)比较。
- 参数:x:
要比较的第一个向量。
- 参数 y:
要比较的第二个向量。
- return:
一个布尔向量,分量
i的计算方法为x[i] >= y[i]。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/greaterThanEqual.xhtml
vec_bool_type equal(vec_type x, vec_type y) 🔗
component-wise 对两个向量进行逐分量的等于(equal-to)比较。
- 参数:x:
要比较的第一个向量。
- 参数 y:
要比较的第二个向量。
- return:
一个布尔向量,分量
i的计算方法为x[i] == y[i]。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/equal.xhtml
vec_bool_type notEqual(vec_type x, vec_type y) 🔗
对两个向量进行逐分量的不等于(not-equal-to)比较 component-wise 。
- 参数:x:
要比较的第一个向量。
- 参数 y:
要比较的第二个向量。
- return:
一个布尔向量,分量
i的计算方法为x[i] != y[i]。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/notEqual.xhtml
bool any(vec_bool_type x) 🔗
如果布尔向量中的任意分量为
true则返回true,否则返回false。在功能上等同于:
bool any(bvec x) { // bvec can be bvec2, bvec3 or bvec4 bool result = false; int i; for (i = 0; i < x.length(); ++i) { result |= x[i]; } return result; }
- 参数:x:
要检查真假的向量。
- return:
如果 x 中的任意分量为 true 则为 true,否则为 false。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/any.xhtml
bool all(vec_bool_type x) 🔗
如果布尔向量中的所有分量均为
true则返回true,否则返回false。在功能上等同于:
bool all(bvec x) // bvec can be bvec2, bvec3 or bvec4 { bool result = true; int i; for (i = 0; i < x.length(); ++i) { result &= x[i]; } return result; }
- 参数:x:
要检查真假的向量。
- return:
如果
x中的所有分量均为true则为true,否则为false。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/all.xhtml
vec_bool_type not(vec_bool_type x) 🔗
对布尔向量进行逻辑取反。
- 参数:x:
需要取反的向量。
- return:
生成一个新的布尔向量,其中每个元素 i 的值都等于 !x[i]。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/not.xhtml
纹理函数
ivec2
ivec2
ivec2
ivec3
ivec3
|
textureSize(gsampler2D s, int lod)
textureSize(samplerCube s, int lod)
textureSize(samplerCubeArray s, int lod)
textureSize(gsampler2DArray s, int lod)
textureSize(gsampler3D s, int lod)
|
获取纹理的大小。 出于性能考虑,应尽量避免使用此函数,因为它总是会执行一次完整的纹理读取。如果可能的话,你应该改为将纹理尺寸作为一个 uniform(全局变量)传递进去。 |
vec2
vec3
vec2
vec2
|
textureQueryLod(gsampler2D s, vec2 p)
textureQueryLod(gsampler2DArray s, vec2 p)
textureQueryLod(gsampler3D s, vec3 p)
textureQueryLod(samplerCube s, vec3 p)
|
计算对纹理进行采样时,将会使用的细节层级(level-of-detail)。 |
int
int
int
int
|
textureQueryLevels(gsampler2D s)
textureQueryLevels(gsampler2DArray s)
textureQueryLevels(gsampler3D s)
textureQueryLevels(samplerCube s)
|
获取纹理中可访问的 mipmap 层级的数量。 |
gvec4_type
gvec4_type
gvec4_type
vec4
vec4
vec4
|
执行纹理读取。 |
|
gvec4_type
gvec4_type
gvec4_type
|
textureProj(gsampler2D s, vec3 p [, float bias] )
textureProj(gsampler2D s, vec4 p [, float bias] )
textureProj(gsampler3D s, vec4 p [, float bias] )
|
执行带投影的纹理读取。 |
gvec4_type
gvec4_type
gvec4_type
vec4
vec4
|
textureLod(gsampler2D s, vec2 p, float lod)
textureLod(gsampler2DArray s, vec3 p, float lod)
textureLod(gsampler3D s, vec3 p, float lod)
textureLod(samplerCube s, vec3 p, float lod)
textureLod(samplerCubeArray s, vec4 p, float lod)
|
在自定义 mipmap 上执行纹理读取。 |
gvec4_type
gvec4_type
gvec4_type
|
textureProjLod(gsampler2D s, vec3 p, float lod)
textureProjLod(gsampler2D s, vec4 p, float lod)
textureProjLod(gsampler3D s, vec4 p, float lod)
|
执行带投影/LOD的2D纹理读取。 |
gvec4_type
gvec4_type
gvec4_type
vec4
vec4
|
textureGrad(gsampler2D s, vec2 p, vec2 dPdx, vec2 dPdy)
textureGrad(gsampler2DArray s, vec3 p, vec2 dPdx, vec2 dPdy)
textureGrad(gsampler3D s, vec3 p, vec2 dPdx, vec2 dPdy)
textureGrad(samplerCube s, vec3 p, vec3 dPdx, vec3 dPdy)
textureGrad(samplerCubeArray s, vec3 p, vec3 dPdx, vec3 dPdy)
|
执行带显式渐变的纹理读取。 |
gvec4_type
gvec4_type
gvec4_type
|
textureProjGrad(gsampler2D s, vec3 p, vec2 dPdx, vec2 dPdy)
textureProjGrad(gsampler2D s, vec4 p, vec2 dPdx, vec2 dPdy)
textureProjGrad(gsampler3D s, vec4 p, vec3 dPdx, vec3 dPdy)
|
执行带投影/LOD、带显式渐变的纹理读取 |
gvec4_type
gvec4_type
gvec4_type
|
texelFetch(gsampler2D s, ivec2 p, int lod)
texelFetch(gsampler2DArray s, ivec3 p, int lod)
texelFetch(gsampler3D s, ivec3 p, int lod)
|
使用整数坐标获取单个纹素。 |
gvec4_type
gvec4_type
vec4
|
textureGather(gsampler2D s, vec2 p [, int comps] )
textureGather(gsampler2DArray s, vec3 p [, int comps] )
textureGather(samplerCube s, vec3 p [, int comps] )
|
在纹理中收集四个纹素。 |
vec_type |
dFdx(vec_type p) |
相对于 |
vec_type |
dFdxCoarse(vec_type p) |
相对于 使用兼容性渲染器(Compatibility renderer)时不可用。 |
vec_type |
dFdxFine(vec_type p) |
相对于 使用兼容性渲染器(Compatibility renderer)时不可用。 |
vec_type |
dFdy(vec_type p) |
相对于 |
vec_type |
dFdyCoarse(vec_type p) |
相对于 使用兼容性渲染器(Compatibility renderer)时不可用。 |
vec_type |
dFdyFine(vec_type p) |
相对于 使用兼容性渲染器(Compatibility renderer)时不可用。 |
vec_type |
fwidth(vec_type p) |
|
vec_type |
fwidthCoarse(vec_type p) |
使用兼容性渲染器(Compatibility renderer)时不可用。 |
vec_type |
fwidthFine(vec_type p) |
使用兼容性渲染器(Compatibility renderer)时不可用。 |
纹理函数描述
ivec2 textureSize(gsampler2D s, int lod) 🔗
ivec2 textureSize(samplerCube s, int lod) 🔗
ivec2 textureSize(samplerCubeArray s, int lod) 🔗
ivec3 textureSize(gsampler2DArray s, int lod) 🔗
ivec3 textureSize(gsampler3D s, int lod) 🔗
获取纹理某一层级的尺寸。
返回绑定到 sampler 的纹理中,
lod层级(如果存在的话)的尺寸。返回值中的各个分量会按顺序依次填充纹理的宽度、高度和深度。对于数组形式(array forms)来说,返回值的最后一个分量代表纹理数组中的层数。
- param s:
绑定了待获取尺寸的那张纹理的采样器(sampler)。
- param lod:
要获取尺寸的那个纹理层级。
- return:
绑定到 sampler 的纹理中,
lod层级(如果存在的话)的尺寸。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureSize.xhtml
vec2 textureQueryLod(gsampler2D s, vec2 p) 🔗
vec2 textureQueryLod(gsampler2DArray s, vec2 p) 🔗
vec2 textureQueryLod(gsampler3D s, vec3 p) 🔗
vec2 textureQueryLod(samplerCube s, vec3 p) 🔗
备注
仅在片段着色器中可用。
计算对纹理进行采样时,将会使用的细节层级(level-of-detail)。
返回值的 x 分量表示将会被访问的 Mipmap 数组(或层级);y 分量则表示计算得出的、相对于基础层级(base level)的细节层级(level-of-detail)。
如果在一张不完整的纹理上调用此函数,该操作的结果将是未定义的。
- param s:
那张需要查询细节层级(level-of-detail)的纹理,所绑定的采样器(sampler)。
- 参数 p:
将用于查询细节层级(level-of-detail)的纹理坐标。
- return:
见说明。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureQueryLod.xhtml
int textureQueryLevels(gsampler2D s) 🔗
int textureQueryLevels(gsampler2DArray s) 🔗
int textureQueryLevels(gsampler3D s) 🔗
int textureQueryLevels(samplerCube s) 🔗
计算纹理中可访问的 Mipmap 层级数量。
如果在一张不完整的纹理上调用此函数,或者 sampler 没有关联任何纹理,则返回
0。
- param s:
绑定了待查询 Mipmap 层级数量的那张纹理的采样器(sampler)。
- return:
纹理中可访问的 Mipmap 层级数量,或者为
0。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureQueryLevels.xhtml
gvec4_type texture(gsampler2D s, vec2 p [, float bias] ) 🔗
gvec4_type texture(gsampler2DArray s, vec3 p [, float bias] ) 🔗
gvec4_type texture(gsampler3D s, vec3 p [, float bias] ) 🔗
vec4 texture(samplerCube s, vec3 p [, float bias] ) 🔗
vec4 texture(samplerCubeArray s, vec4 p [, float bias] ) 🔗
vec4 texture(samplerExternalOES s, vec2 p [, float bias] ) 🔗
获取纹理中的纹素。
在与
s绑定的纹理上对纹理坐标p处进行纹素采样。还可以通过bias指定细节层级计算的偏置量,用于选择采样的 mipmap。对于阴影(shadow)形式,
p的最后一个分量会被用作 Dsub(即深度参考值),而数组层(array layer)则由p的倒数第二个分量来指定。(对于一维阴影查找,p的第二个分量不会被使用。)对于非阴影(non-shadow)版本,数组层(array layer)取自 P 的最后一个分量。
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- param bias:
在进行细节层级(level-of-detail)计算时,可以应用的可选偏移量。
- return:
纹素。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/texture.xhtml
gvec4_type textureProj(gsampler2D s, vec3 p [, float bias] ) 🔗
gvec4_type textureProj(gsampler2D s, vec4 p [, float bias] ) 🔗
gvec4_type textureProj(gsampler3D s, vec4 p [, float bias] ) 🔗
执行带投影的纹理读取。
从
p中获取的纹理坐标(不包含p的最后一个分量),会先除以p的最后一个分量。在阴影采样形式中,p经过这样计算后得到的第3个分量会被用作 Dref(深度参考值)。在这些数值计算完毕之后,纹理查找的过程就会像 texture 那样继续进行。
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- param bias:
在进行细节层级(level-of-detail)计算时,可以应用的可选偏移量。
- return:
纹素。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureProj.xhtml
gvec4_type textureLod(gsampler2D s, vec2 p, float lod) 🔗
gvec4_type textureLod(gsampler2DArray s, vec3 p, float lod) 🔗
gvec4_type textureLod(gsampler3D s, vec3 p, float lod) 🔗
vec4 textureLod(samplerCube s, vec3 p, float lod) 🔗
vec4 textureLod(samplerCubeArray s, vec4 p, float lod) 🔗
根据
lod中指定的明确细节层级,从绑定到采样器(sampler)的纹理中,在坐标p处执行纹理查找。其中,lod指定了 λbase,并按如下方式设置偏导数:δu/δx=0, δv/δx=0, δw/δx=0 δu/δy=0, δv/δy=0, δw/δy=0
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- param lod:
明确的细节层级(level-of-detail)。
- return:
纹素。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureLod.xhtml
gvec4_type textureProjLod(gsampler2D s, vec3 p, float lod) 🔗
gvec4_type textureProjLod(gsampler2D s, vec4 p, float lod) 🔗
gvec4_type textureProjLod(gsampler3D s, vec4 p, float lod) 🔗
从明确指定的细节层级(level-of-detail)中,执行带有投影(projection)的纹理查找。
从 P 中获取的纹理坐标(不包含
p的最后一个分量),会先除以p的最后一个分量。在阴影采样形式中,p经过这样计算后得到的第3个分量会被用作 Dref(深度参考值)。在这些数值计算完毕之后,纹理查找的过程就会像 textureLod 那样继续进行,并使用lod来指定从哪个细节层级(level-of-detail)对纹理进行采样。
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- param lod:
用于获取纹理元素(texels)的明确细节层级(level-of-detail)。
- return:
纹素
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureProjLod.xhtml
gvec4_type textureGrad(gsampler2D s, vec2 p, vec2 dPdx, vec2 dPdy) 🔗
gvec4_type textureGrad(gsampler2DArray s, vec3 p, vec2 dPdx, vec2 dPdy) 🔗
gvec4_type textureGrad(gsampler3D s, vec3 p, vec2 dPdx, vec2 dPdy) 🔗
vec4 textureGrad(samplerCube s, vec3 p, vec3 dPdx, vec3 dPdy) 🔗
vec4 textureGrad(samplerCubeArray s, vec3 p, vec3 dPdx, vec3 dPdy) 🔗
- 以
dPdx和dPdy中指定的显式纹理坐标梯度,从 sampler 绑定的纹理中,对坐标p处进行纹理查找。设置:
1D 纹理为
δs/δx=δp/δx,其他为δp.s/δx1D 纹理为
δs/δy=δp/δy,其他为δp.s/δy1D 纹理为
δt/δx=0.0,其他为δp.t/δx1D 纹理为
δt/δy=0.0,其他为δp.t/δy1D 和 2D 纹理为
δr/δx=0.0,其他为δp.p/δx1D 和 2D 纹理为
δr/δy=0.0,其他为δp.p/δy对于立方体贴图(cube)版本,
p的偏导数被认为是处于纹理坐标被投影到合适的立方体面之前的坐标系中的。
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- param dPdx:
P 相对于窗口 x 坐标的偏导数。
- param dPdy:
P 相对于窗口 y 坐标的偏导数。
- return:
纹素。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureGrad.xhtml
gvec4_type textureProjGrad(gsampler2D s, vec3 p, vec2 dPdx, vec2 dPdy) 🔗
gvec4_type textureProjGrad(gsampler2D s, vec4 p, vec2 dPdx, vec2 dPdy) 🔗
gvec4_type textureProjGrad(gsampler3D s, vec4 p, vec3 dPdx, vec3 dPdy) 🔗
执行带投影和显式梯度计算的纹理查找。
从
p中获取的纹理坐标(不包含p的最后一个分量),会先除以p的最后一个分量。在算出这些值之后,纹理查找的过程就会像 textureGrad<shader_func_textureGrad> 那样继续进行,并把dPdx和dPdy作为梯度参数传进去。
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- param dPdx:
p相对于窗口 x 坐标的偏导数。- param dPdy:
p相对于窗口 y 坐标的偏导数。- return:
纹素。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureProjGrad.xhtml
gvec4_type texelFetch(gsampler2D s, ivec2 p, int lod) 🔗
gvec4_type texelFetch(gsampler2DArray s, ivec3 p, int lod) 🔗
gvec4_type texelFetch(gsampler3D s, ivec3 p, int lod) 🔗
根据纹理坐标
p,从采样器(sampler)所绑定的纹理中查找并获取单个纹素(texel)。
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- param lod:
指定将从纹理的哪个细节层级(level-of-detail)中获取纹素(texel)。
- return:
纹素。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/texelFetch.xhtml
gvec4_type textureGather(gsampler2D s, vec2 p [, int comps] ) 🔗
gvec4_type textureGather(gsampler2DArray s, vec3 p [, int comps] ) 🔗
vec4 textureGather(samplerCube s, vec3 p [, int comps] ) 🔗
在纹理中收集四个纹素。
返回值为:
vec4(Sample_i0_j1(p, base).comps, Sample_i1_j1(p, base).comps, Sample_i1_j0(p, base).comps, Sample_i0_j0(p, base).comps);
- param s:
用于提取纹素的纹理所绑定的采样器(sampler)。
- 参数 p:
用于对纹理进行采样的纹理坐标。
- 参数 comps:
可选参数: 指定使用源纹理的哪个分量(0 -> x, 1 -> y, 2 -> z, 3 -> w)来生成最终的向量。如果不指定,则默认为 0。
- return:
收集的纹素。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureGather.xhtml
vec_type dFdx(vec_type p) 🔗
备注
仅在片段着色器中可用。
使用局部差分法,返回
p相对于窗口 x 坐标的偏导数。返回 dFdxCoarse 或 dFdxFine 中的一个。具体的实现可能会根据性能表现,或者 API 中
GL_FRAGMENT_SHADER_DERIVATIVE_HINT提示的值等因素,来自主选择执行哪一种计算。警告
像
dFdx(dFdx(n))这样隐含高阶导数的表达式,其结果是未定义的;像dFdx(dFdy(n))这样的混合阶导数也是如此。
- 参数 p:
需要求偏导数的表达式。
备注
这里默认表达式
p是连续的,因此通过非统一控制流(non-uniform control flow)计算得出的表达式,其结果可能是未定义的。- return:
p的偏导数。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/dFdx.xhtml
vec_type dFdxCoarse(vec_type p) 🔗
备注
仅在片段着色器(fragment shader)中可用。在使用兼容性渲染器(Compatibility renderer)时不可用。
返回
p相对于窗口 x 坐标的偏导数。它基于当前片段(fragment)相邻像素的
p值,使用局部差分来计算导数。这个计算过程可能会、但不一定会包含当前片段自身的值。也就是说,在一个给定的区域内,其具体的实现方式可能会比相应的 dFdxFine 函数,在更少的唯一位置上计算导数。警告
像
dFdx(dFdx(n))这样隐含高阶导数的表达式,其结果是未定义的;像dFdx(dFdy(n))这样的混合阶导数也是如此。
- 参数 p:
需要求偏导数的表达式。
备注
这里默认表达式
p是连续的,因此通过非统一控制流(non-uniform control flow)计算得出的表达式,其结果可能是未定义的。- return:
p的偏导数。https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
vec_type dFdxFine(vec_type p) 🔗
备注
仅在片段着色器(fragment shader)中可用。在使用兼容性渲染器(Compatibility renderer)时不可用。
返回
p相对于窗口 x 坐标的偏导数。它基于当前片段(fragment)及其紧邻像素的
p值,使用局部差分法来计算导数。警告
像
dFdx(dFdx(n))这样隐含高阶导数的表达式,其结果是未定义的;像dFdx(dFdy(n))这样的混合阶导数也是如此。
- 参数 p:
需要求偏导数的表达式。
备注
这里默认表达式
p是连续的,因此通过非统一控制流(non-uniform control flow)计算得出的表达式,其结果可能是未定义的。- return:
p的偏导数。https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
vec_type dFdy(vec_type p) 🔗
备注
仅在片段着色器中可用。
使用局部差分法,返回
p相对于窗口 y 坐标的偏导数。返回 dFdyCoarse 或 dFdyFine 中的一个。具体的实现可能会根据性能表现,或者 API 中
GL_FRAGMENT_SHADER_DERIVATIVE_HINT提示的值等因素,来自主选择执行哪一种计算。警告
像
dFdx(dFdx(n))这样隐含高阶导数的表达式,其结果是未定义的;像dFdx(dFdy(n))这样的混合阶导数也是如此。
- 参数 p:
需要求偏导数的表达式。
备注
这里默认表达式
p是连续的,因此通过非统一控制流(non-uniform control flow)计算得出的表达式,其结果可能是未定义的。- return:
p的偏导数。https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
vec_type dFdyCoarse(vec_type p) 🔗
备注
仅在片段着色器(fragment shader)中可用。在使用兼容性渲染器(Compatibility renderer)时不可用。
返回
p相对于窗口 y 坐标的偏导数。它基于当前片段(fragment)相邻像素的
p值,使用局部差分来计算导数。这个计算过程可能会、但不一定会包含当前片段自身的值。也就是说,在一个给定的区域内,其具体的实现方式可能会比相应的 dFdxFine 和 dFdyFine 函数,在更少的唯一位置上计算导数。警告
像
dFdx(dFdx(n))这样隐含高阶导数的表达式,其结果是未定义的;像dFdx(dFdy(n))这样的混合阶导数也是如此。
- 参数 p:
需要求偏导数的表达式。
备注
这里默认表达式
p是连续的,因此通过非统一控制流(non-uniform control flow)计算得出的表达式,其结果可能是未定义的。- return:
p的偏导数。https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
vec_type dFdyFine(vec_type p) 🔗
备注
仅在片段着色器(fragment shader)中可用。在使用兼容性渲染器(Compatibility renderer)时不可用。
返回
p相对于窗口 y 坐标的偏导数。它基于当前片段(fragment)及其紧邻像素的
p值,使用局部差分法来计算导数。警告
像
dFdx(dFdx(n))这样隐含高阶导数的表达式,其结果是未定义的;像dFdx(dFdy(n))这样的混合阶导数也是如此。
- 参数 p:
需要求偏导数的表达式。
备注
这里默认表达式
p是连续的,因此通过非统一控制流(non-uniform control flow)计算得出的表达式,其结果可能是未定义的。- return:
p的偏导数。https://registry.khronos.org/OpenGL-Refpages/gl4/html/dFdx.xhtml
vec_type fwidth(vec_type p) 🔗
返回 x 和 y 方向上的导数绝对值之和。
对输入参数
p使用局部差分。等价于
abs(dFdx(p)) + abs(dFdy(p))。
- 参数 p:
需要求偏导数的表达式。
- return:
偏导数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fwidth.xhtml
vec_type fwidthCoarse(vec_type p) 🔗
备注
仅在片段着色器(fragment shader)中可用。在使用兼容性渲染器(Compatibility renderer)时不可用。
返回 x 和 y 方向上的导数绝对值之和。
对输入参数 p 使用局部差分。
等价于
abs(dFdxCoarse(p)) + abs(dFdyCoarse(p))。
- 参数 p:
需要求偏导数的表达式。
- return:
偏导数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fwidth.xhtml
vec_type fwidthFine(vec_type p) 🔗
备注
仅在片段着色器(fragment shader)中可用。在使用兼容性渲染器(Compatibility renderer)时不可用。
返回 x 和 y 方向上的导数绝对值之和。
对输入参数 p 使用局部差分。
等价于
abs(dFdxFine(p)) + abs(dFdyFine(p))。
- 参数 p:
需要求偏导数的表达式。
- return:
偏导数。
https://registry.khronos.org/OpenGL-Refpages/gl4/html/fwidth.xhtml
封包解包函数
这些函数会将浮点数转换成各种尺寸的整数,然后将这些整数打包进一个单独的 32 位无符号整数中。而 'unpack' (解包)函数则执行相反的操作,负责还原出最初的浮点数。
uint
vec2
|
packHalf2x16(vec2 v)
unpackHalf2x16(uint v)
|
将两个 32 位浮点数转换为 16 位浮点数,并将它们打包在一起。 |
uint
vec2
|
packUnorm2x16(vec2 v)
unpackUnorm2x16(uint v)
|
将两个归一化(范围为 0 到 1)的 32 位浮点数,转换为 16 位无符号整数,并将它们打包在一起。 |
uint
vec2
|
packSnorm2x16(vec2 v)
unpackSnorm2x16(uint v)
|
将两个有符号归一化(范围为 -1 到 1)的 32 位浮点数,转换为 16 位有符号整数,并将它们打包在一起。 |
uint
vec4
|
packUnorm4x8(vec4 v)
unpackUnorm4x8(uint v)
|
将四个归一化(范围为 0 到 1)的 32 位浮点数,转换为 8 位无符号整数,并将它们打包在一起。 |
uint
vec4
|
packSnorm4x8(vec4 v)
unpackSnorm4x8(uint v)
|
将四个有符号归一化(范围为 -1 到 1)的 32 位浮点数,转换为 8 位有符号整数,并将它们打包在一起。 |
打包和解包函数说明
uint packHalf2x16(vec2 v) 🔗
将两个 32 位浮点数转换为 16 位浮点数,并将它们打包进一个单独的 32 位整数中。
该函数返回一个无符号整数。它是通过将二维浮点向量的各个分量转换为 OpenGL 规范中定义的 16 位浮点表示形式,然后将这两个 16 位整数打包到一个 32 位无符号整数中而得到的。向量的第一个分量对应结果中最低有效位的 16 位;第二个分量对应最高有效位的 16 位。
- param v:
一个包含两个 32 位浮点值的向量,它们将被转换为 16 位表示形式并打包到结果中。
- return:
被打包的值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packHalf2x16.xhtml
vec2 unpackHalf2x16(uint v) 🔗
packHalf2x16 的反向操作。
将一个 32 位整数解包为两个 16 位浮点数值,将它们转换为 32 位浮点数值,并将它们放入一个向量中。向量的第一个分量取自
v的 16 个最低有效位;第二个分量取自v的 16 个最高有效位。
- param v:
一个包含 2 个已打包的 16 位浮点值的 32 位无符号整数。
- return:
两个未打包的浮点数值。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackHalf2x16.xhtml
uint packUnorm2x16(vec2 v) 🔗
将浮点数值打包成一个无符号整数。
将归一化浮点数值 v 的每个分量转换为 16 位整数值,然后将结果打包成一个 32 位无符号整数。
向量
v的分量 c 转换为定点数的操作,按如下方式执行:round(clamp(c, 0.0, 1.0) * 65535.0)向量的第一个分量会被写入输出结果的最低有效位;而最后一个分量则会被写入最高有效位。
- param v:
一个将要被打包成无符号整数的数值向量。
- return:
个包含该向量打包编码的 32 位无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
vec2 unpackUnorm2x16(uint v) 🔗
从无符号整数中解包出浮点数值。
将单个 32 位无符号整数解包为一对 16 位无符号整数。然后,将每个分量转换为归一化的浮点数值,从而生成最终返回的二分量向量。
将解包后的定点数值 f 转换为浮点数的操作,按如下方式执行:
f / 65535.0
返回向量的第一个分量将从输入的最低有效位中提取;最后一个分量将从最高有效位中提取。
- param v:
一个包含已打包浮点数值的无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
uint packSnorm2x16(vec2 v) 🔗
将浮点数值打包成一个无符号整数。
将归一化浮点数值
v的每个分量转换为 16 位整数值,然后将结果打包成一个 32 位无符号整数。向量
v的分量 c 转换为定点数的操作,按如下方式执行:round(clamp(c, -1.0, 1.0) * 32767.0)向量的第一个分量会被写入输出结果的最低有效位;而最后一个分量则会被写入最高有效位。
- param v:
一个将要被打包成无符号整数的数值向量。
- return:
个包含该向量打包编码的 32 位无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
vec2 unpackSnorm2x16(uint v) 🔗
从无符号整数中解包浮点数值。
将单个 32 位无符号整数解包为一对 16 位有符号整数。然后,将每个分量转换为归一化的浮点数值,从而生成最终返回的二分量向量。
将解包后的定点数值 f 转换为浮点数的操作,按如下方式执行:
clamp(f / 32727.0, -1.0, 1.0)
返回向量的第一个分量将从输入的最低有效位中提取;最后一个分量将从最高有效位中提取。
- param v:
一个包含已打包浮点数值的无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
uint packUnorm4x8(vec4 v) 🔗
将浮点数值打包成一个无符号整数。
将归一化浮点数值
v的每个分量转换为 16 位整数值,然后将结果打包成一个 32 位无符号整数。向量
v的分量 c 转换为定点数的操作,按如下方式执行:round(clamp(c, 0.0, 1.0) * 255.0)向量的第一个分量会被写入输出结果的最低有效位;而最后一个分量则会被写入最高有效位。
- param v:
一个将要被打包成无符号整数的数值向量。
- return:
个包含该向量打包编码的 32 位无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
vec4 unpackUnorm4x8(uint v) 🔗
从无符号整数中解包浮点数值。
将单个 32 位无符号整数解包为四个 8 位无符号整数。然后,将每个分量转换为归一化的浮点数值,从而生成最终返回的四分量向量。
将解包后的定点数值 f 转换为浮点数的操作,按如下方式执行:
f / 255.0
返回向量的第一个分量将从输入的最低有效位中提取;最后一个分量将从最高有效位中提取。
- param v:
一个包含已打包浮点数值的无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
uint packSnorm4x8(vec4 v) 🔗
将浮点数值打包成一个无符号整数。
将归一化浮点数值
v的每个分量转换为 16 位整数值,然后将结果打包成一个 32 位无符号整数。向量
v的分量 c 转换为定点数的操作,按如下方式执行:round(clamp(c, -1.0, 1.0) * 127.0)向量的第一个分量会被写入输出结果的最低有效位;而最后一个分量则会被写入最高有效位。
- param v:
一个将要被打包成无符号整数的数值向量。
- return:
个包含该向量打包编码的 32 位无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/packUnorm.xhtml
vec4 unpackSnorm4x8(uint v) 🔗
从无符号整数中解包出浮点数值。
将单个 32 位无符号整数解包为四个 8 位有符号整数。然后,将每个分量转换为归一化的浮点数值,从而生成最终返回的四分量向量。
将解包后的定点数值 f 转换为浮点数的操作,按如下方式执行:
clamp(f / 127.0, -1.0, 1.0)
返回向量的第一个分量将从输入的最低有效位中提取;最后一个分量将从最高有效位中提取。
- param v:
一个包含已打包浮点数值的无符号整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/unpackUnorm.xhtml
位运算函数
vec_int_type
vec_uint_type
|
bitfieldExtract(vec_int_type value, int offset, int bits)
bitfieldExtract(vec_uint_type value, int offset, int bits)
|
提取整数的某一范围中的比特位。 |
vec_int_type
vec_uint_type
|
bitfieldInsert(vec_int_type base, vec_int_type insert, int offset, int bits)
bitfieldInsert(vec_uint_type base, vec_uint_type insert, int offset, int bits)
|
将比特位插入到整数的某一范围中。 |
vec_int_type
vec_uint_type
|
bitfieldReverse(vec_int_type value)
bitfieldReverse(vec_uint_type value)
|
将整数的比特位顺序反转。 |
vec_int_type
vec_uint_type
|
计算整数中为 1 的比特位的数量。 |
|
vec_int_type
vec_uint_type
|
找出整数中为 1 的最低有效比特位的索引。 |
|
vec_int_type
vec_uint_type
|
找出整数中为 1 的最高有效比特位的索引。 |
|
void
void
|
imulExtended(vec_int_type x, vec_int_type y, out vec_int_type msb, out vec_int_type lsb)
umulExtended(vec_uint_type x, vec_uint_type y, out vec_uint_type msb, out vec_uint_type lsb)
|
将两个 32 位数字相乘,并产生一个 64 位的结果。 |
vec_uint_type |
uaddCarry(vec_uint_type x, vec_uint_type y, out vec_uint_type carry) |
将两个无符号整数相加,能够产生进位。 |
vec_uint_type |
usubBorrow(vec_uint_type x, vec_uint_type y, out vec_uint_type borrow) |
将两个无符号整数相减,能够产生借位。 |
vec_type |
ldexp(vec_type x, out vec_int_type exp) |
根据值和指数构成浮点数。 |
vec_type |
frexp(vec_type x, out vec_int_type exp) |
将浮点数( |
位运算函数说明
vec_int_type bitfieldExtract(vec_int_type value, int offset, int bits) 🔗
从
value(数值)中提取一部分位的子集,并将其放置在结果值的最低有效位中返回。被提取的位范围是[offset, offset + bits - 1]。结果的最高有效位将被设为零。
备注
如果 bits(位数)为零,结果将为零。
警告
在以下情况下,结果将是未定义的:
offset(偏移量)或 bits(位数)是负数。
如果 offset(偏移量)和 bits(位数)的总和,超过了用于存储该操作数的位数。
- 参数 value:
要从中提取位的整数。
- 参数 offset:
要提取的第一个位的索引。
- 参数 bits:
要提取的比特数。
- return:
带有请求位的整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldExtract.xhtml
vec_uint_type bitfieldExtract(vec_uint_type value, int offset, int bits) 🔗
从
value(数值)中提取一部分位的子集,并将其放置在结果值的最低有效位中返回。被提取的位范围是[offset, offset + bits - 1]。最高有效位将被设置为
offset + base - 1的值(也就是说,它会被符号扩展至返回类型的宽度)。备注
如果 bits(位数)为零,结果将为零。
警告
在以下情况下,结果将是未定义的:
offset(偏移量)或 bits(位数)是负数。
如果 offset(偏移量)和 bits(位数)的总和,超过了用于存储该操作数的位数。
- 参数 value:
要从中提取位的整数。
- 参数 offset:
要提取的第一个位的索引。
- 参数 bits:
要提取的比特数。
- return:
带有请求位的整数。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldExtract.xhtml
vec_uint_type bitfieldExtract(vec_uint_type value, int offset, int bits) 🔗
vec_uint_type bitfieldInsert(vec_uint_type base, vec_uint_type insert, int offset, int bits) 🔗
将
insert的最低bits位,插入到base的offset偏移处。返回的值中,[offset, offset + bits - 1] 范围内的位将取自
insert的 [0, bits - 1] 位,而所有其他位则直接从 base 的对应位中获取。备注
如果 bits 为零,结果将是 base 的原始值。
警告
在以下情况下,结果将是未定义的:
offset(偏移量)或 bits(位数)是负数。
如果 offset(偏移量)和 bits(位数)的总和,超过了用于存储该操作数的位数。
- 参数 base:
要将
insert插入进去的那个整数。- 参数 insert:
要插入的位的值。
- 参数 offset:
要插入的第一个位的索引(位置)。
- 参数 bits:
要插入的位的数量。
- return:
插入了指定位后的
base值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldInsert.xhtml
vec_int_type bitfieldReverse(vec_int_type value) 🔗
vec_uint_type bitfieldReverse(vec_uint_type value) 🔗
将整数的比特位顺序反转。
编号为
n的位,将会取自value的第(bits - 1) - n位,其中 bits 是表示value所使用的总位数。
- 参数 value:
要反转其位的数值。
- return:
value的位反转后的结果。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitfieldReverse.xhtml
vec_int_type bitCount(vec_int_type value) 🔗
vec_uint_type bitCount(vec_uint_type value) 🔗
计算整数中为 1 的比特位的数量。
- 参数 value:
要统计其位的数值。
- return:
在
value的二进制表示中,被置为 1 的位的数量。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/bitCount.xhtml
vec_int_type findLSB(vec_int_type value) 🔗
vec_uint_type findLSB(vec_uint_type value) 🔗
查找被置为
1的最低有效位的索引。备注
如果
value为零,则返回-1。
- 参数 value:
要扫描其位的值。
- return:
在 value 的二进制表示中,被置为 1 的最低有效位的位编号。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/findLSB.xhtml
vec_int_type findMSB(vec_int_type value) 🔗
vec_uint_type findMSB(vec_uint_type value) 🔗
查找被置为 1 的最高有效位的索引。
备注
- 对于有符号整数类型,会先检查符号位,然后:
对于正整数,结果将是被置为 1 的最高有效位的位编号。
对于负整数,结果将是被置为 0 的最高有效位的位编号。
备注
如果值为 0 或负 1,则返回 -1。
- 参数 value:
要扫描其位的值。
- return:
在 value 的二进制表示中,被置为 1 的最高有效位的位编号。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/findMSB.xhtml
void imulExtended(vec_int_type x, vec_int_type y, out vec_int_type msb, out vec_int_type lsb) 🔗
执行 32 位乘以 32 位的有符号乘法,并生成一个 64 位的结果。
该乘积的低 32 位(最低有效位)将返回到
lsb中,而高 32 位(最高有效位)将返回到msb中。
- 参数:x:
第一个乘数。
- 参数 y:
第二个乘数。
- 参数 msb:
用于接收乘积最高有效字的变量。
- 参数 lsb:
用于接收乘积最低有效字的变量。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/umulExtended.xhtml
void umulExtended(vec_uint_type x, vec_uint_type y, out vec_uint_type msb, out vec_uint_type lsb) 🔗
执行 32 位乘以 32 位的无符号乘法,并生成一个 64 位的结果。
该乘积的低 32 位(最低有效位)将返回到
lsb中,而高 32 位(最高有效位)将返回到msb中。
- 参数:x:
第一个乘数。
- 参数 y:
第二个乘数。
- 参数 msb:
用于接收乘积最高有效字的变量。
- 参数 lsb:
用于接收乘积最低有效字的变量。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/umulExtended.xhtml
vec_uint_type uaddCarry(vec_uint_type x, vec_uint_type y, out vec_uint_type carry) 🔗
对无符号整数进行加法运算,并产生进位。
将两个 32 位无符号整数变量(标量或向量)相加,并生成一个 32 位无符号整数结果,同时输出进位值。其进位值为 。
- 参数:x:
第一个操作数。
- 参数 y:
第二个操作数。
- 参数进位(Carry):
如果总和小于 232,结果为 0;否则结果为 1。
- return:
(x + y) % 2^32。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/uaddCarry.xhtml
vec_uint_type usubBorrow(vec_uint_type x, vec_uint_type y, out vec_uint_type borrow) 🔗
对无符号整数进行减法运算,并产生借位。
- 参数:x:
第一个操作数。
- 参数 y:
第二个操作数。
- param borrow:
如果
x >= y则为0,否则为1。- return:
如果
x和y的差值是非负数,就取这个差值;否则(如果是负数),就取 232 加上这个差值。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/usubBorrow.xhtml
vec_type ldexp(vec_type x, out vec_int_type exp) 🔗
将一个数值和一个指数组装成一个浮点数。
警告
如果这个乘积太大,超出了该浮点数类型能表示的范围,那么结果将是未定义的。
- 参数:x:
用作尾数来源的那个数值。
- 参数 exp:
用作指数来源的那个数值。
- return:
x * 2^exphttps://www.khronos.org/registry/OpenGL-Refpages/gl4/html/ldexp.xhtml
vec_type frexp(vec_type x, out vec_int_type exp) 🔗
将
x拆分为一个范围在[0.5, 1.0)之间的浮点尾数,以及一个以 2 为底的整数指数,并且满足以下关系:x = significand * 2 ^ exponent对于值为零的浮点数,它的尾数和指数都为零。
警告
如果浮点数值是无穷大(infinity)或者非数(NaN),那么结果将是未定义的。
- 参数:x:
需要从中提取 尾数 和 指数 的那个数值。
- 参数 exp:
用来存放
x的指数的变量。- return:
x的尾数。https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/frexp.xhtml