title: GLSL calculating normal on a sphere mesh in vertex shader using noise function by sampling is producing strange graphical errors
body: <p>I'm trying to calculate the normals on surface of a sphere in the vertex shader because I defer my noise calculation to the vertex shader. The normal results are good when my theta (sampling angle) is closer to 1 but for more detailed terrain &amp; a smaller theta my normals become very incorrect. Here's what I mean:</p>
  
  <p><em>Accurate normals</em></p>
  
  <p><img src="https://i.imgur.com/6X7Z6BQ.png" alt="Accurate normals"></p>
  
  <p><em>More detailed noise with a higher theta</em></p>
  
  <p><img src="https://i.imgur.com/b4FJSpL.png" alt="More detailed noise with a higher theta"></p>
  
  <p><em>Zoomed in onto surface of last image. Red indicates ridges, blue indicates incorrect shadows</em></p>
  
  <p><img src="https://i.imgur.com/WJGK6J2.png" alt="More detailed noise with a higher theta zoomed in"></p>
  
  <p>The code I use to calculate normals is:</p>
  
  <pre><code>vec3 calcNormal(vec3 pos)
  {
      float theta = .1; //The closer this is to zero the less accurate it gets
      vec3 vecTangent = normalize(cross(pos, vec3(1.0, 0.0, 0.0))
          + cross(pos, vec3(0.0, 1.0, 0.0)));
      vec3 vecBitangent = normalize(cross(vecTangent, pos));
      vec3 ptTangentSample = getPos(pos + theta * normalize(vecTangent));
      vec3 ptBitangentSample = getPos(pos + theta * normalize(vecBitangent));
  
      return normalize(cross(ptTangentSample - pos, ptBitangentSample - pos));
  }
  </code></pre>
  
  <p>I call calcNormal with </p>
  
  <pre><code>calcNormal(getPos(position))
  </code></pre>
  
  <p>where getPos is the 3D noise function that takes and returns a vec3 and position is the original position on the sphere.</p>