Sign in to follow this  

sphere tangent in a specific point

This topic is 3627 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

I sucefully implemented normal mapping for triangles in my raytracer, and was thinking to add it to spheres as well, but I don't know how to compute the tangent of the intersection point on the sphere. I was not able to find useful resources, except a post here on gamedev. Since the approach suggested was not trivial and I don't even know if it is suited for texture mapping, and since I'm mainly targeting polygons anyway, I would like to ask for a (relatively) easy way to accomplish this. Otherwise I will skip tangents for sphere (wich are used only for test scenes untill a proper geometry loader is ready). Thank you.

Share this post


Link to post
Share on other sites
You can compute a tangent space given any normal using the following procedure

given that normal is not lying on the y axis. project onto xz plane, rotate 90 degrees around y axis and normalise, then take cross of this with the normal to give the basis.

i.e. along the lines of

normal = y given that y.x!=0&&y.z!=0
double iy = 1/sqrt(y.x*y.x+y.z*y.z);
vec x (-y.z*iy,0,y.x*iy);
vec z = x cross y;

then you can build the tangent from the 3 vectors

may need to switch signs depending on your system. This is what i do in my ray tracer for whatever type of object it is if it cannot be precomputed like with a triangle or other.

i find this is best done in object space so that the same object will appear the same when normal mapped independant of its rotation, remember theres an infinite number of tangent spaces given only a normal.

Share this post


Link to post
Share on other sites
Here's a formal way that works in all cases (from the journal of graphics tools):

given u = (x,y,z)

v' = ( 0,-z, y ) if x is the smallest
( -z, 0, x ) if y is the smallest
( -y, x, 0 ) if z is the smallest
v = normalize(v')
w = u X v

Note that v,w won't be continuous on on a sphere for example as that just isn't possible.


Cheers!

Eric Penner

Share this post


Link to post
Share on other sites
Quote:
Original post by luca-deltodesco
You can compute a tangent space given any normal using the following procedure

given that normal is not lying on the y axis. project onto xz plane, rotate 90 degrees around y axis and normalise, then take cross of this with the normal to give the basis.

i.e. along the lines of

normal = y given that y.x!=0&&y.z!=0
double iy = 1/sqrt(y.x*y.x+y.z*y.z);
vec x (-y.z*iy,0,y.x*iy);
vec z = x cross y;

then you can build the tangent from the 3 vectors

may need to switch signs depending on your system. This is what i do in my ray tracer for whatever type of object it is if it cannot be precomputed like with a triangle or other.

i find this is best done in object space so that the same object will appear the same when normal mapped independant of its rotation, remember theres an infinite number of tangent spaces given only a normal.


Thank you for answering. Just a question: what is the vector y? Is this method suited for texturing? I ask because I don't see references to texturing axis...

Quote:

Here's a formal way that works in all cases (from the journal of graphics tools):

given u = (x,y,z)

v' = ( 0,-z, y ) if x is the smallest
( -z, 0, x ) if y is the smallest
( -y, x, 0 ) if z is the smallest
v = normalize(v')
w = u X v


I suppose that u is the intersection point. But since it is a point (in world space) this means that I have to use (point - sphereposition) instead?

I thought a bit about that, and wonder if the following could work:
Let north be the vector that points to the north pole (set in the constructor and used for texturing).
- vector tonorth = point - sphereposition + north * radius)
- vector bitangent = normal.Cross(north);
- vector tangent = normal.Cross(bitangent);

It seems to easy, but if I don't miss something it could work (at least with a couple of minor changes)... what do you think about this?

[Edited by - cignox1 on January 10, 2008 6:25:43 AM]

Share this post


Link to post
Share on other sites

This topic is 3627 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this