   Derivative of 3D Function ?
  Hi guys,In my book it says this:quote:If you have a function that maps a scalar field to a value (like a fractal noise value, or a perturbed sine), you can take the derivative of the scalar function in all three directions (x, y, z,) add these values to the surface normal, then renormalize it.So here is how I''m doing it with a noise function:Vector3D vNormal=GetNormal(x,y,z); // I got the normal of the point on the surface here.float vn=Noise(x,y,z); // I got the noise value here.// now I think I get the derivative like this:Vector3D vDeriv;float epsilon=0.000001;vDeriv.x=Noise(x+epsilon,y,z)-vn;vDeriv.y=Noise(x,y+epsilon,z)-vn;vDeriv.z=Noise(x,y,z+epsilon)-vn;// then I normalize it (see note below)Normalize(vDeriv);// now I add it to the surface normal and renormalizevNormal += vDeriv;Normalize(vNormal);Am I doing it right ? Is that how I get the derivative ? It looks good when I render but it might be all wrong. Also, if I don''t normalize the vDeriv before I add it to the vNormal nothing seems to change.I''m doing this for bump mapping, I change the normals then ray trace it.Thanks. 
  That is not the derivative, you are obtaining the change in each direction... you must divide by epsilon to get the derivative. Incidentally.. what you are calculating is called the gradient of the scalar field... it is an example of vector calculus.. which in general boils down to using the dell operation, which is just a vector...(d/dx, d/dy, d/dz)if you dot (multiply) a scalar field with it.. you get a vector field.. called Grad (the gradient of the field).If you dot it with a vector field.. you get a scalar field.. called Div (the divergence of the field.. in some way measuring "spread" of the field from a point).If you cross it with a vector field.. you get a vector field.. called Curl (a vector field representative of the local rotation (or vorticity as it''s known more generally) of the field).Sorry to be going off on a bit of a tangent here... but anyway.. yes, divide by epsilon. There might be a way to avoid renormalizing sqrt by taking a dot products... but I can''t exactly think of how atm. Anyway, hope this all helps . ;  Thanks dmounty.So I go like this instead:vDeriv.x = (Noise(x+epsilon,y,z)-vn)/epsilon;// same for y and zI still subtract the vn though right ? I''ll try that now. Maybe I don''t have to normalize the vDeriv vector now, I was wondering why I had to in the first place. It''s no big deal though because I''m not doing this in real time.I''m glad you went off and explained it, I guess I should read up on vector calculus. Damn, how did you learn all that ?Thanks again.;  Erm... The derivative of the field is the same thing as the gradient of the field... In both cases you would need to divide by epsilon, the way you are doing it.But since you are going to be normalising the vector you get anyway, there is no point (dividing by epsilon will just change the length of the vector, not the direction).What i find a little strange is that you are adding these values to the normal of your surface (how did you calculate those normals)?Isn''t the whole point of this to calculate the normal in the first place? You can use the normalised derivative/gradient as the normal without adding it to anything else...And finally, the way you are calculating the derivative isn''t very good in my opinion. You can do it analytically (time to bust out the pen and paper) if you know what the field function is (what is inside your Noise() function?). The advantages of doing it analytically is that your answer will be exactly correct, and also will be faster to calculate.Sorry for the fragmented answer :x ;  Hi SpaceDude,My goal is to render hypertexture and I wanted to start off slowly and make sure the components of my program were working properly.First I made a simple ray tracer with a Phong illumination model, that''s working nicely. Then I made ''solid texture'', that''s 3D Perlin Noise for the most part, which is also working nicely.So then I decided to ray trace a bump mapped sphere. I used the 3D Perlin Noise as the bump function. So here is what I do:1) see if the camera ray intersects a sphere2) if it does then calculate the point of intersection3) compute the normal as the sphere center to the point4) compute a noise value at the intersection point-*- above works great -*--*- below is newbie part for me -*-5) compute the derivative of the noise function like I''ve been asking about6) multiply the derivative by a bump factor (0.0 = no bump) and add it to the surface normal7) then use the lighting model to light it upI really don''t know what I''m doing in steps 5 and 6. Also, if I don''t add to the original normal it doesn''t look like a sphere, just a circle outline.It''s really hard to find information on this stuff.;  Hi.I don''t think you should add the normal vectors.If vDeriv returns the vector in object space, then nothing more needs to be done, just use vDeriv. (I don''t think this is the case)If vDeriv is independent of the actual surface, then you need to rotate it so that it is in the same reference frame (tangent space) as the intersection point on the sphere.  This would be about the same as you''d have to do for dot3 bump mapping.The tangent space frame might look something like:tz = sphere normaltx = tangent to the surface in the clockwise latitude direction.ty = tz cross txbuild a rotation matrix out of those three vectors (don''t forget to normalize), then inverse-rotate (mul by the transpose of the matrix) your original vDeriv.lonesock Piranha are people too. ;  Ok it makes more sense now quote:Original post by Endemoniada  5) compute the derivative of the noise function like I''ve been asking aboutCan you tell us what your noise function is please? What is inside your function "Noise(x, y, z)"? ;quote:you can take the derivative of the scalar function in all three directions (x, y, z,)The scalar function is Noise(). You need to take the derivative of it. That does not mean doing something to its return value, it means the function itself. I think you need to write something like DNoise() which is a 1st-derivative version of Noise. So if Noise() returns, I don''t know, sin(x) + cos(z), then DNoise returns cos(x) - sin(z).   ~CGameProgrammer( ); -- Post screenshots of your projects. There''s already 134 screenshot posts. ;  Yeah, but what he is doing, is taking an output value.. and an output value at a slightly perturbed value in each direction.. and dividing by the perturbation. This obtains an approximation to the derivative, in the same way as any numerical integrator/differentiator does.EDIT: In the limit as epsilon tends to 0, this IS differentiation   [edited by - dmounty on February 13, 2004 8:40:40 AM];  Oh, OK. But if the function is simple enough, it would be better taking the functional derivative, wouldn't it? Right now he's calling Noise() four times, but it could just be called once (or twice, at most) if he took the actual derivative, from what I understand. No, the function can't possibly be slow enough that this would actually matter, but I'm just speaking theoretically.  ~CGameProgrammer( );signature test blah blah blah [edited by - CGameProgrammer on February 13, 2004 11:40:30 PM] [edited by - CGameProgrammer on February 13, 2004 11:40:50 PM] [edited by - CGameProgrammer on February 13, 2004 11:41:19 PM]