《Unity着色器圣经》4.1.9. | Min and Max function.

目录索引

译文

“min”是指两个向量或标量之间的最小值,而“max”则相反。我们将在不同的操作中经常使用这些函数,例如,我们可以在计算漫反射时用到max函数:用来返回“0”和法线与光方向之间的点积之间的最大值。

其语法如下:

// if "a" is less than "b", it returns "a", otherwise returns "b"
float min (float a, float b)
{
    float n = (a < b? a : b);
    return n;
}

float2 min (float2 a, float2 b);
float3 min (float3 a, float3 b);
float4 min (float4 a, float4 b);
// if "a" is greater than "b", it returns "a", otherwise returns "b"
float max (float a, float b)
{
    float n = (a > b? a : b);
    return n;
}

float2 max (float2 a, float2 b);
float3 max (float3 a, float3 b);
float4 max (float4 a, float4 b);

我们将在稍后的第二章第7.0.3节中详细讨论这个函数,讨论漫反射。


原文对照

On the one hand, “min” refers to the minimum value between two vectors or scalars, while the “max” is the opposite. We will use these functions frequently in different operations, e.g., we can use max to calculate the diffusion on an object, returning the maximum between “zero” and the dot product between the normals of the mesh and the direction of the light.


Its syntax is as follows:

// if "a" is less than "b", it returns "a", otherwise returns "b"
float min (float a, float b)
{
    float n = (a < b? a : b);
    return n;
}

float2 min (float2 a, float2 b);
float3 min (float3 a, float3 b);
float4 min (float4 a, float4 b);
// if "a" is greater than "b", it returns "a", otherwise returns "b"
float max (float a, float b)
{
    float n = (a > b? a : b);
    return n;
}

float2 max (float2 a, float2 b);
float3 max (float3 a, float3 b);
float4 max (float4 a, float4 b);

We will review this function in detail later in Chapter II, Section 7.0.3, discussing diffuse reflection.

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

请登录后发表评论

    暂无评论内容