# UV mapping a sphere in shader

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

## Recommended Posts

I have a sphere that I'm going to use as a skybox, and I need(because I can't do it propperly in Blender) to generate the texture coordinates in the shader. I have a 360° texture that I want to wrap around the sphere, similar to this one: http://mpan3.homeip.net/content/resources/earth-thumb/day-overcast.jpg Anyway, everything works fine, except where I the texture will "seam" back together, then the texture repeats itself entierly instead of wrapping back to 0. Not entierly sure how to fix this. This is how i calculate the coords now (in CG): (NOTE that coords are Z-up!)
	float2 normd = normalize(vtx_position.xy);

// texture coordinates
float deg = atan2(normd.y, normd.x);
deg = degrees(deg);

if (deg < 0)
deg += 360;

deg /= 360;

l_newUV.x = deg;
l_newUV.y = vtx_position.z;

Btw the sphere has a radius of 1, so that the y coord is correct. If it helps, this is sort of how it looks now (wireframe overlaid): http://www.steik.org/dump/uv.jpg Ps, I know that "deg" is calculated correctly and is always in the range of 0 to 1 Pps.. here is the model, for reference: http://www.steik.org/dump/icosphere.jpg

##### Share on other sites
The technique outlined by Robert Dunlop (http://www.mvps.org/directx/articles/spheremap.htm) should work fine for your dome although you'll probably have to make adjustments for the v component.

Regards,
ViLiO

1. 1
2. 2
frob
15
3. 3
4. 4
5. 5
Rutin
12

• 12
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632115
• Total Posts
3004200

×