Jump to content
  • Advertisement
Sign in to follow this  
cignox1

sphere tangent in a specific point

This topic is 3935 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
Advertisement
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
Apparently the method I tried works. Thank you all, and if you think that my method is for some reason wrong, please tell me!

Thank you again!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!