6
$\begingroup$

This question bothers me since the first time I got to know about derivatives in pixel shader. Suppose we have a 2d texture:

5   10  20  30
6   11  50  100

If I correctly understand, the derivatives for the pixel [0, 0] will be:

  • dx = pixel[1, 0] - pixel[0, 0] = 10 - 5 = 5
  • dy = pixel[0, 1] - pixel[0, 0] = 6 - 5 = 1

And this will be 100% guaranteed because gpu executes pixels in 2x2 block. But what is the dx-derivative for the pixel[1, 0]? The pixel right to it is from another block which maybe not executed yet? And what about pixel[3, 0]? It doesn't have a right neighbor at all!

$\endgroup$

1 Answer 1

7
$\begingroup$

In Vulkan the shader only looks at each 2x2 and won't attempt to look beyond the neighbourhood: http://vulkan-spec-chunked.ahcox.com/ch15s05.html

$$dPdx_{0,0}=dPdx_{1, 0} = P_{1,0}−P_{0,0}\\ dPdx_{2,0}=dPdx_{3, 0} = P_{3,0}−P_{2,0}$$

For times when a pixel would fall off the geometry the shader is invoked for the values it would have if the triangle extended a pixel further.

$\endgroup$
1
  • $\begingroup$ Thanks. After reading of Vulkan doc I could find the similar for directx fine and coarse derivatives. $\endgroup$ Commented Mar 30, 2016 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.