HLSL intrinsic functions are made up of
For example, the abs intrinsic function could be called like this:
float3 retValue; retValue = abs(float3(0,0,1));
Where:
The input argument is made up of one or more template types, where each template type is made up of one or more data types. The return value is also made up of a template type and a data type, and the return value is dependent on the choices made for the input argument and the operation of the function.
These are the template types for input arguments and return values:
The component data types for input arguments and return values are the HLSL types:
The template type must be compatible with the component type:
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 - HLSL | value abs(value a) | Absolute value (per component). |
acos - HLSL | acos(x) | Returns the arccosine of each component of x. Each component should be in the range [-1, 1]. |
all - HLSL | all(x) | Test if all components of x are nonzero. |
any - HLSL | any(x) | Test if any component of x is nonzero. |
asin - HLSL | asin(x) | Returns the arcsine of each component of x. Each component should be in the range [-pi/2, pi/2]. |
atan - HLSL | atan(x) | Returns the arctangent of x. The return values are in the range [-pi/2, pi/2]. |
atan2 - HLSL | atan2(y, x) | Returns the arctangent of y/x. The signs of y and x are used to determine the quadrant of the return values in the range [-pi, pi]. atan2 is well-defined for every point other than the origin, even if x equals 0 and y does not equal 0. |
ceil - HLSL | ceil(x) | Returns the smallest integer which is greater than or equal to x. |
clamp - HLSL | clamp(x, min, max) | Clamps x to the range [min, max]. |
clip - HLSL | clip(x) | Discards the current pixel, if any component of x is less than zero. This can be used to simulate clip planes, if each component of x represents the distance from a plane. |
cos - HLSL | cos(x) | Returns the cosine of x. |
cosh - HLSL | cosh(x) | Returns the hyperbolic cosine of x. |
cross - HLSL | cross(a, b) | Returns the cross product of two 3D vectors a and b. |
D3DCOLORtoUBYTE4 - HLSL | D3DCOLORtoUBYTE4(x) | Swizzles and scales components of the 4D vector x to compensate for the lack of UBYTE4 support in some hardware. |
ddx - HLSL | ddx(x) | Returns the partial derivative of x with respect to the screen-space x-coordinate. |
ddy - HLSL | ddy(x) | Returns the partial derivative of x with respect to the screen-space y-coordinate. |
degrees - HLSL | degrees(x) | Converts x from radians to degrees. |
determinant - HLSL | determinant(m) | Returns the determinant of the square matrix m. |
distance - HLSL | distance(a, b) | Returns the distance between two points, a and b. |
dot - HLSL | dot(a, b) | Returns the • product of two vectors, a and b. |
exp - HLSL | exp(x) | Returns the base-e exponent. |
exp2 - HLSL | value exp2(value a) | Base 2 Exp (per component). |
faceforward - HLSL | faceforward(n, i, ng) | Returns -n * sign(•(i, ng)). |
floor - HLSL | floor(x) | Returns the greatest integer which is less than or equal to x. |
fmod - HLSL | fmod(a, b) | Returns the floating point remainder f of a / b such that a = i * b + f, where i is an integer, f has the same sign as x, and the absolute value of f is less than the absolute value of b. |
frac - HLSL | frac(x) | Returns the fractional part f of x, such that f is a value greater than or equal to 0, and less than 1. |
frexp - HLSL | frexp(x, out exp) | Returns the mantissa and exponent of x. frexp returns the mantissa, and the exponent is stored in the output parameter exp. If x is 0, the function returns 0 for both the mantissa and the exponent. |
fwidth - HLSL | fwidth(x) | Returns abs(ddx(x)) + abs(ddy(x)). |
isfinite - HLSL | isfinite(x) | Returns true if x is finite, false otherwise. |
isinf - HLSL | isinf(x) | Returns true if x is +INF or -INF, false otherwise. |
isnan - HLSL | isnan(x) | Returns true if x is NAN or QNAN, false otherwise. |
ldexp - HLSL | ldexp(x, exp) | Returns x * 2exp. |
length - HLSL | length(v) | Returns the length of the vector v. |
lerp - HLSL | lerp(a, b, s) | Returns a + s(b - a). This linearly interpolates between a and b, such that the return value is a when s is 0, and b when s is 1. |
lit - HLSL | lit(n • l, n • h, m) | Returns a lighting vector (ambient, diffuse, specular, 1):ambient = 1;diffuse = (n • l < 0) ? 0 : n • l; specular = (n • l < 0) || (n • h < 0) ? 0 : (n • h * m); |
log - HLSL | log(x) | Returns the base-e logarithm of x. If x is negative, the function returns indefinite. If x is 0, the function returns +INF. |
log10 - HLSL | log10(x) | Returns the base-10 logarithm of x. If x is negative, the function returns indefinite. If x is 0, the function returns +INF. |
log2 - HLSL | log2(x) | Returns the base-2 logarithm of x. If x is negative, the function returns indefinite. If x is 0, the function returns +INF. |
max - HLSL | max(a, b) | Selects the greater of a and b. |
min - HLSL | min(a, b) | Selects the lesser of a and b. |
modf - HLSL | modf(x, out ip) | Splits the value x into fractional and integer parts, each of which has the same sign and x. The signed fractional portion of x is returned. The integer portion is stored in the output parameter ip. |
mul - HLSL | mul(a, b) | Performs matrix multiplication between a and b. If a is a vector, it is treated as a row vector. If b is a vector, it is treated as a column vector. The inner dimension acolumns and brows must be equal. The result has the dimension arows x bcolumns. |
noise - HLSL | noise(x) | Not yet implemented. |
normalize - HLSL | normalize(v) | Returns the normalized vector v / length(v). If the length of v is 0, the result is indefinite. |
pow - HLSL | pow(x, y) | Returns xy. |
radians - HLSL | radians(x) | Converts x from degrees to radians. |
reflect - HLSL | reflect(i, n) | Returns the reflection vector v, given the entering ray direction i, and the surface normal n, such that v = i - 2n * (i•n). |
refract - HLSL | refract(i, n, R) | Returns the refraction vector v, given the entering ray direction i, the surface normal n, and the relative index of refraction R. If the angle between i and n is too great for a given R, refract returns (0,0,0). |
round - HLSL | round(x) | Rounds x to the nearest integer |
rsqrt - HLSL | rsqrt(x) | Returns 1 / sqrt(x) |
saturate - HLSL | saturate(x) | Clamps x to the range [0, 1] |
sign - HLSL | sign(x) | Computes the sign of x. Returns -1 if x is less than 0, 0 if x equals 0, and 1 if x is greater than zero. |
sin - HLSL | sin(x) | Returns the sine of x |
sincos - HLSL | sincos(x, out s, out c) | 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. |
sinh - HLSL | sinh(x) | Returns the hyperbolic sine of x |
smoothstep - HLSL | smoothstep(min, max, x) | Returns 0 if x < min. Returns 1 if x > max. Returns a smooth Hermite interpolation between 0 and 1, if x is in the range [min, max]. |
sqrt - HLSL | value sqrt(value a) | Square root (per component) |
step - HLSL | step(a, x) | Returns (x >= a) ? 1 : 0 |
tan - HLSL | tan(x) | Returns the tangent of x |
tanh - HLSL | tanh(x) | Returns the hyperbolic tangent of x |
tex1D - HLSL | tex1D(s, t) | 1D texture lookup. s is a sampler or a sampler1D object. t is a scalar. |
tex1Dgrad - HLSL | tex1D(s, t, ddx, ddy) | 1D texture lookup, with derivatives. s is a sampler or sampler1D object. t, ddx, and ddy are scalars. |
tex1Dbias - HLSL | tex1Dbias(s, t) | 1D biased texture lookup. s is a sampler or sampler1D object. t is a 4D vector. The mip level is biased by t.w before the lookup takes place. |
tex1Dgrad - HLSL | tex1Dgrad(s, t, ddx, ddy) | 1D gradient texture lookup. s is a sampler or sampler1D object. t is a 4D vector. The gradient values (ddx, ddy) select the appropriate mipmap level of the texture for sampling. |
tex1Dlod - HLSL | tex1Dlod(s, t) | 1D texture lookup with LOD. s is a sampler or sampler1D object. t is a 4D vector. The mipmap LOD is specified in t. |
tex1Dproj - HLSL | tex1Dproj(s, t) | 1D projective texture lookup. s is a sampler or sampler1D object. t is a 4D vector. t is divided by its last component before the lookup takes place. |
tex2D - HLSL | tex2D(s, t) | 2D texture lookup. s is a sampler or a sampler2D object. t is a 2D texture coordinate. |
tex2D - HLSL | tex2D(s, t, ddx, ddy) | 2D texture lookup, with derivatives. s is a sampler or sampler2D object. t, ddx, and ddy are 2D vectors. |
tex2Dbias - HLSL | tex2Dbias(s, t) | 2D biased texture lookup. s is a sampler or sampler2D object. t is a 4D vector. The mip level is biased by t.w before the lookup takes place. |
tex2Dgrad - HLSL | tex2Dgrad(s, t, ddx, ddy) | 2D gradient texture lookup. s is a sampler or sampler2D object. t is a 4D vector. The gradient values (ddx, ddy) select the appropriate mipmap level of the texture for sampling. |
tex2Dlod - HLSL | tex2Dlod(s, t) | 2D texture lookup with LOD. s is a sampler or sampler2D object. t is a 4D vector. The mipmap LOD is specified in t. |
tex2Dproj - HLSL | tex2Dproj(s, t) | 2D projective texture lookup. s is a sampler or sampler2D object. t is a 4D vector. t is divided by its last component before the lookup takes place. |
tex3D - HLSL | tex3D(s, t) | 3D volume texture lookup. s is a sampler or a sampler3D object. t is a 3D texture coordinate. |
tex3D - HLSL | tex3D(s, t, ddx, ddy) | 3D volume texture lookup, with derivatives. s is a sampler or sampler3D object. t, ddx, and ddy are 3D vectors. |
tex3Dbias - HLSL | tex3Dbias(s, t) | 3D biased texture lookup. s is a sampler or sampler3D object. t is a 4D vector. The mip level is biased by t.w before the lookup takes place. |
tex3Dgrad - HLSL | tex3Dgrad(s, t, ddx, ddy) | 3D gradient texture lookup. s is a sampler or sampler3D object. t is a 4D vector. The gradient values (ddx, ddy) select the appropriate mipmap level of the texture for sampling. |
tex3Dlod - HLSL | tex3Dlod(s, t) | 3D texture lookup with LOD. s is a sampler or sampler3D object. t is a 4D vector. The mipmap LOD is specified in t. |
tex3Dproj - HLSL | tex3Dproj(s, t) | 3D projective volume texture lookup. s is a sampler or sampler3D object. t is a 4D vector. t is divided by its last component before the lookup takes place. |
texCUBE - HLSL | texCUBE(s, t) | 3D cube texture lookup. s is a sampler or a samplerCUBE object. t is a 3D texture coordinate. |
texCUBE - HLSL | texCUBE(s, t, ddx, ddy) | 3D cube texture lookup, with derivatives. s is a sampler or samplerCUBE object. t, ddx, and ddy are 3D vectors. |
texCUBEbias - HLSL | texCUBEbias(s, t) | 3D biased cube texture lookup. s is a sampler or samplerCUBE object. t is a 4Dimensional vector. The mip level is biased by t.w before the lookup takes place. |
texCUBEgrad - HLSL | texCUBEgrad(s, t, ddx, ddy) | 3D gradient cube texture lookup. s is a sampler or samplerCUBE object. t is a 4D vector. The gradient values (ddx, ddy) select the appropriate mipmap level of the texture for sampling. |
texCUBElod - HLSL | tex3Dlod(s, t) | 3D 3D cube texture lookup with LOD. s is a sampler or samplerCUBE object. t is a 4D vector. The mipmap LOD is specified in t. |
texCUBEproj - HLSL | texCUBEproj(s, t) | 3D projective cube texture lookup. s is a sampler or samplerCUBE object. t is a 4D vector. t is divided by its last component before the lookup takes place. |
transpose - HLSL | transpose(m) | Returns the transpose of the matrix m. If the source is dimension mrows x mcolumns, the result is dimension mcolumns x mrows. |