Terrains, tangents and binormals

Started by
4 comments, last by RobM 8 years, 8 months ago
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
Advertisement

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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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?

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).


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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Ok great, thanks both

This topic is closed to new replies.

Advertisement