Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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;]   ... };

 

 

Parameters

sampler

Direct3D 9 only. Required keyword.

Name

ASCII string that uniquely identifies the sampler variable name.

[Index]

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

SamplerType

[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
AddressU
AddressV
AddressW
BorderColor
Filter
MaxAnisotropy
MaxLOD
MinLOD
MipLODBias

// sampler-comparison state
ComparisonFunc


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.

Remarks

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:

Example

Differences between Direct3D 9 and Direct3D 10:

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


sampler MeshTextureSampler = 
sampler_state
{
    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
   Filter = COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
   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)

 

 

Community Additions

Show:
© 2014 Microsoft