views:

447

answers:

1

I have a sphere with per-vertex normals and I'm trying to derive the texture coordinates for the object using the algorithm:

U = Asin(Norm.X) / PI + 0.5
V = Asin(Norm.Y) / PI + 0.5

With a polka dot texture, I get:

Misaligned textures

Here's the same object without the texture applied:

No textures

The issue I'm particuarly looking at (I know there's a few) is the misalignment of the textures.

I am inclined to believe the issue resides in my use of those algorithms, as the specular highlighting (which doesn't utilise any textures but does rely on the normals being correct) appears to have no artifacts.

Any ideas?

+2  A: 

Can't you just set your UVs while you are building the sphere?

Then:

 u = theta / (2 * PI);
 v = phi / PI;

Edit: I might also point out that there probably is something wrong with your normals given the black dot on top ... There also appears to be highlighted lines along polygon edges. This again points to probable dodgy normals ...

Goz
As I said, I'm aware of other issues... and setting the UV whilst I'm building the sphere won't cover later deformations. I'm building the sphere from scratch rather than using a prebuilt mesh for specifically that reason.
Rushyo
Well if you are going to re-texture as you deform perhaps its projective texturing you are after...
Goz
Might well be worth looking into, but I don't have any resources and 'tis not the season to be buying reference manuals.
Rushyo
http://developer.nvidia.com/object/Projective_Texture_Mapping.html
Goz