HLSL固有函数 【Intrinsic Functions (DirectX HLSL)】
每天30分钟看Shader--(1)HLSL固有函数 【Intrinsic Functions (DirectX HLSL)】
放在blog上看起来方便,这个是MSDN上的,DirectX Documentation里也有
Intrinsic Functions (DirectX HLSL)
The following table lists the intrinsic functions available in HLSL. Each function has a brief description, and a link to a reference page that has more detail about the input argument and return type.
Name | Syntax | Description |
abs(x) | Absolute value (per component). | |
acos(x) | Returns the arccosine of each component of x. | |
all(x) | Test if all components of x are nonzero. | |
any(x) | Test if any component of x is nonzero. | |
asfloat(x) | Convert the input type to a float. | |
asin(x) | Returns the arcsine of each component of x. | |
asint(x) | Convert the input type to an integer. | |
asuint(x) | Convert the input type to an unsigned integer. | |
atan(x) | Returns the arctangent of x. | |
atan2(y, x) | Returns the arctangent of of two values (x,y). | |
ceil(x) | Returns the smallest integer which is greater than or equal to x. | |
clamp(x, min, max) | Clamps x to the range [min, max]. | |
clip(x) | Discards the current pixel, if any component of x is less than zero. | |
cos(x) | Returns the cosine of x. | |
cosh(x) | Returns the hyperbolic cosine of x. | |
cross(x, y) | Returns the cross product of two 3D vectors. | |
D3DCOLORtoUBYTE4(x) | Swizzles and scales components of the 4D vector x to compensate for the lack of UBYTE4 support in some hardware. | |
ddx(x) | Returns the partial derivative of x with respect to the screen-space x-coordinate. | |
ddy(x) | Returns the partial derivative of x with respect to the screen-space y-coordinate. | |
degrees(x) | Converts x from radians to degrees. | |
determinant(m) | Returns the determinant of the square matrix m. | |
distance(x, y) | Returns the distance between two points. | |
dot(x, y) | Returns the dot product of two vectors. | |
exp(x) | Returns the base-e exponent. | |
exp2(x) | Base 2 exponent (per component). | |
faceforward(n, i, ng) | Returns -n * sign(•(i, ng)). | |
floor(x) | Returns the greatest integer which is less than or equal to x. | |
fmod(x, y) | Returns the floating point remainder of x/y. | |
frac(x) | Returns the fractional part of x. | |
frexp(x, exp) | Returns the mantissa and exponent of x. | |
fwidth(x) | Returns abs(ddx(x)) abs(ddy(x)) | |
GetRenderTargetSampleCount() | Returns the number of render-target samples. | |
GetRenderTargetSamplePosition(x) | Returns a sample position (x,y) for a given sample index. | |
isfinite(x) | Returns true if x is finite, false otherwise. | |
isinf(x) | Returns true if x is INF or -INF, false otherwise. | |
isnan(x) | Returns true if x is NAN or QNAN, false otherwise. | |
ldexp(x, exp) | Returns x * 2exp | |
length(v) | Returns the length of the vector v. | |
lerp(x, y, s) | Returns x s(y - x). | |
lit(n • l, n • h, m) | Returns a lighting vector (ambient, diffuse, specular, 1) | |
log(x) | Returns the base-e logarithm of x. | |
log10(x) | Returns the base-10 logarithm of x. | |
log2(x) | Returns the base-2 logarithm of x. | |
max(x, y) | Selects the greater of x and y. | |
min(x, y) | Selects the lesser of x and y. | |
modf(x, out ip) | Splits the value x into fractional and integer parts. | |
mul(x, y) | Performs matrix multiplication using x and y. | |
noise(x) | Generates a random value using the Perlin-noise algorithm. | |
normalize(x) | Returns a normalized vector. | |
pow(x, y) | Returns xy. | |
radians(x) | Converts x from degrees to radians. | |
reflect(i, n) | Returns a reflection vector. | |
refract(i, n, R) | Returns the refraction vector. | |
round(x) | Rounds x to the nearest integer | |
rsqrt(x) | Returns 1 / sqrt(x) | |
saturate(x) | Clamps x to the range [0, 1] | |
sign(x) | Computes the sign of x. | |
sin(x) | Returns the sine of x | |
sincos(x, out s, out c) | Returns the sine and cosine of x. | |
sinh(x) | Returns the hyperbolic sine of x | |
smoothstep(min, max, x) | Returns a smooth Hermite interpolation between 0 and 1. | |
sqrt(x) | Square root (per component) | |
step(a, x) | Returns (x >= a) ? 1 : 0 | |
tan(x) | Returns the tangent of x | |
tanh(x) | Returns the hyperbolic tangent of x | |
tex1D(s, t) | 1D texture lookup. | |
tex1Dbias(s, t) | 1D texture lookup with bias. | |
tex1Dgrad(s, t, ddx, ddy) | 1D texture lookup with a gradient. | |
tex1Dlod(s, t) | 1D texture lookup with LOD. | |
tex1Dproj(s, t) | 1D texture lookup with projective divide. | |
tex2D(s, t) | 2D texture lookup. | |
tex2Dbias(s, t) | 2D texture lookup with bias. | |
tex2Dgrad(s, t, ddx, ddy) | 2D texture lookup with a gradient. | |
tex2Dlod(s, t) | 2D texture lookup with LOD. | |
tex2Dproj(s, t) | 2D texture lookup with projective divide. | |
tex3D(s, t) | 3D texture lookup. | |
tex3Dbias(s, t) | 3D texture lookup with bias. | |
tex3Dgrad(s, t, ddx, ddy) | 3D texture lookup with a gradient. | |
tex3Dlod(s, t) | 3D texture lookup with LOD. | |
tex3Dproj(s, t) | 3D texture lookup with projective divide. | |
texCUBE(s, t) | Cube texture lookup. | |
texCUBEbias(s, t) | Cube texture lookup with bias. | |
texCUBEgrad(s, t, ddx, ddy) | Cube texture lookup with a gradient. | |
tex3Dlod(s, t) | Cube texture lookup with LOD. | |
texCUBEproj(s, t) | Cube texture lookup with projective divide. | |
transpose(m) | Returns the transpose of the matrix m. | |
trunc(x) | Truncates floating-point value(s) to integer value(s) |
表 3-1 HLSL内置函数
函数名 用法 |
abs 计算输入值的绝对值。
acos 返回输入值反余弦值。
all 测试非0值。
any 测试输入值中的任何非零值。
asin 返回输入值的反正弦值。
atan 返回输入值的反正切值。
atan2 返回y/x的反正切值。
ceil 返回大于或等于输入值的最小整数。
clamp 把输入值限制在[min, max]范围内。
clip 如果输入向量中的任何元素小于0,则丢弃当前像素。
cos 返回输入值的余弦。
cosh 返回输入值的双曲余弦。
cross 返回两个3D向量的叉积。
ddx 返回关于屏幕坐标x轴的偏导数。
ddy 返回关于屏幕坐标y轴的偏导数。
degrees 弧度到角度的转换
determinant 返回输入矩阵的值。
distance 返回两个输入点间的距离。
dot 返回两个向量的点积。
exp 返回以e为底数,输入值为指数的指数函数值。
exp2 返回以2为底数,输入值为指数的指数函数值。
faceforward 检测多边形是否位于正面。
floor 返回小于等于x的最大整数。
fmod 返回a / b的浮点余数。
frac 返回输入值的小数部分。
frexp 返回输入值的尾数和指数
fwidth 返回 abs ( ddx (x) abs ( ddy(x))。
isfinite 如果输入值为有限值则返回true,否则返回false。
isinf 如何输入值为无限的则返回true。
isnan 如果输入值为NAN或QNAN则返回true。
ldexp frexp的逆运算,返回 x * 2 ^ exp。
len / lenth 返回输入向量的长度。
lerp 对输入值进行插值计算。
lit 返回光照向量(环境光,漫反射光,镜面高光,1)。
log 返回以e为底的对数。
log10 返回以10为底的对数。
log2 返回以2为底的对数。
max 返回两个输入值中较大的一个。
min 返回两个输入值中较小的一个。
modf 把输入值分解为整数和小数部分。
mul 返回输入矩阵相乘的积。
normalize 返回规范化的向量,定义为 x / length(x)。
pow 返回输入值的指定次幂。
radians 角度到弧度的转换。
reflect 返回入射光线i对表面法线n的反射光线。
refract 返回在入射光线i,表面法线n,折射率为eta下的折射光线v。
round 返回最接近于输入值的整数。
rsqrt 返回输入值平方根的倒数。
saturate 把输入值限制到[0, 1]之间。
sign 计算输入值的符号。
sin 计算输入值的正弦值。
sincos 返回输入值的正弦和余弦值。
sinh 返回x的双曲正弦。
smoothstep 返回一个在输入值之间平稳变化的插值。
sqrt 返回输入值的平方根。
step 返回(x >= a)? 1 : 0。
tan 返回输入值的正切值。
fanh 返回输入值的双曲线切线。
transpose 返回输入矩阵的转置。
tex1D* 1D纹理查询。
tex2D* 2D纹理查询。
tex3D* 3D纹理查询。
texCUBE* 立方纹理查询。
Intrinsic Functions (DirectX HLSL)
The following table lists the intrinsic functions available in HLSL. Each function has a brief description, and a link to a reference page that has more detail about the input argument and return type.
Name | Description | Minimum shader model |
Absolute value (per component). | 11 | |
Returns the arccosine of each component of x. | 11 | |
Test if all components of x are nonzero. | 11 | |
Blocks execution of all threads in a group until all memory accesses have been completed. | 5 | |
Blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. | 5 | |
Test if any component of x is nonzero. | 11 | |
Reinterprets a cast value into a double. | 5 | |
Convert the input type to a float. | 4 | |
Returns the arcsine of each component of x. | 11 | |
Convert the input type to an integer. | 4 | |
Reinterprets the bit pattern of a 64-bit type to a uint. | 5 | |
Convert the input type to an unsigned integer. | 4 | |
Returns the arctangent of x. | 11 | |
Returns the arctangent of of two values (x,y). | 11 | |
Returns the smallest integer which is greater than or equal to x. | 11 | |
Clamps x to the range [min, max]. | 11 | |
Discards the current pixel, if any component of x is less than zero. | 11 | |
Returns the cosine of x. | 11 | |
Returns the hyperbolic cosine of x. | 11 | |
Counts the number of bits (per component) in the input integer. | 5 | |
Returns the cross product of two 3D vectors. | 11 | |
Swizzles and scales components of the 4D vector xto compensate for the lack of UBYTE4 support in some hardware. | 11 | |
Returns the partial derivative of x with respect to the screen-space x-coordinate. | 21 | |
Computes a low precision partial derivative with respect to the screen-space x-coordinate. | 5 | |
Computes a high precision partial derivative with respect to the screen-space x-coordinate. | 5 | |
Returns the partial derivative of x with respect to the screen-space y-coordinate. | 21 | |
Computes a low precision partial derivative with respect to the screen-space y-coordinate. | 5 | |
Computes a high precision partial derivative with respect to the screen-space y-coordinate. | 5 | |
Converts x from radians to degrees. | 11 | |
Returns the determinant of the square matrix m. | 11 | |
Blocks execution of all threads in a group until all device memory accesses have been completed. | 5 | |
Blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call. | 5 | |
Returns the distance between two points. | 11 | |
Returns the dot product of two vectors. | 1 | |
Calculates a distance vector. | 5 | |
Evaluates at the pixel centroid. | 5 | |
Evaluates at the indexed sample location. | 5 | |
Evaluates at the pixel centroid with an offset. | 5 | |
Returns the base-e exponent. | 11 | |
Base 2 exponent (per component). | 11 | |
Converts the float16 stored in the low-half of the uint to a float. | 5 | |
Converts an input into a float16 type. | 5 | |
Returns -n * sign(dot(i, ng)). | 11 | |
Gets the location of the first set bit starting from the highest order bit and working downward, per component. | 5 | |
Returns the location of the first set bit starting from the lowest order bit and working upward, per component. | 5 | |
Returns the greatest integer which is less than or equal to x. | 11 | |
Returns the floating point remainder of x/y. | 11 | |
Returns the fractional part of x. | 11 | |
Returns the mantissa and exponent of x. | 21 | |
Returns abs(ddx(x)) abs(ddy(x)) | 21 | |
Returns the number of render-target samples. | 4 | |
Returns a sample position (x,y) for a given sample index. | 4 | |
Blocks execution of all threads in a group until all group shared accesses have been completed. | 5 | |
Blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call. | 5 | |
Performs a guaranteed atomic add of value to the dest resource variable. | 5 | |
Performs a guaranteed atomic and. | 5 | |
Atomically compares the input to the comparison value and exchanges the result. | 5 | |
Atomically compares the input to the comparison value. | 5 | |
Assigns value to dest and returns the original value. | 5 | |
Performs a guaranteed atomic max. | 5 | |
Performs a guaranteed atomic min. | 5 | |
Performs a guaranteed atomic or. | 5 | |
Performs a guaranteed atomic xor. | 5 | |
Returns true if x is finite, false otherwise. | 11 | |
Returns true if x is INF or -INF, false otherwise. | 11 | |
Returns true if x is NAN or QNAN, false otherwise. | 11 | |
Returns x * 2exp | 11 | |
Returns the length of the vector v. | 11 | |
Returns x s(y - x). | 11 | |
Returns a lighting vector (ambient, diffuse, specular, 1) | 11 | |
Returns the base-e logarithm of x. | 11 | |
Returns the base-10 logarithm of x. | 11 | |
Returns the base-2 logarithm of x. | 11 | |
Performs an arithmetic multiply/add operation on three values. | 5 | |
Selects the greater of x and y. | 11 | |
Selects the lesser of x and y. | 11 | |
Splits the value x into fractional and integer parts. | 11 | |
Performs matrix multiplication using x and y. | 1 | |
Generates a random value using the Perlin-noise algorithm. | 11 | |
Returns a normalized vector. | 11 | |
Returns xy. | 11 | |
Generates the corrected tessellation factors for a quad patch. | 5 | |
Generates the corrected tessellation factors for a quad patch. | 5 | |
Generates the corrected tessellation factors for a quad patch. | 5 | |
Generates the rounded tessellation factors for an isoline. | 5 | |
Generates the corrected tessellation factors for a quad patch. | 5 | |
Generates the corrected tessellation factors for a quad patch. | 5 | |
Generates the corrected tessellation factors for a quad patch. | 5 | |
Generates the corrected tessellation factors for a tri patch. | 5 | |
Generates the corrected tessellation factors for a tri patch. | 5 | |
Generates the corrected tessellation factors for a tri patch. | 5 | |
Converts x from degrees to radians. | 1 | |
Calculates a fast, approximate, per-component reciprocal. | 5 | |
Returns a reflection vector. | 1 | |
Returns the refraction vector. | 11 | |
Reverses the order of the bits, per component. | 5 | |
Rounds x to the nearest integer | 11 | |
Returns 1 / sqrt(x) | 11 | |
Clamps x to the range [0, 1] | 1 | |
Computes the sign of x. | 11 | |
Returns the sine of x | 11 | |
Returns the sine and cosine of x. | 11 | |
Returns the hyperbolic sine of x | 11 | |
Returns a smooth Hermite interpolation between 0 and 1. | 11 | |
Square root (per component) | 11 | |
Returns (x >= a) ? 1 : 0 | 11 | |
Returns the tangent of x | 11 | |
Returns the hyperbolic tangent of x | 11 | |
1D texture lookup. | 1 | |
1D texture lookup. | 21 | |
1D texture lookup with bias. | 21 | |
1D texture lookup with a gradient. | 21 | |
1D texture lookup with LOD. | 31 | |
1D texture lookup with projective divide. | 21 | |
2D texture lookup. | 11 | |
2D texture lookup. | 21 | |
2D texture lookup with bias. | 21 | |
2D texture lookup with a gradient. | 21 | |
2D texture lookup with LOD. | 3 | |
2D texture lookup with projective divide. | 21 | |
3D texture lookup. | 11 | |
3D texture lookup. | 21 | |
3D texture lookup with bias. | 21 | |
3D texture lookup with a gradient. | 21 | |
3D texture lookup with LOD. | 31 | |
3D texture lookup with projective divide. | 21 | |
Cube texture lookup. | 11 | |
Cube texture lookup. | 21 | |
Cube texture lookup with bias. | 21 | |
Cube texture lookup with a gradient. | 21 | |
Cube texture lookup with LOD. | 31 | |
Cube texture lookup with projective divide. | 21 | |
Returns the transpose of the matrix m. | 1 | |
Truncates floating-point value(s) to integer value(s) | 1 |
1 see reference page for restrictions.