SampleLevel (DirectX HLSL Texture Object)
Samples a texture using a mipmap-level offset.
<Template Type> Object.SampleLevel( sampler_state S, float Location, float LOD [, int Offset] );
This function is similar to Sample except that it uses the LOD level (in the last component of the location parameter) to choose the mipmap level. For example, a 2D texture uses the first two components for uv coordinates and the third component for the mipmap level.
Parameters
Item | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Object |
Any texture-object type (except Texture2DMS and Texture2DMSArray). |
||||||||||
S |
[in] A Sampler state. This is an object declared in an effect file that contains state assignments. |
||||||||||
Location |
[in] The texture coordinates. The argument type is dependent on the texture-object type.
If the texture object is an array, the last component is the array index. |
||||||||||
LOD |
[in] A number that specifies the mipmap level. If the value is = 0, the zero'th (biggest map) is used. The fractional value (if supplied) is used to interpolate between two mipmap levels. |
||||||||||
Offset |
[in] An optional texture coordinate offset, which can be used for any texture-object type; the offset is applied to the location before sampling. The texture offsets need to be static. The argument type is dependent on the texture-object type. For more info, see Applying texture coordinate offsets.
|
Return Value
The texture's template type, which may be a single- or multi-component vector. The format is based on the texture's DXGI_FORMAT.
Minimum Shader Model
This function is supported in the following shader models.
vs_4_0 | vs_4_1 | ps_4_0 | ps_4_1 | gs_4_0 | gs_4_1 |
---|---|---|---|---|---|
x | x | x | x | x | x |
- TextureCubeArray is available in Shader Model 4.1 or higher.
- Shader Model 4.1 is available in Direct3D 10.1 or higher.
Example
This partial code example is from the Instancing.fx file in the Instancing10 Sample.
// Object Declarations
Texture1D g_txRandom;
SamplerState g_samPoint
{
Filter = MIN_MAG_MIP_POINT;
AddressU = Wrap;
AddressV = Wrap;
};
// Shader body calling the intrinsic function
float3 RandomDir(float fOffset)
{
float tCoord = (fOffset) / 300.0;
return g_txRandom.SampleLevel( g_samPoint, tCoord, 0 );
...