Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the fwidth glsl function actually used for?

Every time I drunk browse so I see an unanswered fwidth question. And it makes me wonder what it actually was designed to do.

Reading the docs it is: abs(dFdx(p)) + abs(dFdy(p))

So it is not classic mip selection which is max(dx,dy). Is it for alternative mip selection? But I fail to find a case where abs(dx) + abs(dy) would be better. There must be some siggraph paper or common algorithm I am completely missing that uses that function. And it must be really popular because it made it into GLSL. The only thing I can think of is some 2d post filter I am missing.
But what? I am sure somebody here knows and once you see it it's obvious. So: What algorithm uses abs(dx) + abs(dy)?

like image 957
starmole Avatar asked Jul 23 '11 13:07

starmole


2 Answers

You're actually quite on the money with the 2D filtering suggestion. Any filter which relies on some sort of metric for the rate of change between a pixel and its neighbors could benefit from this function.

Examples would be anti-aliasing, edge detection, anisotropic filtering. I'm sure there are more examples one could think of.

It seems from your question and comments that you expect there to be a mind-blowing reason for this function to be included in GLSL. I would just say that it's a useful function to have. Perhaps someone with more in-depth knowledge about the actual internals of this function could provide more detail on what happens behind the scenes (i.e. if there is any performance improvement over a handwritten equivalent with dFdx and dFdy).

like image 53
Bart Avatar answered Sep 30 '22 09:09

Bart


this is the total derivative for the function DF = dF/dx*dx + dF/dy*dy .see the similarity? fWidth >= DF or in words fWidth is maximum possible change in a fragment variable F, between any of a current fragmants neighboring pixels. ie the 8 surrounding pixels in the 3x3 neighborhood.

like image 45
TimW Avatar answered Sep 30 '22 09:09

TimW