Texture Object

In Direct3D 10, you specify the samplers and textures independently; texture sampling is implemented by using a templated-texture object. This templated-texture object has a specific format, returns a specific type, and implements several methods.

Differences between Direct3D9 and Direct3D10:

In Direct3D 9, samplers are bound to specific textures; in Direct3D 10, textures and samplers are independent objects. Each templated-texture object implements texture sampling methods that take both the texture and the sampler as input parameters.

 

Here is the syntax for creating all texture objects (except multisampled objects).

Object1 [<Type>] Name;

 

Multisampled objects (Texture2DMS and Texture2DMSArray) require the texture size to be explicitly stated and expressed as the number of samples.

Object2 [<Type, Samples>] Name;

 

Parameters

ItemDescription

Object

A texture object. Must be one of the following types.

Object1 TypeDescription
BufferBuffer1
Texture1D1D texture
Texture1DArrayArray of 1D textures
Texture2D2D texture
Texture2DArrayArray of 2D textures
Texture3D3D texture
TextureCubeCube texture
TextureCubeArray23Array of cube textures
Object2 TypeDescription
Texture2DMS2D multisampled texture
Texture2DMSArrayArray of 2D multisampled textures

 

  1. The Buffer type supports most texture object methods except GetDimensions.
  2. TextureCubeArray is available in shader model 4.1 or higher.
  3. Shader model 4.1 is available in Direct3D 10.1 or higher.

Type

Optional. Any scalar HLSL type or vector HLSL type, surrounded by angle brackets. The default type is float4.

Name

An ASCII string that specifies the texture object name.

Samples

The number of samples (ranges between 1 and 128).

 

Example

Here is an example of declaring a texture object.



Texture2D <float4> MyTex;

Texture2DMS <float4, 128> MyMSTex;


Texture Object Methods

Each texture object implements certain methods; here's the table that lists all of the methods. See the reference page for each method to see what objects can use that method.

Texture MethodDescriptionvs_4_0vs_4_12ps_4_0ps_4_12gs_4_0gs_4_12
CalculateLevelOfDetail Calculate the LOD, return a clamped result.x
CalculateLevelOfDetailUnclamped Calculate the LOD, return an unclamped result.x
Gather Gets the four samples (red component only) that would be used for bilinear interpolation when sampling a texture.xxx
GetDimensions Get the texture dimension for a specified mipmap level.xxxxxx
GetDimensions (MultiSample) Get the texture dimension for a specified mipmap level.xxx
GetSamplePosition Get the position of the specified sample.xxx
Load Load data without any filtering or sampling.xxxxxx
Load (Multisample) Load data without any filtering or sampling.xxxx
Sample Sample a texture.xx
SampleBias Sample a texture, after applying the bias value to the mipmap level.xx
SampleCmp Sample a texture, using a comparison value to reject samples.xx
SampleCmpLevelZero Sample a texture (mipmap level 0 only), using a comparison value to reject samples.xxxxxx
SampleGrad Sample a texture using a gradient to influence the way the sample location is calculated.xxxxxx
SampleLevel Sample a texture on the specified mipmap level.xxxxxx

 

Return Type

The return type of a texture object method is float4 unless specified otherwise, with the exception of the multisampled anti-aliased texture objects that always need the type and sample count specified. The return type is the same as the texture resource type (DXGI_FORMAT). In other words, it can be any of the following types.

TypeDescription
float32-bit float (see Floating-Point Rules for differences from IEEE float)
int32-bit signed integer
unsigned int32-bit unsigned integer
snorm32-bit float in range -1 to 1 inclusive (see Floating-Point Rules for differences from IEEE float)
unorm32-bit float in range 0 to 1 inclusive (see Floating-Point Rules for differences from IEEE float)
any texture type or structThe number of components returned must be between 1 and 3 inclusive.

 

In addition, the return type can be any texture type including a structure but, it must be less than 4 components such as a float1 type which returns one component.

Default Values for Missing Components in a Texture

The default value for missing components in a texture resource type is zero for any component except the alpha component (A); the default value for the missing A is one. The way that this one appears to the shader depends on the texture resource type. It takes the form of the first typed component that is actually present in the texture resource type (starting from the left in RGBA order). If this form is UNORM or FLOAT, the default value for the missing A is 1.0f. If the form is SINT or UINT, the default value for the missing A is 0x1.

For example, when a shader reads the DXGI_FORMAT_R24_UNORM_X8_TYPELESS texture resource type, the default values for G and B are zero and the default value for A is 1.0f; when a shader reads the DXGI_FORMAT_R16G16_UINT texture resource type, the default value for B is zero and the default value for A is 0x00000001; when a shader reads the DXGI_FORMAT_R16_SINT texture resource type, the default values for G and B are zero and the default value for A is 0x00000001.

Example

Here is an example of texture sampling using a texture method.



sampler MySamp;
Texture2D <float4> MyTex;
 
float4 main( float2 TexCoords[2] : TEXCOORD ) : SV_Target
{
    return MyTex.Sample( MySamp, TexCoords[0] ));
}


Minimum Shader Model

This object is supported in the following shader models.

Shader ModelSupported
Shader Model 4 and higher shader modelsyes

 

See also

Shader Model 4

 

 

Community Additions

ADD
Show:
© 2014 Microsoft