title: How to achieve smooth tangent space normals?
body: <p>I'm trying to add bump mapping functionality to my application but I'm getting very faceted models:</p>
  
  <p><img src="https://i.stack.imgur.com/S6y9c.png" alt="enter image description here"></p>
  
  <p>The reason it is happening is because I'm calculating tangent, binormal and normal on per face basis and completely ignoring the normals I'm getting from the model file. </p>
  
  <p>The calculation currently uses two edges of the triangle and texture space vectors to get tangent and binormal, which are then used to calculate normal by cross product. It is all done on the CPU as soon as the model loads and the values are then stored as a part of model's geometry.</p>
  
  <pre><code>    vector1 = vertex2.coords - vertex1.coords;      
      vector2 = vertex3.coords - vertex1.coords;
  
      tuVector = vertex2.texcoords - vertex1.texcoords;
      tvVector = vertex3.texcoords - vertex1.texcoords;
  
      float den = 1.0f / (tuVector.x * tvVector.y - tuVector.y * tvVector.x);
  
      tangent.x = (tvVector.y * vector1.x - tvVector.x * vector2.x) * den;
      tangent.y = (tvVector.y * vector1.y - tvVector.x * vector2.y) * den;
      tangent.z = (tvVector.y * vector1.z - tvVector.x * vector2.z) * den;
  
      binormal.x = (tuVector.x * vector2.x - tuVector.y * vector1.x) * den;
      binormal.y = (tuVector.x * vector2.y - tuVector.y * vector1.y) * den;
      binormal.z = (tuVector.x * vector2.z - tuVector.y * vector1.z) * den;
  
      D3DXVec3Normalize(&amp;tangent, &amp;tangent);
      D3DXVec3Normalize(&amp;binormal, &amp;binormal);
  
      D3DXVec3Cross(&amp;normal, &amp;tangent, &amp;binormal);    
      D3DXVec3Normalize(&amp;normal, &amp;normal);
  </code></pre>
  
  <p>Is there a way to either calculate these values on per vertex basis, perhaps using the normal supplied with the model or to smooth them out somehow so the model doesn't appear faceted?</p>