User defined functions are very similar to C functions.
Functions are declared with one or more of these components:
[Storage Class Modifiers] [Type Modifiers] FunctionType FunctionName ( [ParameterList] ) { [StatementBlock] } ;
static | At global scope, the static keyword prevents a shader variable from being exposed to an application. None of the application programming interface (API) methods (GetVertexShaderConstantx or SetVertexShaderConstantx) and none of the ID3DXConstantTable interface methods can be used to get or set a static variable.
static float fConstant_Hidden_From_the_App = 0.2f;At local scope, a static variable has a value that persists from one invocation of the function to the next. |
---|---|
inline | Each copy of a function may have its own function body to decrease the overhead of calling the function. All functions are currently inlined. Recursion is not supported. |
target | The target represents an optional identifier specifying the platform for which the function has been authored. |
Type modifiers are optional keywords placed immediately before the variable type, which give the compiler additional information about the data type.
const | The const modifier indicates a variable whose value cannot be changed by a shader. Declaring a variable with const allows the compiler to put the value in a portion of memory that does not need write access. Because the variable cannot be changed, it must be initialized in the declaration. |
---|
Any valid type including: basic types, vector types, matrix types, shader types, sampler type, user defined types.
An ASCII string that uniquely identifies the name of the shader function.
One or more parameters separated by commas. See Function Parameter List Syntax.
One or more statements that make up the body of the function. See Statement Block Syntax.
If a function is defined without a body, it is considered to be a prototype. The function must be redefined, with a body, later on in the code.
Functions can be overloaded. A function is uniquely identified by its name, the types of its parameters, and the target platform, if provided. For a list of the built in functions, see HLSL Intrinsic Functions.