# Tangents/Bitangents for spherical cube

This topic is 3795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am playing around with planet rendering (again), and have hit a weird bug to do with normal mapping. My normals are continuous across the sphere: But my tangents are not: And nor are my bitangents: Which leads to a normal-mapped result like this: The sphere is really an exploded cube, which explains why only a certain face has trouble, but I can't for the life of me find the error. I have made sure that the tangents and bitangents lie along the texture U,V coordinates (which are tested to be correct), and have tried all combinations of rotating/flipping the tangents and bitangents on the affected faces. If anyone has any ideas, they would be most welcome!

##### Share on other sites
It is a known topological fact that you can't have a non-vanishing continuous tangent field on a sphere. There's going to be a problem somewhere, so you have to decide how to divide the surface up into different regions where the tangent field is locally continuous, but you will always have seams between the regions.

##### Share on other sites
Quote:
 Original post by Eric LengyelIt is a known topological fact that you can't have a non-vanishing continuous tangent field on a sphere. There's going to be a problem somewhere, so you have to decide how to divide the surface up into different regions where the tangent field is locally continuous, but you will always have seams between the regions.
Understood, and seams I can deal with. However, it looks like I have entire faces that have flipped tangents/bitangents, and I think this should be correctable.

The texture coordinates of the sphere match the OpenGL cubemap layout, and they seem to be correct. The tangents/bitangents definitely match the s/t texture coordinates, so each face should be correctly lit, even if there are seams.

##### Share on other sites
All right, the problems seem to run deeper than I realised. A quick question:

If my tangent space basis is correct, should the light direction - once it has been transformed into tangent space - be continuous?

My intuition says yes, but this series of images says no (light vector transformed into tangent space, as rgb: front-left, front-right, rear-right, rear-left):

Now, obviously we can't have continuous tangents/bitangents over a sphere, as Eric pointed out. But if we ignore for a moment that this looks spherical, it is in fact a cube (which has been expanded). And it is certainly possible to normal map a cube - I have it mostly working here, except for the problem in the tangent space transform.

Do you think this is just a case that my s,t texture coordinates are screwy, or is there something deeper wrong here?

[Edited by - swiftcoder on May 25, 2008 2:09:42 PM]

##### Share on other sites
Quote:
 Original post by swiftcoderNow, obviously we can't have continuous tangents/bitangents over a sphere, as Eric pointed out. But if we ignore for a moment that this looks spherical, it is in fact a cube (which has been expanded). And it is certainly possible to normal map a cube - I have it mostly working here, except for the problem in the tangent space transform.

No, it isn't possible to normal map a cube, not in the way that you need here.
The curvature of an actual cube is "swept under the carpet" at its edges and vertices, individual faces pose no problem and discontinuous tangents between adjacent faces are actually desired; but here the fact that your sphere model is based on a cube doesn't help, you still need continuous tangents and you cannot take advantage of cube edges.

Maybe you don't need a whole smooth sphere: if only an hemisphere is visible, you can put the seam at its invisible circumference and deform the tangents, frame by frame, to match camera position.

##### Share on other sites
Quote:
 Original post by LorenzoGattiNo, it isn't possible to normal map a cube, not in the way that you need here. The curvature of an actual cube is "swept under the carpet" at its edges and vertices, individual faces pose no problem and discontinuous tangents between adjacent faces are actually desired; but here the fact that your sphere model is based on a cube doesn't help, you still need continuous tangents and you cannot take advantage of cube edges.
Ah, that makes sense - unfortunately :)

So it looks like my best choice is going to be model-space normal maps. Generating those is going to be a little expensive compared to the image-based approach I was using, but if it has to be, it has to be.

##### Share on other sites
Thanks for all your help, world space normal maps did the trick quite nicely!

Seems between faces are still visible, but hopefully that can be fixed (or disguised) in the future.

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009385
• ### Who's Online (See full list)

There are no registered users currently online

×