Jump to content
  • Advertisement
Sign in to follow this  
shadone

texturing on sphere

This topic is 3326 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 there, i've been trying to write my first ray tracer and i have come to the point of texture mapping. i have a sphere to cover with a checkerboard texture and im stuck at one point. i know the intersection point between the ray and the sphere and im trying to calculate u and v, the texture coordinates. im using a frame size of 300x300 and 0,0,0 point is the left-most bottom pixel of the frame. im trying to find out an exact formula for u and v but im desperate, i can't find a working one..can anyone help please? thanks..

Share this post


Link to post
Share on other sites
Advertisement
It depends on your texture mapping scheme. I'll describe the usual "latitude-longitude" projection here.

Say your sphere is defined by,

Position: c = (cx, cy, cz)
Radius: r
Orientation: R (rotation matrix)

and you've found a point p on the sphere using a ray-sphere intersection test. Then u,v coordinates for p can be found by
1. Computing d = R-1(p-c).
2. Converting d to spherical coordinates (r, theta, phi).

The u,v coordinates are (theta,phi).

More on step 2: It's done using a two-argument arctangent function. Google "spherical coordinates" and you'll figure it out.

Share this post


Link to post
Share on other sites
did you try with this formula..

int i;
for( i = 0; i < numOfVertices; i++ )
{
vertex->u = vertex->nx / (sqrt(vertex->nx*vertex->nx + vertex->ny*vertex->ny + vertex->nz*vertex->nz));

vertex->v = vertex->ny / (sqrt(vertex->nx*vertex->nx + vertex->ny*vertex->ny + vertex->nz*vertex->nz));
vertex++;
}

where u,v are texture coordinates and
nx,ny,nz are normals of each vertex

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!