Forum

That sphere texture mapping thing

I’ve found some old threads on this problem, but what I found in them as a solution doesn’t really work.

When applying a texture to a sphere mesh in a shader, the texture does not cover the whole sphere, and is repeated in a thin slice. By uncommenting a line in the shader:

   //Wrap0 = U;  // useful when mesh is round like a sphere

the situation is improved, but there is still a slice of repeated image (see attached file).

Has this been resolved? Is there another approach to applying textures to spheres?

Thanks!

sphere-texture.zip (60.2 kB)

If you need a properly closed sphere, I think you need to texture it in a 3D prgram like cinema and export as xfile with the proper texture coordinates.

ja, this is due to a bad default we chose for texture addressing. we should have chosen WRAP as opposed to MIRROR (which it is now) and such problems would not have occured.

so in your example in the effects sampler definition you’d have to add:
AddressU = WRAP;
in order to fix that.

for details see Texture Wrapping and Texture Addressing Modes.

Excellent, joreg, thank you! That also fixes a problem with X translation.

However, there is still a distortion with X scaling, where the texture is repeated in the same area as before. Not an issue with what I’m doing right now, but it still looks like a problem. Did I put the WRAP in the right place?

The problem area seems to be in X of .43 - .5, and I don’t understand what might be special with that range.

Thanks again!

sphere-texture-wrap.zip (85.7 kB)

i cannot explain this behavior, but Sphere (DX9) works better in this scenario where you scale the texture.

OK, but Sphere (DX9) cannot be “lit” in any way, can it? Thanks!

right, it can’t.