最常用的一个函数是Sample
Sample( sampler_state S, float Location [, int Offset] );
sampler_state 可以从外部的buffer传过来,也可以是hlsl内定义,一般情况下都选择从外部设置进行共享。
Location应该穿入的是uv数据,不同的图片类型有不同的uv类型
Texture-Object Type Parameter Type
Texture1D float
Texture1DArray, Texture2D float2
Texture2DArray, Texture3D, TextureCube float3
TextureCubeArray float4
offset是可选参数,不填则是默认的0,0
Texture-Object Type Parameter Type
Texture1D, Texture1DArray int
Texture2D, Texture2DArray int2
Texture3D int3
TextureCube, TextureCubeArray //not supported
// Object Declarations
Texture2D g_MeshTexture; // Color texture for mesh
SamplerState MeshTextureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color (note that COLOR0 is clamped from 0..1)
float2 TextureUV : TEXCOORD0; // vertex texture coords
};
VS_OUTPUT In;
// pixel shader函数体
...
Output.RGBColor = g_MeshTexture.Sample(MeshTextureSampler, In.TextureUV) * In.Diffuse;