   Normals for Primitives
  Hello,I am having trouble calculating some primitives' normals for my ray tracer:One is for a plane (lol yes i know) which gives the following result:The equation for the intersection between ray and plane is: t = -(A*xo + B*yo + C*zo + D) / (A*xd + B*yd + C*zd)A*xo = position(of point in plane)*ray's origin similar for B and C, D is the distanceand I use as its normal (A,B,C) which is the position.The other normal is for a cone(infinite on y):which appears as a hourglass :PCone equation with ray:a=xD^2+yD^2-zD^2, b=2*(xExD+yEyD-zEzD), and c=xE^2+yE^2-zE^2.will be used to find the discriminantwith normal calculation:Nx = (ix - x) / yNy = 0Nz = (iz - z) / ysimilar to a cylinder as I thought it would work.   
  any suggestions of websites or books I should check out?   ;  Also I m wondering if there is a general way of calculating the normals if you have the algebraic equation of any primitive, whether that is a sphere or a torus etc   ;Quote:Original post by Tipotas688any suggestions of websites or books I should check out?To be honest, it is hard to understand your question, even harder to see any question at all in your initial post. I see some formulas, some images I don't really understand and some formulas about raytracing while you are talking about calculating normals...Well, to clean it up:1. You are writing a simple raytracer, which works with simple forms like spheres, torus, planes ? 2. You are able to determine the hit-location of a given ray and a given form ?3. Now you want to calculate the normal at the hit-location depending on the given form, right ?Well, for planes the normal is constant, for sphere it is the normalized vector from the sphere center to the hit location. I think there will be other simple methods to determine a normal for different form. Is this your question ?   ;  If you have a parametric description of your surface, the derivative with respect to each of the two parameters will give you two vectors that are tangent to the surface; the cross product of those vectors is a normal.I you have an implicit-function formula for your surface, the gradient of the function is a normal.;  My initial question was: how do I find the normals for primitive types, eg. plane, cone, torus etc.What I have that I can use is: the equations of those primitive types, eg. plane is Ax+By+Cz+D=0, since I thought they are directly connected.I have the normals for spheres for example working as I knew that it was the normalized vector of the intersection to the center of the sphere, but I can't say that I know for other primitives. I did try what I posted on my first post but got those wrong pictures as result.Quote:1. You are writing a simple raytracer, which works with simple forms like spheres, torus, planes ? 2. You are able to determine the hit-location of a given ray and a given form ?3. Now you want to calculate the normal at the hit-location depending on the given form, right ?1. I am2. Yep3. Yep   ;Quote:What I have that I can use is: the equations of those primitive types, eg. plane is Ax+By+Cz+D=0, since I thought they are directly connected.normalize the vector <A, B, C>alvaro gave you the answer for the rest.   ;  I zoom out to see clearer:With normalizing (A,B,C) I get:Without normalizing (A,B,C) I get:That should be a plane :)That how I calculate the plane's intersection with the raysfloat Sx = ray.origin.x * position.x;float Sy = ray.origin.y * position.y;float Sz = ray.origin.z * position.z;float Vx = ray.direction.x * position.x;float Vy = ray.direction.y * position.y;float Vz = ray.direction.z * position.z;float S = Sx + Sy + Sz;float V = Vx + Vy + Vz;float D = (-radius - S)/V;Quote:If you have a parametric description of your surface, the derivative with respect to each of the two parameters will give you two vectors that are tangent to the surface; the cross product of those vectors is a normal.I you have an implicit-function formula for your surface, the gradient of the function is a normal.Yeah this is how I should be doing it, I just have a bit of trouble on how to calculate those two vectors. And I am searching at the moment how to calculate the gradient as I haven't encountered it before :)EDIT: I knew gradients in the end, I just had to translate it in my language first ;)[Edited by - Tipotas688 on April 15, 2010 2:51:20 AM];  Your plane intersection calculation seems off. You should have something like:distance = (planeDistance - DotProduct(rayOrig, planeNormal)) / DotProduct(rayNormal, planeNormal)   