title: Calculate TBN matrix in vertex shader vs fragment shader?
body: <p>I think we can calculate TBN matrix in both vertex shader and fragment shader.</p>
  
  <pre><code>// calculate in vs
  varying mat3 vTbnMatrix;
  void main() {
    vec3 n = normalMatrix * aNormal;
    vec3 t = normalMatrix * vec3(aTangent.xyz);
    vec3 b = cross(n, t) * aTangent.w;
    vTbnMatrix = mat3(t, b, n);
  }
  
  // calculate in fs
  varying vec3 vNormal; // transformed by normalMatrix
  varying vec3 vTangent; // transformed by normalMatrix
  varying vec3 vBitantent;
  void main() {
    mat3 tbnMatrix = mat3(vTangent, vBitangent, vNormal);
  }
  </code></pre>
  
  <p>What's the difference? I think we can calculate TBN matrix in the vertex shader as it can speed up the program. </p>
  
  <p>But when I dive into the source code of THREE.js and PlayCanvas engine, they both calculate TBN matrix in the fragment shader.</p>
  
  <p>What's the advantage of calculating in the fragment shader?</p>