What and why about GLSL textureGrad
Asked Answered
E

1

9

So I read the OpenGL info page on textureGrad but it doesn't really explain anything. So you can explicitly specify the partial derivatives of P relative to X and Y

  • What does this actually do?
  • How does OpenGL calculate the derivatives when you sample without specific partial derivatives?
  • Why does texture sampling use or even need derivatives?

My mind has been blown.

Earthbound answered 9/1, 2014 at 1:20 Comment(8)
Because I tried, with little luck. I was hoping someone on here would actually understand it and be able to explain. You know, like the site is for?Earthbound
This document will thoroughly answer all your questions: Paul S. Heckbert. Fundamentals of texture mapping and image warping. Technical report, 1989 ------------------------------------------------------------------------Killifish
I don't get why my comments got removed, am I really the only one here on Stack Overflow actually reading the guidelines and/or help/tour page? ... Stack Overflow Quote: "Focus on questions about an actual problem you have faced. Include details about what you have tried and exactly what you are trying to do."Tellford
@Vallentin: I believe it has to do with the general tone in your comments as of late... what you stated is very much true, but not particularly constructive. Even so, there are plenty of quality questions on Stack Overflow that pertain more to the purpose/function of a new/under-documented feature of some language/API than actual coding problems. I tend to answer questions that are not a perfect fit for SO's model in comments; it may not be right for a full-blown answer, but if I can help at all I generally will.Buffum
To that end, the 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
@AndonM.Coleman I can agree with some of that! Though the reason I comment, telling them that this is not what SO is for, is because well, if didn't know that, then my comment would be helpful! If I owned Stack Exchange, I would delete all questions which didn't follow the guidelines to whatever site that might be! (SO, GameDev, Math, etc.) ... Just because something is hard to learn (or...) doesn't mean that people can disobey rules of a certain site... That's like saying, well if you're in a hurry then it's okay to run a red light in traffic!Tellford
@Vallentin Honestly, my question IS very open ended and generalized, but I needed help and SO is normally very helpful with stuff like this. I DID over-react though so my bad.Earthbound
Possible duplicate of What is, in simple terms, textureGrad()?Estoppel
D
2

When you invoke a texture sample operation on the GPU, the GPU does the following:

  1. The texture request is broadcasted to neighboring pixels in a 2x2 quad fragment
  2. The partial derivatives of the texture coordinates with respect to x and y are computed
  3. These partials are used to compute the MIP level (accounting for level of detail and anisotropic filtering)
  4. 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.

Diocese answered 23/7, 2018 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.