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 abs(x) Absolute value (per component).
acos acos(x) Returns the arccosine of each component of x.
all all(x) Test if all components of x are nonzero.
any any(x) Test if any component of x is nonzero.
asfloat asfloat(x) Convert the input type to a float.
asin asin(x) Returns the arcsine of each component of x.
asint asint(x) Convert the input type to an integer.
asuint asuint(x) Convert the input type to an unsigned integer.
atan atan(x) Returns the arctangent of x.
atan2 atan2(y, x) Returns the arctangent of of two values (x,y).
ceil ceil(x) Returns the smallest integer which is greater than or equal to x.
clamp clamp(x, min, max) Clamps x to the range [min, max].
clip clip(x) Discards the current pixel, if any component of x is less than zero.
cos cos(x) Returns the cosine of x.
cosh cosh(x) Returns the hyperbolic cosine of x.
cross cross(x, y) Returns the cross product of two 3D vectors.
D3DCOLORtoUBYTE4 D3DCOLORtoUBYTE4(x) Swizzles and scales components of the 4D vector x to compensate for the lack of UBYTE4 support in some hardware.
ddx ddx(x) Returns the partial derivative of x with respect to the screen-space x-coordinate.
ddy ddy(x) Returns the partial derivative of x with respect to the screen-space y-coordinate.
degrees degrees(x) Converts x from radians to degrees.
determinant determinant(m) Returns the determinant of the square matrix m.
distance distance(x, y) Returns the distance between two points.
dot dot(x, y) Returns the dot product of two vectors.
exp exp(x) Returns the base-e exponent.
exp2 exp2(x) Base 2 exponent (per component).
faceforward faceforward(n, i, ng) Returns -n * sign(•(i, ng)).
floor floor(x) Returns the greatest integer which is less than or equal to x.
fmod fmod(x, y) Returns the floating point remainder of x/y.
frac frac(x) Returns the fractional part of x.
frexp frexp(x, exp) Returns the mantissa and exponent of x.
fwidth fwidth(x) Returns abs(ddx(x)) + abs(ddy(x))
GetRenderTargetSampleCount GetRenderTargetSampleCount() Returns the number of render-target samples.
GetRenderTargetSamplePosition GetRenderTargetSamplePosition(x) Returns a sample position (x,y) for a given sample index.
isfinite isfinite(x) Returns true if x is finite, false otherwise.
isinf isinf(x) Returns true if x is +INF or -INF, false otherwise.
isnan isnan(x) Returns true if x is NAN or QNAN, false otherwise.
ldexp ldexp(x, exp) Returns x * 2exp
length length(v) Returns the length of the vector v.
lerp lerp(x, y, s) Returns x + s(y - x).
lit lit(n • l, n • h, m) Returns a lighting vector (ambient, diffuse, specular, 1)
log log(x) Returns the base-e logarithm of x.
log10 log10(x) Returns the base-10 logarithm of x.
log2 log2(x) Returns the base-2 logarithm of x.
max max(x, y) Selects the greater of x and y.
min min(x, y) Selects the lesser of x and y.
modf modf(x, out ip) Splits the value x into fractional and integer parts.
mul mul(x, y) Performs matrix multiplication using x and y.
noise noise(x) Generates a random value using the Perlin-noise algorithm.
normalize normalize(x) Returns a normalized vector.
pow pow(x, y) Returns xy.
radians radians(x) Converts x from degrees to radians.
reflect reflect(i, n) Returns a reflection vector.
refract refract(i, n, R) Returns the refraction vector.
round round(x) Rounds x to the nearest integer
rsqrt rsqrt(x) Returns 1 / sqrt(x)
saturate saturate(x) Clamps x to the range [0, 1]
sign sign(x) Computes the sign of x.
sin sin(x) Returns the sine of x
sincos sincos(x, out s, out c) Returns the sine and cosine of x.
sinh sinh(x) Returns the hyperbolic sine of x
smoothstep smoothstep(min, max, x) Returns a smooth Hermite interpolation between 0 and 1.
sqrt sqrt(x) Square root (per component)
step step(a, x) Returns (x >= a) ? 1 : 0
tan tan(x) Returns the tangent of x
tanh tanh(x) Returns the hyperbolic tangent of x
tex1D tex1D(s, t) 1D texture lookup.
tex1Dbias tex1Dbias(s, t) 1D texture lookup with bias.
tex1Dgrad tex1Dgrad(s, t, ddx, ddy) 1D texture lookup with a gradient.
tex1Dlod tex1Dlod(s, t) 1D texture lookup with LOD.
tex1Dproj tex1Dproj(s, t) 1D texture lookup with projective divide.
tex2D tex2D(s, t) 2D texture lookup.
tex2Dbias tex2Dbias(s, t) 2D texture lookup with bias.
tex2Dgrad tex2Dgrad(s, t, ddx, ddy) 2D texture lookup with a gradient.
tex2Dlod tex2Dlod(s, t) 2D texture lookup with LOD.
tex2Dproj tex2Dproj(s, t) 2D texture lookup with projective divide.
tex3D tex3D(s, t) 3D texture lookup.
tex3Dbias tex3Dbias(s, t) 3D texture lookup with bias.
tex3Dgrad tex3Dgrad(s, t, ddx, ddy) 3D texture lookup with a gradient.
tex3Dlod tex3Dlod(s, t) 3D texture lookup with LOD.
tex3Dproj tex3Dproj(s, t) 3D texture lookup with projective divide.
texCUBE texCUBE(s, t) Cube texture lookup.
texCUBEbias texCUBEbias(s, t) Cube texture lookup with bias.
texCUBEgrad texCUBEgrad(s, t, ddx, ddy) Cube texture lookup with a gradient.
texCUBElod tex3Dlod(s, t) Cube texture lookup with LOD.
texCUBEproj texCUBEproj(s, t) Cube texture lookup with projective divide.
transpose transpose(m) Returns the transpose of the matrix m.
trunc 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* 立方紋理查詢。
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/duduliao/archive/2008/12/30/3646100.aspx