Reputation: 77
When I use Normal maps in my app I get seams like this enter image description here
I think there is something wrong with tangents I compute them whit this function from Rastertek.com
vector1[0] = vertex2.x - vertex1.x;
vector1[1] = vertex2.y - vertex1.y;
vector1[2] = vertex2.z - vertex1.z;
vector2[0] = vertex3.x - vertex1.x;
vector2[1] = vertex3.y - vertex1.y;
vector2[2] = vertex3.z - vertex1.z;
tuVector[0] = vertex2.tu - vertex1.tu;
tvVector[0] = vertex2.tv - vertex1.tv;
tuVector[1] = vertex3.tu - vertex1.tu;
tvVector[1] = vertex3.tv - vertex1.tv;
den = 1.0f / (tuVector[0] * tvVector[1] - tuVector[1] * tvVector[0]);
tangent.x = (tvVector[1] * vector1[0] - tvVector[0] * vector2[0]) * den;
tangent.y = (tvVector[1] * vector1[1] - tvVector[0] * vector2[1]) * den;
tangent.z = (tvVector[1] * vector1[2] - tvVector[0] * vector2[2]) * den;
binormal.x = (tuVector[0] * vector2[0] - tuVector[1] * vector1[0]) * den;
binormal.y = (tuVector[0] * vector2[1] - tuVector[1] * vector1[1]) * den;
binormal.z = (tuVector[0] * vector2[2] - tuVector[1] * vector1[2]) * den;
I use Vertex normals but there is no difference when I use face normals i get the same picture
How can I solve this problem
This is picture of normal map rendered in diffuse texture enter image description here
Upvotes: 0
Views: 576
Reputation: 7824
Looking closely at the rendered output, it looks like the for the top right you have a reversed sense of lighting. In the bottom left it looks like you have groves on the surface, in the top right it looks like they point outwards. This might indicate problems with orientation.
Actually looking at the normal map rendered in diffuse texture you have the same boundaries. Before proceeding make sure the "normal map rendered in diffuse texture" appears seamless.
Spheres are tricky as you can not define a non vanishing vector field over the whole sphere. (The Hairy ball theorem) This means you can not consistently define the tangent and binormal vectors over the whole sphere, there must be some jumps. This may not a great problem for you as normal map is made up of individual pieces. It may be possible to alter the sense of vectors tu
and tv
for each piece. So for some pieces one or other is reversed tu'=-tu
, tv'=-tv
, or possibly the order of the two is reversed. tu'=tv, tv'=-tu
. You will need some way of the code knowing which patch needs which transformation.
One drastic way around the problem is to remove the top and bottom from you object. This will allow you to treat the object as a distorted cylinder which can have consistent definitions for the two vectors.
Perhaps a better solution might be to store the normal map as a three component, directly giving 3D normal at each point.
Assuming we don't have to worry about rotations other than 90º we can have the symmetry of the square
Upvotes: 1