I try to learn the usage of shaders at the moment. In my program I generate the buffers (vertices, texCoords, normals, indices) for a flat area made up of some quads. That works, but when I used the lighting material on it (as in the material-tutorial) this happened:

Only when I added

TangentBinormalGenerator.generate(mesh)

everything looked ok (a flat gray pixel lighted plane).

But I have no clue why. I thought correct normals would be sufficient to calculate the lighting? How works the TangentBinormalGenerator?

To be honest I never did understand why you need tangents for normal mapping as well, at least to most computer grafic papers this is not necessary, and the varying normal + the offset from the normal map should suffice.

Normal maps are almost 100% of the time, in tangent space (a frame of reference localized for each vertex), but they could be created in any space you want. When you do light calculations, you need to do them in the same space. Your light/camera vectors wonâ€™t be in the correct space.

A normal map gives you the Z axis, but to form a basis, you need 3 axes (the other 2 being tangent and binormal). The generator creates tangent vectors for you, and the bi-normal is normally created in the shader (cross product between the 2). Then you can create a tangent space matrix which you can use to transform the light vectors

@wezrule said:
Normal maps are almost 100% of the time, in tangent space (a frame of reference localized for each vertex), but they could be created in any space you want. When you do light calculations, you need to do them in the same space. Your light/camera vectors won't be in the correct space.

A normal map gives you the Z axis, but to form a basis, you need 3 axes (the other 2 being tangent and binormal). The generator creates tangent vectors for you, and the bi-normal is normally created in the shader (cross product between the 2). Then you can create a tangent space matrix which you can use to transform the light vectors

This. Could have been a response to empire, also.

Regular normal maps are based on the baseline of the texture space being the same as the tangent vector. Without tangent space then you donâ€™t know what direction to project the normal vector from the normal map. You canâ€™t just use world or model space because the triangle could be rotated, etcâ€¦

Without special normal maps I donâ€™t know how youâ€™d do it without tangents, really.

@Empire Phoenix said:
To be honest I never did understand why you need tangents for normal mapping as well, at least to most computer grafic papers this is not necessary, and the varying normal + the offset from the normal map should suffice.

That's like saying "we don't need the Z axis in a 3D world".
Normals in a normal map are usually in tangent space because the normal in the map will still be correct if the model is deformed (like in bone animation).
Normals for each vertex in a model buffer are in model space, that's the Z axis of the tangent space.
Now we want to compute this tangent space normal we got from the normal map in view space (because that's where we compute lighting). But we only have one axis...so there is no way to make a transformation matrix.

Only way is to generate tangents (and binormal but they are computed later in the shader), to have a real coordinate system.
Tangent and binormal follows the U and V coordinates of your normal map, so you can generate them from normals and texture coordinatesâ€¦with some crazy mathsâ€¦

If you seen some normal mapping implementation without tangents, thatâ€™s probably because tangents in the map were not in tangent space (some implementations use model space, but if the mesh deforms the normals are wrong, some even use world space but the object has to be staticâ€¦).

itâ€™s only needed if you plan to use normal mapping or parallax mapping

it may already have tangents

it may be time consuming, soâ€¦

tangent generation should be done as a preprocessing step and baked into the model

it makes something magic that you should definitely be aware of â€śWhy does my mesh triple in size?â€ť

For certain meshes (Iâ€™m looking at you block world games), itâ€™s easier to just set the tangents when the normals are set.

The SDK will run it for you automatically it seems wen you set a material but you can also manually run it as I recall. Just load the model in the SDK, run tangents, save it. Done.