When you invoke a texture sample operation on the GPU, the GPU does the following:
- The texture request is broadcasted to neighboring pixels in a 2x2 quad fragment
- The partial derivatives of the texture coordinates with respect to x and y are computed
- These partials are used to compute the MIP level (accounting for level of detail and anisotropic filtering)
- Finally, the relevant texels are fetched (possibly from a texture cache) and interpolated to produce the final sampled result
Now, suppose you have different neighboring fragments that branch (say due to some material or something) such that on invocation of that shader, sample requests to different textures are made at the same time. You run into a problem if the tiling rates for these textures are different which will break the MIP selection (the incoherence of this undefined operation will result in a noisy render). The solution is to query for the gradients yourself using dFdx and dFdy outside of the branch and use the textureGrad
function within the branch, applying the correct tiling multipliers to your gradients.
Related
side-bar lists the score of questions, so up- or down-voting a question is usually more constructive than complaining about the quality in a comment. Even low quality questions may actually generate useful answers from time to time... but if enough people determine the question to be sufficiently low quality or a duplicate it can be put on hold to prevent answers. That is really the appropriate way to deal with these sorts of things, and a less obnoxious comment telling the OP why their question is low-quality and may not generate answers. – Buffum