HLSL tex2D () - where does the gradient come from?

When I take the texture in the pixel shader, the texture unit needs to select mipmap based on the texture gradient around the shaded pixel.

There is a tex2Dgrad() function tex2Dgrad() that allows me to provide gradient information manually and tex2Dlod() , which allows me to select mipmap manually, but if I just call tex2D() , where will the additional information about the gradient be?

tex2D() is the most common case for texture matching used in most shaders, but I don’t know where this gradient tex2D() from. Obviously, Mipmapping works, so it must come from somewhere.

I want to use the texture as a lookup table in the pixel shader using the calculated U and V coordinates, but I don’t want tex2D() have no unexpected “magic” .

Do I need to use tex2Dlod() to avoid this? I read that tex2Dlod() slower than tex2D() .

+4
source share
1 answer
GPUs

a “square” of 4 pixels is extracted at a time, and the gradients used to obtain the texture come from finite differences calculated from adjacent pairs of pixels. This is how the GPU can generate partial derivatives even for arbitrary expressions in a pixel shader. The tex2Dgrad function can be useful if you can calculate more accurate analytical derivatives for the values ​​that you pass as texture coordinates.

+1
source

Source: https://habr.com/ru/post/1387239/


All Articles