Sign in to follow this  

ddx ddy with a sampler returned value

Recommended Posts

I wonder if it is possible to use partial derivates, namely ddx and ddy, in GLSL, with a value returned by texture2D function.


Since ddx and ddy can operate only on interpolated fragment function inputs (true?), what would be most apropriate way to retrieve the texture samples at neighboiring pixels, is the only solution to fire multiple sampling functions with derived texture coordinates?


I do not want GPU to perform this:


sample bottom closest mipmap 1 texel- travel to upper closest mipmap for 1 texel - weight- repeat four times


rather pefrom this


sample bottom closest mipmap 4 neigbouring texels- travel to upper closest mipmap for other 4 texels- weight- done




Share this post

Link to post
Share on other sites

dfdx and dfdy operate on any value you give it, it doesn't matter where it comes from, and it's not limited to the fragment shader inputs. The only thing you are not allowed to do is to assemble higher order statements of some kind (e.g. dfdx(dfdy(val))).


When you call the function, your GPU has information on the value given to the function in all invocations of the fragment shader in a certain neighborhood (e.g. 2x2 fragment grid). This information is what the GPU uses to give you a derivate using differencing in the pixel neighborhood.

Edited by agleed

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this