I've just verified it again: the tangent passed to a terrain entity is always 0,0,0. Try outputting it as a color in the pixel shader..
I think you can calculate the tangent and binormal from only the normal because you know that it's a regular grid (u and v always pointing in xz direction).
So you'd take the cross of the normal and a (unit?) vector pointing in x (or z?) direction to get the tangent and then cross that with the normal to get the binormal or something..
PS. I'm talking about the directX coordinate system here, so z = y.
EDIT: I was creating this shader for a client who is using 6.31.4. I just tried it in 6.50, and it does give some kind of a tangent there, but I'm getting the impression it's still not quite right..
EDIT2: Yes I'm now convinced that in 6.50, the tangents are wrong. Try outputting the tangent as a color on a terrain and then convert that terrain to a mdl and do it again. The tangents look somewhat like they should be, but there are some strange things.. I guess it's a bug, or we're not supposed to use them with terrains (and have to calculate them from the normal).
EDIT3:
Ok, I can calculate the tangent and binormal from the normal on a terrain. This works on a model terrain, but when I use it on a terrain, I get the SAME tangents as when I use the tangent flag.. Seems like the problem is related to the normals then..
worldToTangentSpace[0] = cross(InNorm, float3(0.0f, 0.0f, 1.0f));
worldToTangentSpace[1] = cross(worldToTangentSpace[0], InNorm);
worldToTangentSpace[2] = InNorm;
EDIT4: Ok, after calling ent_fixnormals everything works fine.. Strange!
I would advise you to use the above way of calculating the tangent and not use the tangent flag, because it is faster on the GPU. Ofcourse it only works for terrains. EDIT: it's not faster
Last edited by Excessus; 04/10/07 07:33.