title: Half of normal mapped object is inverted
body: <p>I have tried to implement normal mapping for 3 days now in vulkan. I pre-calculate the tangents and bitangents in the simple obj loader i made and create the TBN matrix in the shader. For now I'm just trying to get it to work, optimizations is saved for later. I'm very confused for why this problem occurs, I have googled around a lot which led me to check for handedness in the texture coordinates. This hasn't solved my problem though. I'm not sure what could be the problem or why this doesn't look correct. I worked with openGL before and this problem also occurred then. The normal mapping works on another model, but not this one.</p>
  
  <p><strong>Example of the problem</strong>
  <a href="https://i.stack.imgur.com/DpmjS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DpmjS.jpg" alt="enter image description here"></a></p>
  
  <p>This is how i pre-calculate the tangents and bitangents</p>
  
  <pre><code>    for (unsigned int i = 0; i &lt; vertices.size(); i += 3)
              {
                  Vector3f deltapos1 = vertices[i + 1].position - vertices[i].position;
                  Vector3f deltapos2 = vertices[i + 2].position - vertices[i].position;
  
                  Vector2f deltauv1 = vertices[i + 1].uv - vertices[i].uv;
                  Vector2f deltauv2 = vertices[i + 2].uv - vertices[i].uv;
  
                  float f;
  
                  Vector3f tangent(1, 0, 0);
                  Vector3f bitangent(0, 1, 0);
  
                  float det = deltauv1.x * deltauv2.y - deltauv1.y * deltauv2.x;
  
                  if (det != 0)
                  {
                      f = 1.0f / det;
  
                      tangent = (deltapos1 * deltauv2.y - deltapos2 * deltauv1.y) * f;
                      bitangent = (deltapos2 * deltauv1.x - deltapos1 * deltauv2.x) * f;
                  }
  
                  vertices[i].tangent     = tangent;
                  vertices[i + 1].tangent = tangent;
                  vertices[i + 2].tangent = tangent;
  
                  vertices[i].bitangent     = bitangent;
                  vertices[i + 1].bitangent = bitangent;
                  vertices[i + 2].bitangent = bitangent;
              }
  
              for (unsigned int i = 0; i &lt; vertices.size(); i++)
              {
                  vertices[i].tangent = Math::normalize(vertices[i].tangent - vertices[i].normal * Math::dot(vertices[i].tangent, vertices[i].normal));
  
                  if (Math::dot(Math::cross(vertices[i].bitangent, vertices[i].tangent), vertices[i].normal) &lt; 0.0f)
                      vertices[i].bitangent = Math::normalize(Math::cross(vertices[i].normal, vertices[i].tangent)) * -1;
                  else
                  vertices[i].bitangent = 
                  Math::normalize(Math::cross(vertices[i].normal, vertices[i].tangent));
  
              }
  </code></pre>
  
  <p>Vertex shader </p>
  
  <pre><code>void main()
  {
      UV = vec2(inUv.x, 1.0f - inUv.y);
  
      mat3 nmat = mat3(((ubo.model)));
  
      gl_Position =  ubo.mvp * vec4(inPosition, 1.0f);
  
      Normal = normalize(nmat * inNormal); 
      vec3 T = normalize(nmat * inTangent);
      vec3 B = normalize(nmat * inBitangent);
      vec3 N = Normal;
  
      //T = normalize(T - N * dot(T, N));
      //B = normalize(cross(T, N));
  
      mat3 TBN = mat3(T, B, N);
  
      toModelSpace = TBN;
  
      fragPos = vec3(ubo.model * vec4(inPosition, 1.0f));
      viewPos = ubo.cameraPos;
  </code></pre>
  
  <p>This is how I convert normal map to model space</p>
  
  <pre><code>vec3 normal = normalize(texture(imageBump, UV).rgb * 2.0f - 1.0f);
  normal = normalize(toModelSpace * normal);
  </code></pre>