Sampler Type (Windows)

Switch View :
ScriptFree
Sampler Type

Applies to: desktop apps only

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

Differences between Direct3D 9 and Direct3D 10:

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 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 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:

Direct3D 10 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
ComparisonFilter

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

Remarks

When implementing a shader or an effect, sampler state is one of several types of state that may be required to set up the pipeline for rendering. For a list of all the possible states that can be set in a shader or an effect:

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 = MIN_MAG_LINEAR_MIP_POINT;
   AddressU = MIRROR;
   AddressV = MIRROR;

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

See also

Data Types (DirectX HLSL)

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012