# Terrains, tangents and binormals

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

## Recommended Posts

Hi

When doing normal mapping for heightmap-based terrains, does the binormal and tangent of a vertex have to be exactly perpendicular to the normal of the triangle? Currently I just use the Cartesian axes for tangent and binormal (I.e. along z=1 and x=1) and it seems to work fine, regardless of how slopey my terrain is. I think this is because the terrain itself doesn't move or rotate.

The reason I'm asking is that I want to be able to rotate my terrain textures/normal maps/displacement maps and I'm wondering if I need to also rotate the tangent and binormals to match the angle of the texture. I assume I will.

I hope that's easy to understand - it's a tricky thing to explain.

Thanks

##### Share on other sites

Are you planning to deform your heightmap at runtime? If not, there's no need to use tangent-space normal mapping in the first place.

Terrains don't tend to rotate on their own, so object-space (or even world-space) normal mapping works just as well, and saves a bunch of operations in the shader.

##### Share on other sites

Are you planning to deform your heightmap at runtime? If not, there's no need to use tangent-space normal mapping in the first place.

Terrains don't tend to rotate on their own, so object-space (or even world-space) normal mapping works just as well, and saves a bunch of operations in the shader.

Thanks for the quick response.

No, there is no runtime deformation to the terrain. But I will be rotating the textures that are layered onto the terrain. If I don't specify some form of tangent space, won't the rotated textures be lit from the wrong angle?

##### Share on other sites

If I don't specify some form of tangent space, won't the rotated textures be lit from the wrong angle?

Detail normal maps will, yes.

But the tangent space can be easily derived from vertex normal. Assuming Z-up (N=normal, T=tangent, BT=bitangent, some sign swapping might be necessary depending on your configuration):

T = normalize(cross(N,vec3(0,1,0)));
BT = normalize(cross(N,vec3(1,0,0)));

Also, since the second argument of cross() is a constant, you can probably do swizzling and multiplication to some other constant as well.

Btw, a Google search turned up this: http://www.gamedev.net/blog/446/entry-1404088-terrain-with-tangent-space-normal-mapping/

P.S. If you want to rotate your textures, you'll probably want to rotate the tangent space as well - you can do that by rotating those constant vectors, using sin/cos to specify their X/Y components. First will probably be vec3(cos(angle-pi/2),sin(angle-pi/2),0), second - vec3(cos(angle),sin(angle),0).

Edited by snake5

##### Share on other sites

If I don't specify some form of tangent space, won't the rotated textures be lit from the wrong angle?

It looks like snake5 has you covered, but roughly, yes, you want to rotate the tangent space by the exact same process you used to rotate the texture coordinates.

##### Share on other sites
Ok great, thanks both

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013433
×