Advertisement Jump to content
Sign in to follow this  

UV mapping a sphere in shader

This topic is 3958 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: 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): 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:

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!