Gradients of signed distance function
category: general [glöplog]
Does anyone know how to calculate the gradient of any given signed distance function? I have it in the form f(x,y,z)...is there a generalized method to finding the derivative given a point residing on the implicit surface?
Nevermind, found what I was looking for :) You can get a good estimate with the following equations:
F0 = F(x,y,z)
Fx = F(x + e,y,z)
Fy = F(x,y + e,z)
Fz = F(x,y,z + e)
Fn = normalize(Fx-F0,Fy-F0,Fz-F0)
:)
F0 = F(x,y,z)
Fx = F(x + e,y,z)
Fy = F(x,y + e,z)
Fz = F(x,y,z + e)
Fn = normalize(Fx-F0,Fy-F0,Fz-F0)
:)
...Just make sure e is tiny ;)
eh, what? You may want to look up basic numerical differentiation.
http://en.wikipedia.org/wiki/Numerical_derivative
http://en.wikipedia.org/wiki/Numerical_derivative
WHAT DO YOU TEACH IN SCHOOLS NOWADAYS?
Btw, the solution is
Fx=(F(x+h,y,z)-F(x-h,y,z))/2h
etc...
And the gradient is not normalized.
Btw, the solution is
Fx=(F(x+h,y,z)-F(x-h,y,z))/2h
etc...
And the gradient is not normalized.
What Calexico said!
I usually prefer the 6 point gradient (Calexico's) as it's more accurate (central differences). You can read it in page 46 of
http://iquilezles.org/www/material/nvscene2008/rwwtt.pdf
and also how do add bump (procedural) map to the distance field surface. Note that unsigned distance fields will give inaccurate normals when the sampling points fall inside the objects, so it's almost mandatory to use signed fields for good quality images.
Another trick, if you are having LOD in your distance function (further away objects get a simplified function), then you can also make "e" bigger with the distance, than can reduce aliasing a lot.
Finally, I also I join the "What do you teach in schools nowadays?"
http://iquilezles.org/www/material/nvscene2008/rwwtt.pdf
and also how do add bump (procedural) map to the distance field surface. Note that unsigned distance fields will give inaccurate normals when the sampling points fall inside the objects, so it's almost mandatory to use signed fields for good quality images.
Another trick, if you are having LOD in your distance function (further away objects get a simplified function), then you can also make "e" bigger with the distance, than can reduce aliasing a lot.
Finally, I also I join the "What do you teach in schools nowadays?"
ferris' solution is actually okay if you replace the normalize by "(1/e)*". symmetric differences have a better approximation order for smooth functions, but with the 3 forward differences you only need 4 samples instead of 6, which can mean quite a speed boost for distance functions that are expensive to sample. (if you use a newton-like scheme, you need F(x,y,z) anyway, and it's 4 vs. 7 samples).
also, all higher-order derivative approximations assume higher-order smoothness of the target function. cheaper approximations can actually perform better when that assumption doesn't hold.
also, all higher-order derivative approximations assume higher-order smoothness of the target function. cheaper approximations can actually perform better when that assumption doesn't hold.
Wow, I lost my faith in the American education system with this question of yours Jake :P.
Decipher: You had some to begin with?
I'm aware it's not normalized :P
And hey lay off, I thought there would be some special case for signed distance functions rather than other types of functions. Besides, gradients of 3D surfaces I thought weren't taught until college anyways, but whatever.
And hey lay off, I thought there would be some special case for signed distance functions rather than other types of functions. Besides, gradients of 3D surfaces I thought weren't taught until college anyways, but whatever.
...seems like you're all forgetting I have alot of school left :P
..And I forgot to mention thanks :)
ryg: The problem is that you actually translate your function by h/2 for the "single sided" differential. This is fine if you work on continuous data sets or functions where you can use a vey small value of h, but may become quite an issue if you work with discrete, sampled data. Ok, granted, that is not much of an issues with CG, but I have seen quite a bit of RL applications where this had interesting consequences (oscillations...)
The point is, more likely, if you're taught the idea of what differentiation is and the difference quotient, the whole thing should be rather obvious. Then again, when gradients were introduced in my college math classes, a lot of people were baffled..
Quote:
WHAT DO YOU TEACH IN SCHOOLS NOWADAYS?
Quote:
Wow, I lost my faith in the American education system with this question of yours Jake :P.
I'm offended. I can't even derive e^x correctly, and still I have an M.Sc. And there's nothing wrong with that!
M.Sc in what? :)
computer science, but does it matter?
then again, why would you learn how to derive if there's software for it? :D
Preacher: I'm not in college yet :)
If you're from the US, college in many European countries actually means High School and not University which you guys call "College". :)
And besides, in Europe, we're taught this stuff in secondary school ! Which I _think_ Americans call "Grade School" :P
And besides, in Europe, we're taught this stuff in secondary school ! Which I _think_ Americans call "Grade School" :P
Secondary school is our high school, and our college is also called post-secondary...so it's not QUITE grade school :P :D
Quote:
ps 3.0? Probably over 2048^3; it's pretty big
Ferris is further showing us how US mathematics work! Kidding mate :).
But seriously, we learnt differentiation in 10th grade which was two years ago. I am in sheer wonder what the heck were you learning in tenth grade?
Afterall, does it even matter what you call it if it solves your problem?