   Normal mapping (math question)
  Hello all.I'm trying to implement normal mapping for my deferred rendering engine. At the moment I'm only working with map data and don't use any world matrices or anything.So, I have this surface with a normal (a wall, say normal (1,0,0)). Now I want to add normal mapping to it. I have this normal map in which the stored normals are correct for a surface with the surface normal (0,1,0) or whatever. So how can I rotate all those stored normals so that they are correct for a surface with normal N (such as my wall)..?I have a really hard time expressing what I'm trying to do which is probably why my attempts to google it have been so unsuccessful. I guess my question is something like this: How can I create a 3x3 rotation matrix that can rotate normal N so that it becomes M..?N * ROTMAT = MI have N and M, how to get ROTMAT?I assure you, this is no assignment or homework, I just havn't taken a linear algebra class (yet).Thanks for any help   
  The rotation matrix you're speaking of is your TBN matrix, tangent-binormal-normal matrix.  Look up tangents and binormals.  Tangents can be computed from your UV coordinates, and then binormals are cross products of your tangents and normals.  This means you have to create them in a pre-processing step before rendering, since you need access to neighboring vertice's UV coordinates.(You may need the inverse of your TBN matrix depending on whether you're going from tangent space to world space or vice versa)   ;  Hi,nullsquared is right. The matrix you need for NMapping is just TBN basis matrix. If you're working with DX Meshes (i.e. .X files), it's quite simple to compute all TBN basis. Just use D3DXComputeTangentFrameEx() function. You can find a lot of info by googling fot it ;)The remaining work is using TBN basis in your shader. We're always here, you can ask whenever you want.Rohat.   ;  Just like they said you can calculate the TBN matrix using the UV coordinates and in my case I used the view vector but seems position will work too. If possible check out the ShaderX5 book . They have a section specifically on calculating the TBN matrix in vertex or pixel shaders. Originally I was passing in the tangent and bitangents along with the vertex data but getting that data when loading models or calculating it was a P.I.T.A. This was much easier as you can  control of a mesh is normal mapped by which shader you use to render it. Alternatively I could post what I got to work for me too if you want.   