SampleGrad (DirectX HLSL Texture Object)
Samples a texture using a gradient to influence the way the sample location is calculated.
<Template Type> Object.SampleGrad( sampler_state S, float Location, float DDX, float DDY [, int Offset] );
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.
|
||||||||||||
DDX |
[in] The rate of change of the surface geometry in the x direction. The argument type is dependent on the texture-object type.
|
||||||||||||
DDY |
[in] The rate of change of the surface geometry in the y direction. The argument type is dependent on the texture-object type.
|
||||||||||||
Offset |
[in] An optional texture coordinate offset, which can be used for any texture-object types. The offset is applied to the location before sampling. Use an offset only at an integer miplevel; otherwise, you may get results that do not translate well to hardware. The argument type is dependent on the texture-object type. For more info, seeApplying Integer 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 MotionBlur.fx file in the MotionBlur10 Sample.
// Object Declarations
Texture2D g_txDiffuse;
SamplerState g_samLinear
{
Filter = ANISOTROPIC;
MaxAnisotropy = 8;
AddressU = Wrap;
AddressV = Wrap;
};
struct VSSceneOut
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
float2 Tex : TEXCOORD;
float2 Aniso : ANISOTROPY;
};
float4 PSSceneMain( VSSceneOut Input ) : SV_TARGET
{
float2 ddx = Input.Aniso;
float2 ddy = Input.Aniso;
// Shader body calling the intrinsic function
float4 diff = g_txDiffuse.SampleGrad( g_samLinear, Input.Tex, ddx, ddy);
...
}