dFdx, dFdy

metamax's icon

How are partial derivatives expressed in Gen Expr?

ex. shader code:3vec3 nor = normalize( vec3( dFdx(s.x), 0.02, dFdy(s.x) ) );

Is [delta] or [change] used in place of the dFd functions ? If so, how?
All of the following return errors that the operators are not properly defined:

nor = normalize(delta(s.x), 0.02, delta(s.x));
nor = normalize(vec(delta(s.x), 0.02, delta(s.x)));
nor = normalize(change(s.x), 0.02, change(s.x));
nor = normalize(vec(change(s.x), 0.02, change(s.x)));

metamax's icon

Can I do this within Gen? (calculate the slope of a function across the whole matrix simultaneously) Or do I need to do something like output the matrix and re-input it back into the 2nd outlet to sample? I really have no idea how to approach this.. and it doesn't help that I don't understand the math. :/ Thanks for taking the time to read this.

Rob Ramirez's icon
Max Patch
Copy patch and select New From Clipboard in Max.

hi metamax. dFdx/y are not supported operators in gen. delta and change are only supported in gen~ (not jit.gen).
getting your history in jit.gen is simply storing the output in a jit.matrix @thru 0, and banging that matrix back into an inlet:

metamax's icon

Rob, thanks for taking a look. I saw your @thru example in my searches but I don't understand how it translates to calculating derivatives. That said, I suspect there are some other structural features of the shader that might need similar treatment so I shelved it for now.

For future reference, in the above example, you are saying to output s and feed the output back into the 2nd outlet via [jit.matrix @thru 1] and then sample in2.. but how? Maybe a pseudocode example? Thanks again.