6.15.4. Common Functions
6.15.4. 常用函数
The following table describes the list of built-in common functions. These all operate component-wise. The description is per-component.
下表描述了内置常用函数的列表。这些都是按分量操作的。描述是针对每个分量的。
The generic type name gentype
indicates that the function can take any of
泛型类型名称gentype表示该函数可以采用以下任何类型
-
float
,float2
,float3
,float4
,float8
, orfloat16
-
double
[39],double2
,double3
,double4
,double8
ordouble16
-
half
[48],half2
,half3
,half4
,half8
orhalf16
as the type for the arguments.
作为参数的类型。
The generic type name gentypef
indicates that the function can take any of
泛型类型名称gentypef表示该函数可以接受以下任何类型
-
float
,float2
,float3
,float4
,float8
, orfloat16
as the type for the arguments.
作为参数的类型。
The generic type name gentyped
[49] indicates that the function can take any of
泛型类型名称gentyped[49]表示该函数可以采用以下任何一种
-
double
,double2
,double3
,double4
,double8
ordouble16
as the type for the arguments.
作为参数的类型。
The generic type name gentypeh
[50] indicates that the function can take any of
泛型类型名称gentypeh[50]表示该函数可以采用以下任何一种
-
half
,half2
,half3
,half4
,half8
orhalf16
as the type for the arguments.
作为参数的类型。
All functions taking or returning 仅当支持cl_khr_fp16扩展宏时,才支持所有接受或返回 |
Function 函数 | Description 描述 | ||
---|---|---|---|
gentype clamp(gentype x, gentype minval, gentype maxval) gentypeh clamp(gentypeh x, half minval, half maxval) | Returns fmin(fmax(x, minval), maxval). Results are undefined if minval > maxval. 返回fmin(fmax(x,minval),maxval)。如果minval>maxval,则结果未定义。 | ||
gentype degrees(gentype radians) | Converts radians to degrees, i.e. (180 / π) * radians. 将弧度转换为角度数,即(180/π)*弧度。 | ||
gentype max(gentype x, gentype y) gentypeh max(gentypeh x, half y) | Returns y if x < y, otherwise it returns x. If x or y are infinite or NaN, the return values are undefined. 如果x<y,则返回y,否则返回x。如果x或y为无穷大或NaN,则返回值未定义。 | ||
gentype min(gentype x, gentype y) gentypeh min(gentypeh x, half y) | Returns y if y < x, otherwise it returns x. If x or y are infinite or NaN, the return values are undefined. 如果y<x,则返回y,否则返回x。如果x或y为无穷大或NaN,则返回值未定义。 | ||
gentype mix(gentype x, gentype y, gentype a) gentypeh mix(gentypeh x, gentypeh y, half a) | Returns the linear blend of x and y implemented as: 返回x和y的线性混合,实现为: _x_ + (_y_ - _x_) * _a_ _a_ must be a value in the range [0.0, 1.0]. If _a_ is not in the range [0.0, 1.0], the return values are undefined. _a_必须是[0.0,1.0]范围内的值。
| ||
gentype radians(gentype degrees) | Converts degrees to radians, i.e. (π / 180) * degrees. 将角度数转换为弧度,即(π/180)*度。 | ||
gentype step(gentype edge, gentype x) gentypeh step(half edge, gentypeh x) | Returns 0.0 if x < edge, otherwise it returns 1.0. 如果x<edge,则返回0.0,否则返回1.0。 | ||
gentype smoothstep(gentype edge0, gentype edge1, gentype x) gentypeh smoothstep(half edge0, half edge1, gentypeh x) | Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where you would want a threshold function with a smooth transition. 如果x<=edge0,则返回0.0;如果x>=edge1,则返回1.0;当edge0<x<edge1时,在0和1之间执行平滑的Hermite插值。这在需要平滑过渡的阈值函数的情况下非常有用。 This is equivalent to: 这相当于: Results are undefined if edge0 >= edge1 or if x, edge0 or edge1 is a NaN. 如果edge0>=edge1,或者x、edge0或edge1是NaN,则结果未定义。
| ||
gentype sign(gentype x) | Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if x < 0. Returns 0.0 if x is a NaN. 如果x>0,返回1.0;如果x=-0.0,返回-0.0;如果x=+0.0,返回+0.0;如果x<0,返回-1.0。如果x是NaN,则返回0.0。 |