• Advertisement
Sign in to follow this  

UV mapping a sphere in shader

This topic is 3623 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 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 this post

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

  • Advertisement