zoukankan      html  css  js  c++  java
  • 高级着色语言HLSL入门(7)

    max (Direct3D 9 HLSL)

    Selects the greater of x and y.

    Syntax

    ret max(x, y)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float, int any
    y in same as input x float, int same dimension(s) as input x
    ret return type same as input x float, int same 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_1 ps_1_4

    min (Direct3D 9 HLSL)

    Selects the lesser of x and y.

    Syntax

    ret min(x, y)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float, int any
    y in same as input x float, int same dimension(s) as input x
    ret return type same as input x float, int same 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_1 ps_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     
      x in scalar float, int 1
      y in scalar same as input x 1
      ret out scalar same as input x 1
    2     
      x in scalar float, int 1
      y in vector float, int any
      ret out vector float, int same dimension(s) as input y
    3     
      x in scalar float, int 1
      y in matrix float, int any
      ret out matrix same as input y same dimension(s) as input y
    4     
      x in vector float, int any
      y in scalar float, int 1
      ret out vector float, int same dimension(s) as input x
    5     
      x in vector float, int any
      y in vector float, int same dimension(s) as input x
      ret out scalar float, int 1
    6     
      x in vector float, int any
      y in matrix float, int rows = same dimension(s) as input x, columns = any
      ret out vector float, int same dimension(s) as input y columns
    7     
      x in matrix float, int any
      y in scalar float, int 1
      ret out matrix float, int same dimension(s) as input x
    8     
      x in matrix float, int any
      y in vector float, int number of columns in input x
      ret out vector float, int number of rows in input x
    9     
      x in matrix float, int any
      y in matrix float, int rows = number of columns in input x
      ret out matrix float, int rows = 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_1 ps_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
    x in vector float any
    ret out same as input x float same 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_1 ps_2_0

    pow (Direct3D 9 HLSL)

    Returns xy.

    Syntax

    ret pow(x, y)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float any
    y in same as input x float same dimension(s) as input x
    ret out same as input x float same 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_1 ps_2_0

    radians (Direct3D 9 HLSL)

    Converts x from degrees to radians.

    Syntax

    ret radians(x)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float any
    ret out same as input x float same 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_1 ps_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
    i in vector float any
    n in vector float same dimension(s) as input i
    ret out vector float same 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_1 ps_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
    i in vector float any
    n in vector float same dimension(s) as input i
    ri in scalar float 1
    refraction vector out vector float same 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_1 ps_2_0

    rsqrt (Direct3D 9 HLSL)

    Returns 1 / sqrt(x).

    Syntax

    ret rsqrt(x)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float any
    ret out same as input x float same 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_1 ps_2_0

    saturate (Direct3D 9 HLSL)

    Clamps x to the range [0, 1].

    Syntax

    ret saturate(x)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float any
    ret out same as input x float same 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_1 ps_1_1

    sin (Direct3D 9 HLSL)

    Returns the sine of x.

    Syntax

    ret sin(x)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float any
    ret out same as input x float same 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_1 ps_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
    x in scalar, vector, or matrix float any
    s out same as input x float same dimension(s) as input x
    c out same as input x float same 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_1 ps_2_0

    sqrt (Direct3D 9 HLSL)

    Square root (per component).

    Syntax

    ret sqrt(x)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float any
    ret out same as input x float same 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_1 ps_2_0

    tan (Direct3D 9 HLSL)

    Returns the tangent of x.

    Syntax

    ret tan(x)

    Where:

    NameIn/OutTemplate TypeComponent TypeSize
    x in scalar, vector, or matrix float any
    ret out same as input x float same 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_1 ps_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
    x in matrix float, int, bool any
    ret out matrix float, int, bool rows = 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_1 ps_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

  • 相关阅读:
    学习CSS定位(布局)
    XSLT
    CSS模型框学习笔记
    XMLDOM复习
    XMLDOM之浏览器差异
    HTMLDOM入门
    学习二级纵向菜单两步走
    Xpath很全的学习地点,不看后悔
    LinQ To XML
    收集的一些零散代码
  • 原文地址:https://www.cnblogs.com/8586/p/1401979.html
Copyright © 2011-2022 走看看