I am trying to understand the dFdx()
and dFdy()
functions in GLSL.
I understand the following:
- The derivative is the rate of change
- The partial derivative of a function with two parameters is when you differentiate the function while keeping one of the parameters constant.
dFdx()
anddFdy()
find the rate that a value changes between the current fragment and a neighboring fragment.
I don't understand what the rate of change is referring to. Is it the rate of change of fragment coordinates?
Could it possibly be that you can find the rate of change of an arbitrary variable between two invocations of the fragment shader? Are the shader invocations "reading" variables from neighboring invocations? For a (simplistic) example:
// invocation for fragment 1
float x = 1.0;
float d = dFdx(x);
// invocation for fragment next to fragment 1 along the x axis.
float x = 2.0;
float d = dFdx(x);
Would d
be -1.0 and 1.0 respectively?