Jump to content
  • Advertisement
Sign in to follow this  
Tipotas688

Normals for Primitives

This topic is 2987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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: Photobucket 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 distance and I use as its normal (A,B,C) which is the position. The other normal is for a cone(infinite on y): Photobucket which appears as a hourglass :P Cone 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 discriminant with normal calculation: Nx = (ix - x) / y Ny = 0 Nz = (iz - z) / y similar to a cylinder as I thought it would work.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Quote:
Original post by Tipotas688
any 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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 am
2. Yep
3. Yep

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I zoom out to see clearer:

With normalizing (A,B,C) I get:

Photobucket

Without normalizing (A,B,C) I get:

Photobucket

That should be a plane :)
That how I calculate the plane's intersection with the rays

float 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]

Share this post


Link to post
Share on other sites
Your plane intersection calculation seems off. You should have something like:

distance = (planeDistance - DotProduct(rayOrig, planeNormal)) / DotProduct(rayNormal, planeNormal)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!