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...
Yes, ray differentials are the way to go. The Paper by Igehy introduces them for the use case of filtered texture lookups. When generating the primary rays, you initialise the differentials to reflect the pixel footprint. As the ray progresses through the scene, you update the differentials at every bounce. When it comes to a texture lookup, you need to project the differentials to your s,t texture space (aka UV), typically by going to surface parameter space as an intermediate.

The case that you mention, the calculation of derivatives for a ray surface intersection, is implemented in pbrt:
Here the surface is described by a point p, normal n and two tangent vectors dPdu and dPdv. The resulting dudx, dudy, dvdx and dvdy are the differentials of the u, v parameters of the surface with respect to screen space x and y. Conversion from surface parameters to texture space happens here.