# Tangents? Ive searched but still confused.

Hi, im having my first go at trying to do normal maps using shaders.

So ive done some shaders form tuts, i have per pixel lighting working and i now want to have a go at normal mapping. I have my normal map loaded in ready to go.

Ive found plenty of normal map shader tuts, but they all seem to just “receive” tangents from opengl and i literally dont have a clue what tangents are? Well i know an hours worth of reading from today, but i really dont know…

1. What they are?
2. Why i need them?
3. And how i calculate them (actual code, not therory)

Lamens terms i guess!

Really hope you can help.
Thanks
Andy

Hi,

1. They build the basis set of the tangent space on a particular point (vertex) of the surface.

2. In most cases the normals from your normal map are represented in tangentspace. So you need to transform your light direction into the tangentspace to compute your lighting. And for that task you use the basis mentioned in 1.

Hi, thanks, so from looking at that code? It loops threw all the triangles and seems to put all the tangents in a array? Is this all required to simply show a single normal map on a quad?

If it is then thats fine ill try to continue. Justs seems hard work at the momement.

Ive read from the above links, that if the pimative or object is made form quads and not triangles then a different calculation is needed? Is that so? What happenes if you have mixed objects in a scene?

Thanks
Andy

Technically thats right. But the algorithm targets arbitrary meshdata. For a quad its not pretty hard to provide the tangents by hand (for the sake of testing).

Since a quad can be seen as two adjacent triangles there should be no real problem in this case. Normally you would generate the tangents (or just one of them, plus the vertexnormal… In this case you could retrieve the remaining axis by taking the cross product of the given two vectors in your shader) for each vertex, and pass the data as vertexattributes to the shader. Since you would do that for all objects which require the data it’s no matter how many objects reside in your scene.