• Advertisement
Sign in to follow this  

Applying texture on a sphere [raytracing]

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

Hi guys !

I'm doing a raytracer in C. I have to apply textures on a sphere. I have the coordinates x, y,z where my ray hits the sphere, the radius of the sphere and a function that returns the color of the pixel of the texture for a given x and y.

Do you have a formula to get the x,y of the texture from the x,y,z of the sphere and the radius r ?

Ty !

Share this post


Link to post
Share on other sites
Advertisement
I don't have my code at the moment, but I remember that there is a simple addition to the intersection formula that gives u,v parameters of the intersection point. You just have to specify a couple of vectors defining the orientation of te sphere.

Those uv can then be scaled/translated/rotated/clipped any way you want and in the end you do a get(u,v) on the texture (where u and v are presumably normalized so that 0 is completely left and 1 is completely right - same thing for top and bottom).

Hope this helps

Share this post


Link to post
Share on other sites
I have to specify a couple of vector to define the sphere ? On the 0.x axe and 0.y axe ? And is it on a cartesian reference ?

Share this post


Link to post
Share on other sites
This should be of some help...

[url="http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_6_Textures_Cameras_and_Speed.shtml"]http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_6_Textures_Cameras_and_Speed.shtml[/url]

Share this post


Link to post
Share on other sites
[quote name='Frénésie' timestamp='1338497298' post='4945085']
I have to specify a couple of vector to define the sphere ? On the 0.x axe and 0.y axe ? And is it on a cartesian reference ?
[/quote]
I think that you need to define at least the north (and perhaps even the west) vectors, so that rotations applied to the sphere reflect on the texture orientation...

Share this post


Link to post
Share on other sites
Two words: spherical coordinates.
One link: [url="http://www.mvps.org/directx/articles/spheremap.htm"]sphere texture mapping[/url].

Share this post


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

  • Advertisement