HLSL
+ -

6.7着色器内部函数大全

2024-06-26 7 0

HLSL(High Level Shading Language)是一种用于编写着色器程序的语言,它包含许多内置函数可以用于实现各种图形效果。以下是一些常见的内置函数类型:

  1. 数学函数:

    • abs(): 返回输入值的绝对值。
    • sin()/cos(): 计算输入值的正弦值/余弦值。
    • sqrt(): 返回输入值的平方根。
    • pow(): 计算指定底数和指数的幂值。
    • ceil()/floor(): 返回不小于/不大于输入值的最小整数值。
  2. 向量操作函数:

    • normalize(): 将输入向量归一化为单位长度。
    • dot(): 计算两个向量的点积。
    • cross(): 计算两个三维向量的叉积。
  3. 颜色操作函数:

    • saturate(): 将输入值限制在[0, 1]范围内。
    • lerp(): 在两个值之间进行线性插值。
    • rgba(): 返回包含指定RGB颜色和alpha值的颜色向量。
  4. 纹理采样函数:

    • tex2D()/tex2Dlod(): 根据指定纹理坐标采样2D纹理纹理数据。
    • texCUBE()/texCUBElod(): 根据指定立方体纹理坐标采样立方体纹理数据。
  5. 矩阵操作函数:

    • mul(): 执行矩阵乘法操作。
    • transpose(): 计算输入矩阵的转置矩阵。

这些函数提供了丰富的功能,可以帮助开发人员实现各种复杂的着色器效果。在编写HLSL着色器时,可以根据需求选择合适的内置函数来实现所需的功能。

  1. abs(x) – Returns |x|.
  2. ceil(x) – Returns the smallest integer ≥ x.
  3. cos(x) – Returns the cosine of x, where x is in radians.
  4. clamp(x, a, b) – Clamps x to the range [a, b] and returns the result.
  5. clip(x) – This function can only be called in a pixel shader, and it discards the current pixel from further processing if x < 0.
  6. cross(u, v) – Returns u × v.
  7. ddx(p) – Estimates screen space partial derivative ∂p/∂x. This allows you to determine how per pixel quantities p vary from pixel to pixel in the screen space x-direction.
  8. ddy(p) – Estimates screen space partial derivative ∂p/∂y. This allows you to determine how per pixel quantities p vary from pixel to pixel in the screen space y-direction.
  9. degrees(x) – Converts x from radians to degrees.
  10. determinant(M) – Returns the determinant of a matrix.
  11. distance(u, v) – Returns the distance || v - u || between the points u and v.
  12. dot(u, v) – Returns u v.
  13. floor(x) – Returns the greatest integer ≤ x.
  14. frac(x) – This function returns the fractional part of a floating-point number (i.e., the mantissa). For example, if x = (235.52,
    696.32) and frac(x) = (0.52, 0.32).
  15. length(v) – Returns || v ||.
  16. lerp(u, v, t) – Linearly interpolates between u and v based on the parameter t ∈ [0,1].
  17. log(x) – Returns ln(x).
  18. log10(x) – Returns log10(x).
  19. log2(x) – Returns log2(x).
  20. max(x, y) – Returns x if x ≥ y, else returns y.
  21. min(x, y) – Returns x if x ≥ y, else returns y.
  22. mul(M, N) – Returns the matrix product MN. Note that the matrix product MN must be defined. If M is a vector, it is treated as a row vector so that the vector-matrix product is defined. Likewise, if N is a vector, it is treated as a column vector so that the
    matrix-vector product is defined.
  23. normalize(v) – Returns v/|| v ||.
  24. pow(b, n) – Returns bn.
  25. radians(x) – Converts x from degrees to radians.
  26. saturate(x) – Returns clamp(x, 0.0, 1.0).
  27. sin(x) – Returns the sine of x, where x is in radians.
  28. sincos(in x, out s, out c) – Returns the sine and cosine of x, where x is in radians.
  29. sqrt(x) – Returns .
  30. reflect(v, n) – Computes the reflection vector given the incident vector v and the surface normal n.
  31. refract(v, n, eta) – Computes the refraction vector given the incident vector v, the surface normal n, and the ratio of the two in dices of refraction of the two materials eta.
  32. rsqrt(x) – Returns .
  33. tan(x) – Returns the tangent of x, where x is in radians
  34. transpose(M) – Returns the transpose MT.
  35. Texture2D::Sample(S, texC) – Returns a color from a 2D texture map based on the SamplerState object S, and 2D texturecoordinates texC.
  36. Texture2D::SampleLevel(S, texC, mipLevel) – Returns a color from a 2D texture map based on the SamplerState object S, 2D texture coordinates texC, and mipmap level mipLevel. This function differs from Texture2D::Sample in that the third parameter manually specifies the mipmap level to use. For example, we would specify 0 to access the topmost mipmap LOD.
  37. TextureCube::Sample(S, v) – Returns a color from a cube map based on the SamplerState object S and 3D lookup vector v.
  38. Texture2DArray::Sample(S, texC) – Returns a color from a 2D texture array based on the SamplerState object S (recall a sampler state specifies texture filters and texture address modes) and 3D texture coordinates texC, where the first two coordinates are the usual 2D texture coordinates and the third coordinate specifies the array index.

0 篇笔记 写笔记

作者信息
站长漫谈
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!