title | description | ms.assetid | keywords | topic_type | api_name | api_type | ms.topic | ms.date | api_location | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Texture type |
Use the following syntax to declare a texture variable. |
54db5432-dab8-4a4d-a4de-93c6fa640535 |
|
|
|
|
reference |
05/31/2018 |
Use the following syntax to declare a texture variable.
Type Name; |
Item | Description |
---|---|
Type |
One of the following types: texture (untyped, for backwards compatibility), Texture1D, Texture1DArray, Texture2D, Texture2DArray, Texture3D, TextureCube. The element size must fit into 4 32-bit quantities. |
Name |
An ASCII string that uniquely identifies the variable name. |
There are three parts to using a texture.
-
Declaring a texture variable. This is done with the syntax shown above. For example, these are valid declarations.
texture g_MeshTexture;
- or -
Texture2D g_MeshTexture;
-
Declaring and initializing a sampler object. This is done with slightly different syntax in Direct3D 9 and Direct3D 10. For details about sampler object syntax, see Sampler Type (DirectX HLSL).
-
Invoking a texture function in a shader.
Differences between Direct3D 9 and Direct3D 10:
Direct3D 9 uses intrinsic texture functions to perform texture operations. This example is from the BasicHLSL Sample and uses tex2D(s, t) (DirectX HLSL) to perform texture sampling.
Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;
Direct3D 10 uses templated texture objects instead. Here is an example of the equivalent texture operation.
Output.RGBColor = g_MeshTexture.Sample(MeshTextureSampler, In.TextureUV) * In.Diffuse;