Windows Dev Center

Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.


Samples a 2D texture using a gradient to select the mip level.

ret tex2Dgrad(s, t, ddx, ddy)





[in] The sampler state.


[in] The texture coordinates.


[in] Rate of change of the surface geometry in the x direction.


[in] Rate of change of the surface geometry in the y direction.


Return Value

The value of the texture data.

Type Description

NameIn/Out Template Type Component Type Size
sinobject sampler2D 1
tinvector float 2
ddxinvector float 2
ddyinvector float 2
retoutvector float 4


Minimum Shader Model

This function is supported in the following shader models.

Shader ModelSupported
Shader Model 4 yes (pixel shader only)
Shader Model 3 (DirectX HLSL) yes¹ (pixel shader only)
Shader Model 2 (DirectX HLSL) yes² (pixel shader only)
Shader Model 1 (DirectX HLSL) no


  1. Significant code reordering is done to move gradient computations outside of flow control.
  2. If the D3DPSHADERCAPS2_0 cap is set with D3DD3DPSHADERCAPS2_0_GRADIENTINSTRUCTIONS, the compiler maps this function to texldd.


When flow control is present in a shader, the result of a gradient calculation requested inside a given branch path is ambiguous when adjacent pixels may go down separate flow control paths. Therefore, it is deemed illegal to use any pixel shader operation that requests a gradient calculation to occur at a location that is inside a flow control construct which could vary across pixels for a given primitive being rasterized. If either side of an if statement with the branch attribute uses a gradient function a compiler error may be generated. See if Statement (DirectX HLSL).

See also

Intrinsic Functions (DirectX HLSL)



Ajouts de la communauté

© 2015 Microsoft