Jump to content
  • Advertisement
Sign in to follow this  
bjarnia

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.

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
Advertisement
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!