Sampler Type

Use the following syntax to declare sampler state as well as sampler-comparison state.

Differences between Direct3D 9 and Direct3D 10 and later:

Here is the syntax for a sampler in Direct3D 9.

sampler Name = SamplerType{   Texture = <texture_variable>;   [state_name = state_value;]   ... };


The syntax for a sampler in Direct3D 10 and later is changed slightly to support texture objects and sampler arrays.

SamplerType Name[Index]{   [state_name = state_value;]   ... };





Direct3D 9 only. Required keyword.


ASCII string that uniquely identifies the sampler variable name.


Direct3D 10 and later only. Optional array size; a positive integer greater than or equal to 1.


[in] The sampler type, which is one of the following: sampler, sampler1D, sampler2D, sampler3D, samplerCUBE, sampler_state, SamplerState.

Differences between Direct3D 9 and Direct3D 10 and later:

Direct3D 10 and later supports one additional sampler type: SamplerComparisonState.


Texture = <texture_variable>;

Direct3D 9 only. A texture variable. The Texture keyword is required on the left-hand side; the variable name belongs on the right-hand side of the expression within the angle brackets.

state_name = state_value

[in] Optional state assignment(s). The left hand side of an assignment is a state name, the right hand side is the state value. All state assignments must appear within a statement block (in curly brackets). Each statement is separated with a semicolon. The following table lists the possible state names.

// sampler state

// sampler-comparison state

The right side of each expression is the value assigned to each state. See the D3D11_SAMPLER_DESC structure for the possible state values for Direct3D 11. There is a 1 to 1 relationship between the state names and the members of the structure. See the following example.


When you implement an effect, sampler state is one of several types of state that you might need to set up in the pipeline for rendering. For a list of all the possible states that you can set in an effect, see:


Differences between Direct3D 9 and Direct3D 10:

Here is a partial example of a Direct3D 9 sampler from BasicHLSL Sample.

sampler MeshTextureSampler = 
    Texture = <g_MeshTexture>;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;

Here is a partial example of a Direct3D 10 sampler from BasicHLSL10 Sample.

SamplerState MeshTextureSampler
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;


Here is a partial example of declaring sampler-comparison state, and calling a comparison sampler in Direct3D 10.

SamplerComparisonState ShadowSampler
   // sampler state
   AddressU = MIRROR;
   AddressV = MIRROR;

   // sampler comparison state
   ComparisonFunc = LESS;
float3 vModProjUV;
float fShadow = g_ShadowMap.SampleCmpLevelZero( ShadowSampler, vModProjUV.xy, vModProjUV.z);

See also

Data Types (DirectX HLSL)