title: HLSL: Which DDX DDY are expected for TextureCube.SampleGrad()
body: <p>I am wondering which DDX DDY values the SampleGrad() function expects for a TextureCube object.
  I know that it's the change in UV coordinates for 2D textures. So I thought, it would be the change in the direction in this case. However, this does not seem to be the case.</p>
  
  <p>I get different results if I try to use the Sample function vs. SampleGrad:</p>
  
  <hr>
  
  <p>Sample:</p>
  
  <pre><code>// calculate reflected ray
  float3 reflRay = reflect(-viewDir, normal);
  // reflection map lookup
  return reflectionMap.Sample(linearSampler, reflRay);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/l9147.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l9147.png" alt="correct"></a></p>
  
  <hr>
  
  <p>SampleGrad:</p>
  
  <pre><code>// calculate reflected ray
  float3 reflRay = reflect(-viewDir, normal);
  // reflection map lookup
  float3 dxr = ddx(reflRay);
  float3 dyr = ddy(reflRay);
  return reflectionMap.SampleGrad(linearSampler, reflRay, dxr, dyr);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/t79G6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t79G6.png" alt="wrong"></a></p>