# 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. Dec 2 '17 at 15:59
• This question is related and has some good info in the answers: stackoverflow.com/q/1813303/2817105 Dec 2 '17 at 16:01
{"ft_lang_label":"__label__en","ft_lang_prob":0.9030486,"math_prob":0.7295423,"size":549,"snap":"2021-43-2021-49","text_gpt3_token_len":100,"char_repetition_ratio":0.10458715,"word_repetition_ratio":0.0,"special_character_ratio":0.18032786,"punctuation_ratio":0.12371134,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9751939,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-09T01:29:19Z\",\"WARC-Record-ID\":\"<urn:uuid:0b632778-0e77-4c6f-8677-7f6528256cab>\",\"Content-Length\":\"140218\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:93c876a0-a779-4fe3-9610-a8576abbcf11>\",\"WARC-Concurrent-To\":\"<urn:uuid:0560992d-38e1-468c-85a7-efc9deecda53>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://computergraphics.stackexchange.com/questions/5939/ray-tracing-partial-derivatives-for-texture-lookup\",\"WARC-Payload-Digest\":\"sha1:YP3KKTZGSJ63PNTX26IFYSXRABMDQRT3\",\"WARC-Block-Digest\":\"sha1:J3YJ4DE6KJ4NZ5G2CV3VGJAKIIRYFVCW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363641.20_warc_CC-MAIN-20211209000407-20211209030407-00165.warc.gz\"}"}