   Question about tangent vector
  I'm new to HLSL, i met a problem in bump map vertex shader:VS_OUTPUT VS(float4 Pos : POSITION, float2 Tex : TEXCOORD, float3 Normal : NORMAL, float3 Tangent : TANGENT  ){   VS_OUTPUT Out = (VS_OUTPUT)0;   Out.Pos = mul(Pos, matWorldViewProj);   float3x3 worldToTangentSpace;   worldToTangentSpace[0] = mul(Tangent, matWorld); //Here i can't understand   worldToTangentSpace[1] = mul(cross(Tangent,Normal), matWorld);   worldToTangentSpace[2] = mul(Normal, matWorld);   Out.Tex = Tex.xy;   float3 PosWorld = normalize(mul(Pos, matWorld));   float3 Light  = vecLightDir - PosWorld;    Out.Light.xyz = mul(worldToTangentSpace, Light);   float3 Viewer = vecEye - PosWorld;   Out.View = mul(worldToTangentSpace, Viewer);    return Out;}The tangent is computed from D3DXComputeTangent, is it a vector in local space?The tangent need to be put in the world space than get the matrix?Why get the worldtotangent maxtrix like this? any reference?Thanks.   
  Hi,Quote:The tangent is computed from D3DXComputeTangent, is it a vector in local space?Returning vectors of D3DXComputeTangent() or D3DXComputeTangentFrameEx() are tangent, binormal and normal vectors. They're all in local-space. I recommend you to use D3DXComputeTangentFrameEx() cuz it's more reliable. The other one always crashes when I use it :)Quote:The tangent need to be put in the world space than get the matrix?Why get the worldtotangent maxtrix like this? any reference?Tangent-space matrices consists of three tangent space vectors (Tan, Bin and Nor) in local or world-space. First row comes from tangent, second row does binormal and the last one does from normal vector. You know that this kind of matrices can be used for putting a vector (or a vertex) from one space to another. In normal mapping, if you sample a normal map by using a function like tex2D() and multiplying this by 2.0f then subtracting 1.0f, you get a normal vector in TANGENT SPACE. Multiply this vector with your tangent matrix puts this normal vector to LOCAL SPACE (If you construct your tangent-space matrix from local space Tan, Bin and Nor vectors) or WORLD SPACE (If you construct your tangent-space matrix from world space Tan, Bin and Nor vectors). That's why we construct TangentTo... matrix (The name of your matrix is wrong, it must be TangentToWorldSpace cuz it's been built from world space tan, bin and nor vectors).PS:You don't need to get binormal vector by crossing tangent and normal. Just pass a vector in BINORMAL semantic like your VS function inputs.Sample code:Assume we used D3DXComputeTangent() function and it succeeded.texture2D myNormalMap;sampler2D myNormalSampler = sampler_state{    texture = ( myNormalMap );    //filter and adrressing operations//blah blah blah};VS_OUTPUT VS (float4 pos: POSITION, float3 nor: NORMAL, float3 tan: TANGENT, float3 bin: BINORMAL, float2 tex: TEXCOORD){    VS_OUTPUT Out = (VS_OUTPUT)0;    Out.Pos = mul (pos, WorldViewProj);    float3x3 TBNBasis;    TBNBasis[0] = tan;    TBNBasis[1] = bin;    TBNBasis[2] = nor;    //Here we get TangentToLocalSpace matrix; if you wanna get TangentToWorld,    //you must put mul (tan, matWorld) instead of tan, and the same operation    //for the other vectors.    //blah blah blah} PS_OUTPUT PS (YOUR_PS_INPUTS_COME_HERE){   //blah blah blah   float3 nMap = tex2D (myNormalSampler, tex);    nMap = 2.0f * nMap - 1; //here we get normal map in TEXTURE SPACE.   float3 nMapInLocalSpace = mul (nMap, TBNBasis);    float3 nMapInWorldSpace = mul (nMapInLocalSpace, matWorld);    //now we get normal/bump map in world space. Ready to use it in    //Phong or another shading.}Hope this helps.Rohat.   