Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Use the following syntax to declare a texture variable.
Type Name; |
Parameters
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. |
Remarks
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;