您的位置:首页 > 其它

高级着色语言HLSL入门(7)

2010-10-15 11:28 253 查看

高级着色语言HLSL入门(7)

max (Direct3D 9 HLSL)

Selects the greater of x and y.

Syntax

ret max(x, y)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloat, intany
yinsame as input xfloat, intsame dimension(s) as input x
retreturn typesame as input xfloat, intsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_1_4

min (Direct3D 9 HLSL)

Selects the lesser of x and y.

Syntax

ret min(x, y)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloat, intany
yinsame as input xfloat, intsame dimension(s) as input x
retreturn typesame as input xfloat, intsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_1_4

mul (Direct3D 9 HLSL)

Performs matrix multiplication between x and y. If x is a vector, it treated as a row vector. If y is a vector, it is treated as a column vector. The inner dimension x-columns and y-rows must be equal. The result has the dimension x-rows x y-columns.

Syntax

ret mul(x, y)
There are 9 overloaded versions of this function, to handle the different cases for the types and sizes of the x and y input arguments. The following table lists these versions.

VersionNamePurposeTemplate TypeComponent TypeSize
1
xinscalarfloat, int1
yinscalarsame as input x1
retoutscalarsame as input x1
2
xinscalarfloat, int1
yinvectorfloat, intany
retoutvectorfloat, intsame dimension(s) as input y
3
xinscalarfloat, int1
yinmatrixfloat, intany
retoutmatrixsame as input ysame dimension(s) as input y
4
xinvectorfloat, intany
yinscalarfloat, int1
retoutvectorfloat, intsame dimension(s) as input x
5
xinvectorfloat, intany
yinvectorfloat, intsame dimension(s) as input x
retoutscalarfloat, int1
6
xinvectorfloat, intany
yinmatrixfloat, introws = same dimension(s) as input x, columns = any
retoutvectorfloat, intsame dimension(s) as input y columns
7
xinmatrixfloat, intany
yinscalarfloat, int1
retoutmatrixfloat, intsame dimension(s) as input x
8
xinmatrixfloat, intany
yinvectorfloat, intnumber of columns in input x
retoutvectorfloat, intnumber of rows in input x
9
xinmatrixfloat, intany
yinmatrixfloat, introws = number of columns in input x
retoutmatrixfloat, introws = number of rows in input x, columns = number of columns in input y

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_1_1

normalize (Direct3D 9 HLSL)

Returns the normalized vector x / length(x). If the length of x is 0, the result is indefinite.

Syntax

ret normalize(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinvectorfloatany
retoutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

pow (Direct3D 9 HLSL)

Returns xy.

Syntax

ret pow(x, y)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
yinsame as input xfloatsame dimension(s) as input x
retoutsame as input xfloatsame dimension(s) as input x

Remarks

Special cases:

If x = 0, then the result will always be 0.

If x < 0, there will be a compile error.

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

radians (Direct3D 9 HLSL)

Converts x from degrees to radians.

Syntax

ret radians(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
retoutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_1_1

reflect (Direct3D 9 HLSL)

Returns the reflection vector v, given the entering ray direction i, and the surface normal n, as in:

v = i - 2 * dot(i, n) * n

Syntax

ret reflect(i, n)
Where:

NameIn/OutTemplate TypeComponent TypeSize
iinvectorfloatany
ninvectorfloatsame dimension(s) as input i
retoutvectorfloatsame dimension(s) as input i

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_1_1

refract (Direct3D 9 HLSL)

Returns the refraction vector given the entering ray direction i, the surface normal n, and the refraction index ri. If the angle between i and n is too great for a given eta, refract returns (0,0,0).

Syntax

ret refract(i, n, ri)
Where:

NameIn/OutTemplate TypeComponent TypeSize
iinvectorfloatany
ninvectorfloatsame dimension(s) as input i
riinscalarfloat1
refraction vectoroutvectorfloatsame dimension(s) as input i

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

rsqrt (Direct3D 9 HLSL)

Returns 1 / sqrt(x).

Syntax

ret rsqrt(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
retoutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

saturate (Direct3D 9 HLSL)

Clamps x to the range [0, 1].

Syntax

ret saturate(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
retoutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_1_1

sin (Direct3D 9 HLSL)

Returns the sine of x.

Syntax

ret sin(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
retoutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

sincos (Direct3D 9 HLSL)

Returns the sine and cosine of x. sin(x) is stored in the output parameter s. cos(x) is stored in the output parameter c.

Syntax

sincos(x, out s, out c)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
soutsame as input xfloatsame dimension(s) as input x
coutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

sqrt (Direct3D 9 HLSL)

Square root (per component).

Syntax

ret sqrt(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
retoutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

tan (Direct3D 9 HLSL)

Returns the tangent of x.

Syntax

ret tan(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinscalar, vector, or matrixfloatany
retoutsame as input xfloatsame dimension(s) as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_2_0

transpose (Direct3D 9 HLSL)

Returns the transpose of the input matrix x. If the dimensions of the source matrix is p-rows x q-columns, the resulting matrix is q-columns x p-rows.

Syntax

ret transpose(x)
Where:

NameIn/OutTemplate TypeComponent TypeSize
xinmatrixfloat, int, boolany
retoutmatrixfloat, int, boolrows = same number of columns as input x, columns = same number of rows as input x

Minimum Shader Version

This intrinsic function is supported in the following (or above) shader versions:

Vertex ShaderPixel Shader
vs_1_1ps_1_1
大多数函数已经重载以使其可以对所有内建类型有意义。例如,abs对所有数值类型有意义,所以它为所有这些数值类型进行了重载。又例如,叉积的叉乘仅对3D向量有意义,所以它对所有类型的3D向量(比如:int,float,double的3D向量)进行了重载。另一方面,线性插值——lerp,对于数值、2D、3D和4D向量有意义,因此重载了这些类型。

注意:如果你传递进去一个非数值类型到一个(要求)数值类型的函数,也就是一个仅能对数值类型进行操作的函数(比如:cos(x)),那么这个函数会对传进去的每个分量进行操作。例如,你写:

floats v = float3 (0.0f, 0.0f, 0.0f);

v = cos(v);

那么函数将会对每个分量进行操作:v=(cos(x),cos(y),cos(z))。

下例展示了这些固有的函数可能被调用的方式:

float x = sin(1.0f); // sine of 1.0f radian.

float y = sqrt(4.0f); // square root of 4.



vector u = {1.0f, 2.0f, -3.0f, 0.0f};

vector v = {3.0f, -1.0f, 0.0f, 2.0f};

float s = dot(u, v); // compute dot product of u and v.



float3 i = {1.0f, 0.0f, 0.0f};

float3 j = {0.0f, 1.0f, 0.0f};

float3 k = cross(i, j); // compute cross product of i and j.



matrix<float, 2, 2> M = {1.0f, 2.0f, 3.0f, 4.0f};

matrix<float, 2, 2> T = transpose(M); // compute transpose

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: