Function Arguments

A function takes one or more input arguments; use the following syntax to declare each argument.

[InputModifier] Type Name [: Semantic] [InterpolationModifier] [= Initializers]


[Modifier] Type Name [: Semantic] [: Interpolation Modifier] [= Initializer(s)]

If there are multiple function arguments, they are separated by commas.




Optional term that identifies an argument as an input, an output, or both.

inInput only
inoutInput and an output
outOutput only
uniformInput only constant data


Parameters are always passed by value. in indicates that the value of the parameter should be copied in from the calling application before the function begins. out indicates that the last value of the parameter should be copied out, and returned to the calling application when the function returns. inout is a shorthand for specifying both.

A uniform value comes from a constant register; each vertex shader or pixel shader invocation see the same initial value for a uniform variable. Global variables are treated as if they are declared uniform. For non-top-level functions, uniform is synonymous with in. If no parameter usage is specified, the parameter usage is assumed to be in.


The argument type; can be any valid HLSL type.


An ASCII string that uniquely identifies the name of the shader function.


Optional string that identifies the intended usage of the data (see Semantics (DirectX HLSL)).


Optional interpolation modifier which allows a shader to determine the method of interpolation. An interpolation modifier on a function argument only applies to an argument used as an input to a pixel shader function.


Optional values for initialization; multiple values are required to initialize multi-component data types.



Function arguments are listed in a comma-separated argument list in a function declaration. As in C functions, each argument must have a parameter name and type declared; an argument to an HLSL function optionally can include a semantic, an initial value, and a pixel shader input can include an interpolation type.

The Type of a function argument could be a structure, which could include a per-member interpolation modifier. If the function argument also has an interpolation modifier, the function argument modifier overrides interpolation modifiers declared within the Type.


This example (from the BasicHLSL10 Sample) illustrates uniform and non-uniform inputs to a vertex shader function.

VS_OUTPUT RenderSceneVS( 
  float4 vPos : POSITION,
  float3 vNormal : NORMAL,
  float2 vTexCoord0 : TEXCOORD,
  uniform int nNumLights,
  uniform bool bTexture,
  uniform bool bAnimate )

This example (from the ContentStreaming Sample) uses an input structure to pass arguments to a pixel shader function.

VSBasicIn input
struct VSBasicIn
  float4 Pos    : POSITION;
  float3 Norm   : NORMAL;
  float2 Tex    : TEXCOORD0;

PSBasicIn VSBasic(VSBasicIn input)

Related topics

Functions (DirectX HLSL)



Community Additions

© 2014 Microsoft