# Ray tracing - partial derivatives for texture lookup

I'm doing some ray tracing on GPU using a fragment shader...

How can I calculate texture coordinates partial derivatives with respect to screen coordinates so I could perform filtered texture lookup with textureGrad GLSL function?

Do I need to use ray differentials?

If yes, then how?

Example explaining derivatives calculation for ray-plane intersection (ray described using origin and direction normal vector, plane using one point laying on a plane and normal vector) would be nice, although pointers for general case would also be appreciated...

• I'm not actually sure what the usual way to do this is, but if you could somehow know the size of a pixel at this intersection, you could add epsilons to the hit position to get numeric derivatives and use that pixel size to know what mip level to use. – Alan Wolfe Dec 2 '17 at 15:59
• This question is related and has some good info in the answers: stackoverflow.com/q/1813303/2817105 – Alan Wolfe Dec 2 '17 at 16:01