《Unity着色器圣经》4.1.3. | Exp, Exp2 and Pow function.

目录索引

译文

这几个函数的特征是在运算中都用到了指数,例如,函数“exp”返回标量和矢量值中以e为基的指数,也就是说,“e”是用来代替(2.7182828182846f)的。

exp(2) = 7.3890560986f It’s the same as 2.71828182846f²

语法如下所示:

float exp (float n)
{
    float e = 2.71828182846;
    float en = pow (e, n);
    return en;
}

float2 exp (float2 n);
float3 exp (float3 n);
float4 exp (float4 n);
图片[1]-《Unity着色器圣经》4.1.3. | Exp, Exp2 and Pow function.-软件开发学习笔记
(Fig. 4.1.3a. Graphical representation of exp(x) on a Cartesian plane)

此外,“exp2”在不同维度的值中返回以2为基数的指数。

exp2(3) = 8 It’s the same as 2³
exp2(4) = 16
exp2(5) = 32

float exp2 (float n);
float2 exp2 (float2 n);
float3 exp2 (float3 n);
float4 exp2 (float4 n);

另一方面,“pow”有两个参数:基数(x)及其指数(n)。

pow(3, 2) = 9 It’s the same as 3²
pow(2, 2) = 4
pow(4, 2) = 16

float pow (float x, float n);
float2 pow (float2 x, float2 n);
float3 pow (float3 x, float3 n);
float4 pow (float4 x, float4 n);

这些功能的有用性将取决于正在执行的操作。然而,它们通常用于计算噪声、输出颜色中的gamma增加和重复模式。


原文对照

These functions are characterized by using exponents in their operations, e.g., the function “exp” returns the exponential of base-e in scalar and vector values, that is to say, “e” (2.7182828182846f) raised to a number.

exp(2) = 7.3890560986f It’s the same as 2.71828182846f²

Its syntax is as follows:

float exp (float n)
{
    float e = 2.71828182846;
    float en = pow (e, n);
    return en;
}

float2 exp (float2 n);
float3 exp (float3 n);
float4 exp (float4 n);
图片[1]-《Unity着色器圣经》4.1.3. | Exp, Exp2 and Pow function.-软件开发学习笔记
(Fig. 4.1.3a. Graphical representation of exp(x) on a Cartesian plane)

Moreover, “exp2” returns the base-2 exponent in values of different dimensions, that is, two raised to a number.

exp2(3) = 8 It’s the same as 2³
exp2(4) = 16
exp2(5) = 32

float exp2 (float n);
float2 exp2 (float2 n);
float3 exp2 (float3 n);
float4 exp2 (float4 n);

On the other hand, “pow” has two arguments: The base number (x) and its exponent (n).

pow(3, 2) = 9 It’s the same as 3²
pow(2, 2) = 4
pow(4, 2) = 16

float pow (float x, float n);
float2 pow (float2 x, float2 n);
float3 pow (float3 x, float3 n);
float4 pow (float4 x, float4 n);

The usefulness of these functions will depend on the operation being performed. However, they are generally used to calculate noise, gamma increase in the output color, and repetition patterns.

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容