title: normal mapping, TBN matrix calculation
body: <p>I just want to be sure I understand TBN matrix calculation correctly</p>
  
  <p>In vertex shader we usually use:</p>
  
  <pre><code>vec3 n = normalize(gl_NormalMatrix * gl_Normal);
  vec3 t = normalize(gl_NormalMatrix * Tangent.xyz);
  vec3 b = normalize(gl_NormalMatrix * Bitangent.xyz);
  mat3 tbn = mat3(t, b, n);
  </code></pre>
  
  <p>As I understand this <code>tbn</code> matrix transforms a vector <strong>from Tangent</strong> space <strong>to Eye</strong> space. Actually we want the reverse - transform a vector from eye space to Tangent space. Thus we need to invert the <code>tbn</code> matrix:</p>
  
  <pre><code>tbn = transpose(tbn); // transpose should be OK here for doing matrix inversion
  </code></pre>
  
  <p><strong>note:</strong> <code>tbn</code> - should contain only rotations, for such case we can use transpose to inverse the matrix.</p>
  
  <p>And we can transform our vectors:</p>
  
  <pre><code>vec3 lightT  = tbn * light_vector;
  ...          = tbn * ...
  </code></pre>
  
  <p>In several tutorials, source codes I've found that authors used something like this:</p>
  
  <pre><code>light.x = dot(light, t);
  light.y = dot(light, b);
  light.z = dot(light, n);
  </code></pre>
  
  <p>The above code does the same as multiplying by the <code>transposed(tbn)</code> matrix. </p>
  
  <p><strong>The question:</strong> </p>
  
  <p>Should we use transposed <code>tbn</code> matrix just as I explained above? Or maybe I am missing something?</p>
  
  <p><strong>Note</strong> by that solution we have vectors (light_vector) transformed into TBN in the vertex shader, then in fragment shader we only have to get normal from the normal map. Other option is to create TBN matrix that transform from TBN space into eye space and then in the fragment shader transform each read normal from the normal map.</p>